commands.update() 编辑
Change the description or keyboard shortcut for the given command.
This is an asynchronous function that returns a Promise
.
Syntax
browser.commands.update(
details // object
);
Parameters
details
object
. An object with the following properties:name
string
. The name of the command to update. This must match the name of an existing command, as given for example in thename
property of thecommands.Command
object.description
Optionalstring
. A new description to set for the command.shortcut
Optionalstring
. A new shortcut to set for the command. This can be:- an empty string to clear the shortcut.
- a string matching the format of the
commands
manifest.json key to set a new shortcut key. If the string does not match this format, the function throws an error.
Return value
A Promise
that will be fulfilled with no arguments when the shortcut has been updated. The promise will be rejected with an error if the command could not be found.
Browser compatibility
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Examples
Updates the command named "my-command" with the given shortcut value, when the user clicks "update":
const commandName = 'my-command';
function updateShortcut() {
browser.commands.update({
name: commandName,
shortcut: document.querySelector('#shortcut').value
});
}
document.querySelector('#update').addEventListener('click', updateShortcut);
Example extensions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论