Bri*_*ner 11 google-chrome-extension
我已经从使用命令API的Chrome文档中加载了此示例扩展.
的manifest.json
{
"name": "Sample Extension Commands extension",
"description": "Press Ctrl+Shift+F (Command+Shift+F on a Mac) to open the browser action popup, press Ctrl+Shift+Y to send an event (Command+Shift+Y on a Mac).",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": ["background.js"],
"persistent": false
},
"browser_action": {
"default_popup": "browser_action.html"
},
"commands": {
"toggle-feature": {
"suggested_key": { "default": "Ctrl+Shift+Y" },
"description": "Send a 'toggle-feature' event to the extension"
},
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Shift+F",
"mac": "MacCtrl+Shift+F"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
background.js
chrome.commands.onCommand.addListener(function(command) {
console.log('onCommand event received for message: ', command);
});
Run Code Online (Sandbox Code Playgroud)
非常简单,但是侦听器回调没有被触发 - 我在控制台中没有输出,也没有任何错误.如果我使用其他API,例如标签,我的听众会被触发,它只是命令API对我不起作用.
| 归档时间: |
|
| 查看次数: |
3672 次 |
| 最近记录: |