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:

  1. extension ( geturl , inincognitocontext , lasterror , onrequest , sendrequest ) https://developer.chrome.com/extensions/extension#method-geturl
  2. i18n https://developer.chrome.com/extensions/i18n
  3. runtime ( connect , getmanifest , geturl , id , onconnect , onmessage , sendmessage ) https://developer.chrome.com/extensions/runtime
  4. storage https://developer.chrome.com/extensions/storage

solution:

add code in background page or use message passing https://developer.chrome.com/extensions/messaging


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -