Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Browser Action's Popup with keyboard shortcut

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?

like image 817
Van Coding Avatar asked May 12 '11 07:05

Van Coding


People also ask

What is the shortcut key to open browser?

Ctrl+N – Open a new browser window.

What does Ctrl B do?

Alternatively referred to as Control+B, ^b, and C-b, Ctrl+B is a keyboard shortcut most often used to toggle bold text on and off. On Apple computers, the keyboard shortcut for bold is Command + B or Command + Shift + B .


2 Answers

You need to add a "commands" object to your manifest.json, as shown at https://developer.chrome.com/extensions/commands. 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" command; for a "page_action" popup, you'll need the "_execute_page_action" command. 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"
  },
  "commands": {
    "_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 commands are; you just have to experiment with different possible suggested shortcuts until you find one that actually works.

like image 115
Mark Amery Avatar answered Sep 20 '22 15:09

Mark Amery


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

like image 21
Asaf Avatar answered Sep 18 '22 15:09

Asaf