最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Open Browser Action's Popup with keyboard shortcut - Stack Overflow

programmeradmin2浏览0评论

I'm developing a Google Chrome extension with a Browser Action Popup. When the user clicks on the icon, the popup appears.

Is there a way to open this popup with a keyboard shortcut like CTRL+something?

I'm developing a Google Chrome extension with a Browser Action Popup. When the user clicks on the icon, the popup appears.

Is there a way to open this popup with a keyboard shortcut like CTRL+something?

Share Improve this question edited Feb 19, 2017 at 20:15 Mark Amery 155k90 gold badges428 silver badges470 bronze badges asked May 12, 2011 at 7:45 Van CodingVan Coding 24.6k25 gold badges92 silver badges137 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 10

You need to add a "mands" object to your manifest.json, as shown at https://developer.chrome./extensions/mands. If your extension's popup is a "browser_action" popup (indicated by a "browser_action" key in your manifest.json), you'll need the "_execute_browser_action" mand; for a "page_action" popup, you'll need the "_execute_page_action" mand. An example manifest.json using the former looks like this:

{
  "manifest_version": 2,
  "name": "Example Extension",
  "description": "La la la",
  "version": "1.0",
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "mands": {
    "_execute_browser_action": {
      "suggested_key": {
        "default": "Ctrl+Shift+E",
        "linux": "Ctrl+Shift+K",
        "windows": "Alt+Shift+P",
        "mac": "Alt+Shift+P"
      }
    }
  }
}

Note that, per the docs:

Certain Chrome shortcuts (e.g. window management) always take priority over Extension Command shortcuts and can not be overwritten.

As far as I know, there's no canonical list of what these mands are; you just have to experiment with different possible suggested shortcuts until you find one that actually works.

The chrome.mands api enables the user to bind hotkeys (with your suggestion for the hotkey) that will trigger mands such as opening the browser action.

Sorry, currently not possible. Here is corresponding feature request, you can star it.

发布评论

评论列表(0)

  1. 暂无评论