Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome commands API

I've loaded this sample extension from Chrome docs which uses the commands API.

manifest.json

{
"name": "Sample Extension Commands extension",
  "description": "Press Ctrl+Shift+F (Command+Shift+F on a Mac) to open the browser action popup, press Ctrl+Shift+Y to send an event (Command+Shift+Y on a Mac).",
  "version": "1.0",
  "manifest_version": 2,
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "browser_action": {
    "default_popup": "browser_action.html"
  },
  "commands": {
    "toggle-feature": {
      "suggested_key": { "default": "Ctrl+Shift+Y" },
      "description": "Send a 'toggle-feature' event to the extension"
    },
    "_execute_browser_action": {
      "suggested_key": {
        "default": "Ctrl+Shift+F",
        "mac": "MacCtrl+Shift+F"
      }
    }
  }
}

background.js

chrome.commands.onCommand.addListener(function(command) {
  console.log('onCommand event received for message: ', command);
});

Very simple, yet the listener callback is not getting triggered - I get no output in the console, nor any errors. If I use other API, for example tabs, my listeners are getting triggered as they should, it's just the commands API that doesn't work for me.

like image 743
Brian Spilner Avatar asked Oct 25 '13 21:10

Brian Spilner


People also ask

Is there an API for Chrome?

The Chrome Management API is a suite of services that allows administrators to programmatically view, manage, and get insights about policies and usage of ChromeOS devices and Chrome browsers in their organization.

How do I use Chrome commands?

To open the Command Menu: Press Control + Shift + P (Windows / Linux) or Command + Shift + P (Mac). Click. Customize and control DevTools and then select Run command.

How do I use Chrome API extension?

Use the chrome.devtools.network API to retrieve the information about network requests displayed by the Developer Tools in the Network panel. Use the chrome.devtools.panels API to integrate your extension into Developer Tools window UI: create your own panels, access existing panels, and add sidebars.


1 Answers

Commenter rsanchez provides the correct answer:

Are you working with an unpacked extension? You need to remove and re-add the extension for suggested shorcut keys to be considered.

like image 170
Michael Johansen Avatar answered Oct 08 '22 19:10

Michael Johansen