google-chrome-extensionmicrosoft-edge-extension

Adding "Activate the extension" shortcut to Chrome Extension


I am developing a Chrome Extension for personal use and want to add a shortcut to it to activate to popup.html page (i.e. when I press the shortcut the popup.html page will show up).

For some extension I can easily do this by going to chrome://extensions/shortcuts page and assigning a shortcut against "Activate the extension" field.

But my extension is not listed there.

Do I need to add anything to the manifest.json file for my extension to appear in chrome://extensions/shortcuts page?


Solution

  • Thanks to Yu Zhou for sharing this link in his comment. It helped me to make the "Activate the extension" thing to work.

    To make the extension available in chrome://extensions/shortcuts you need to add the following in manifest.json -

    "commands": {
        "_execute_action": {
            "suggested_key": {
                "default": "Ctrl+Shift+Y"
            }
        }
    },
    

    But doing only this doesn't make the shortcut assigned to actually work. For that you need to add a background.js page -

    // in manifext.json
    "background": {
        "service_worker": "background.js"
    }
    
    // in background.js
    chrome.action.onClicked.addListener((tab) => {
        //TODO toggle dark mode in the tab
    });
    

    I am still unclear on how all these are making the popus.html to activate but it is working now.

    P.S. this is for manifest version 3