javascript - I cannot make "commands" in chrome extension work -
i trying write chrome extension. facing problems. unable make commands in chrome extension work. below given code have written. here manifest.json
file.
{ "manifest_version": 2, "name": "test", "description": "this test", "version": "1.0", "browser_action": { "default_icon": "icon.png" }, "content_scripts": [ { "matches": ["<all_urls>"], "js": ["content.js"] } ], "commands": { "toggle-feature-foo": { "suggested_key": { "default": "ctrl+shift+1", "mac": "command+shift+1" }, "description": "show alert" } } }
here content.js
file.
alert("this test 3"); chrome.commands.oncommand.addlistener(function(command) { alert('command:', command); });
the problem: can see first alert. when press ctrl+shift+1 unable see second alert. doing wrong?
content script
cannot use chrome.* apis
, exception of:
extension ( geturl , inincognitocontext , lasterror , onrequest , sendrequest )
https://developer.chrome.com/extensions/extension#method-geturli18n
https://developer.chrome.com/extensions/i18nruntime ( connect , getmanifest , geturl , id , onconnect , onmessage , sendmessage )
https://developer.chrome.com/extensions/runtimestorage
https://developer.chrome.com/extensions/storage
solution:
add code in background page
or use message passing
https://developer.chrome.com/extensions/messaging
Comments
Post a Comment