Friday, 18 June 2021

Custom chrome extension shortcuts not working

I am creating my own chrome extension. I would like to be able to run a script after clicking a shortcut. My manifest looks like this:

{
    "name": "Test",
    "version": "0.0.1",
    "manifest_version": 2,
    "description": "Test ext",
    "homepage_url": "",
    "icons": {
      "16": "icons/test-icon.jpg",
      "48": "icons/test-icon.jpg",
      "128": "icons/test-icon.jpg"
    },
    "default_locale": "en",
    "background": {
      "scripts": ["src/bg/background.js"],
      "persistent": true
    },
    "commands":{
      "run-script": {
        "suggested_key": {
          "default": "Ctrl+E",
          "windows": "Ctrl+E",
          "mac": "Command+E"
        },
        "description": "Run",
        "global": true
      }
    },
    "browser_action": {
      "default_icon": "icons/test-icon.jpg",
      "default_title": "browser action demo",
      "default_popup": "src/browser_action/browser_action.html"
    },
    "permissions": ["tabs", "https://*/*", "storage"],
    "content_scripts": [
      {
        "matches": [
          "https://www.test.co.uk/*"
        ],
        "js": ["src/inject/inject.js"]
      }
    ]
  }

So I have extension with simple UI and start button. I would like to be able to use CTRL+E or CMD+E to run a script after that. When I go to extensions in chrome settings I see shortcut:

enter image description here

so that is fine but when I click shortcut on a page nothing happens. This is my part of background.js file:

chrome.commands.onCommand.addListener((command) => {
  console.log("Command:", command);
});

So as I understand I should get console.log that shows command that was used but I get nothing. What is wrong here?



from Custom chrome extension shortcuts not working

No comments:

Post a Comment