Question

I'm developing a Chrome Extension with Chrome 34 (ie, dev channel), and the new chrome.commands API, mainly to get media key support.

In my manifest.json, I'm currently just using the example code given in the official docs:

"commands": {
  "toggle-feature-foo": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y",
      "mac": "Command+Shift+Y"
    },
    "description": "Toggle feature foo"
  }
}

In my background page:

chrome.commands.getAll(function(commands){
  console.log(commands)
})

chrome.commands.onCommand.addListener(function(command) {
  console.log('Command:', command);
)}

Firstly, the keyboard shortcuts aren't registered:

Array[1]
 0: Object
   description: "Toggle feature foo"
   name: "toggle-feature-foo"
   shortcut: ""

Note how 'shortcut' is blank. https://developer.chrome.com/extensions/commands#method-getAll mentions the shortcut is only shown if it is 'active'. but I'm not sure why the shortcut wouldn't be 'active' (I'm using OS X 10.9, if that matters).

Secondly, actually hitting Cmd Shift Y, or Ctrl Shift Y, doesn't fire the event in the background page.

How can I make keyboard commands be received by my background page?

Was it helpful?

Solution

Have you checked the keyboard shortcuts box on the bottom of the extensions page to verify that your suggested keys are actually set there?

I ran into a similar problem...when I loaded my unpacked extension for development the suggested keys were not set, even if the key was available and defined in the manifest. I had to manually go and set the keys myself in the extension page. I'm not sure if this is the best solution, but I couldn't find any answers from searches. Also, when I published my extension on the chrome store, the suggested key's worked and were set automatically...so this seems to happen in dev mode only.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top