google-chrome-extension

Assign command keyboard shortcut from popup or options


Is it possible with the Chrome API to let users assign a keyboard shortcut from within the extension popup or options page? Without them having to go to extensions page, scroll to the bottom and open keyboard shortcut menu.


Solution

  • In Chrome there's no method to assign a shortcut key programmatically, but you can add a button or a link in the extension popup that will open the built-in dialog.

    popup.html:

    <button id="hotkey">Assign a shortcut key</button>
    <script src="popup.js"></script>
    

    popup.js:

    document.getElementById('hotkey').onclick = () => chrome.tabs.create({
      url: 'chrome://extensions/shortcuts'
    });
    

    Notes: