chrome.commands keyboard shortcuts not working

前端 未结 10 1257
有刺的猬
有刺的猬 2020-12-03 07:57

I am trying to add some keyboard shortcuts to my Chrome extension, specifically to allow the user to use hotkeys to open up a browser action/popup. I\'ve read the d

相关标签:
10条回答
  • 2020-12-03 08:00

    As you can see in the source code here: https://code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/extensions/api/commands/command_service.cc&l=303&sq=package:chromium&rcl=1409677023

    The key binding update is only run when OnExtensionWillBeInstalled callback is triggered.

    So you need to uninstall and reinstall your local extension to see the default keyboard command appear in : chrome://extensions/configureCommands

    0 讨论(0)
  • 2020-12-03 08:03

    I was struggling with the same issue of the "_execute_browser_action" keyboard shortcut not being set automatically despite not conflicting with any existing shortcuts.

    It turns out my problem was caused by the following:

    ...
    "commands" : {
    "_execute_browser_action": {
            "suggested_key": {
              "mac": "Alt+J",
              "linux": "Ctrl+Shift+J"
            },
          "global": true <-- this shouldn't be here
          }
    ...
    

    Removing the "global": true resolved my issue. Hope this helps.

    0 讨论(0)
  • 2020-12-03 08:05

    If you are testing your shortcut with console.log, it will not show up. Perhaps test it with chrome.tabs.create({url: "http://www.google.com/"});

    This will require permissions to "tabs".

    0 讨论(0)
  • 2020-12-03 08:08

    As per documentation:

    The user is free to designate any shortcut as global using the UI in chrome://extensions \ Keyboard Shortcuts, but the extension developer is limited to specifying only Ctrl+Shift+[0..9] as global shortcuts. This is to minimize the risk of overriding shortcuts in other applications since if, for example, Alt+P were to be allowed as global, the printing shortcut might not work in other applications.

    0 讨论(0)
  • 2020-12-03 08:17

    Somehow the keyboard shortcuts started working after I set the shortcuts to contain just one of Ctrl / Cmd / Alt / Shift. So, Alt+S worked but Alt+Shift+S did not work.

    0 讨论(0)
  • 2020-12-03 08:20

    Adding to all of the correct answers above: After removing and adding the extension in the extensions page, the shortcut still didn't apply to the current window i was working in. It only worked once i opened a new chrome window.

    0 讨论(0)
提交回复
热议问题