Chrome extension error with 'onCommand'

风格不统一 提交于 2019-11-29 16:51:06

The chrome.commands is not available by content_scripts (as defined in https://developer.chrome.com/extensions/content_scripts).

To get it working you can change your manifest to :

{
  "name": "Test",
  "description": "Key command test.",
  "version": "1.0",
  "manifest_version": 2,
  "permissions": [
    "<all_urls>"
  ],
  "background":
    {
    "scripts": ["background_test.js"],
    "persistent": true
    },

  "commands": {
    "Ctrl+M": {
      "suggested_key": {
        "default": "Ctrl+M",
        "mac": "Command+M"
      },
      "description": "Ctrl+M."
    },
    "Ctrl+L": {
      "suggested_key": {
        "default": "Ctrl+L",
        "mac": "Command+L"
      },
      "description": "Ctrl+L"
    }
  }
}

In addition Ctlr+L is not working (at least on Mac) as already used by chrome to get focus on adress bar.

The element will be visible in the console of the extension. To see it open chrome://extensions/ and click on the Inspect views: background page of your extension.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!