javascript - Keyboard shortcut to Toggle (hide/show) my chrome extension -
i working on extension, want chrome extension toggle (show / hide) via command (mac: "cmd+shift+9" or default: "ctrl+shift+9"); though have defined command in manifest file:
{ ......... "commands": { "toggle-window": { "suggested_key": { "default": "ctrl+shift+9", "mac": "command+shift+9" }, "description": "toggle feature foo", "global": true }, ........ }
now, can in backgroundscript.js that?
my backgroundscript.js is:
chrome.commands.oncommand.addlistener(function(command) { if(command === "toggle-window") { console.log('command:', command); /* logic show/hide go here..*/ } });
how do that? thanks!
sample extension demo have "show/hide" feature implemented:
https://chrome.google.com/webstore/detail/meldium-browser-extension/fdocegmnehjgfhfjelhmaobjccoiklle
after long research got solved.. first of all, @cviejo, gave me hint problem:
"just use "_execute_browser_action" instead of "toggle-window" in manifest file, chrome handle functionality you.
i updated manifest.js file @cviejo said:
{ ......... "commands": { "_execute_browser_action": { "suggested_key": { "default": "ctrl+shift+9", "mac": "command+shift+9" } } ........ }
then, reloaded extension still didn't worked.. find keyboard shortcuts box on bottom of extensions page, read online, helps "to verify suggested keys set there on keyboard shortcuts box defined in manifest file". checked keyboard shortcuts box key not set, if key available , defined in manifest.
and stack overflow, found 1 (that major mistake): https://stackoverflow.com/a/25654514/5228251
as can see in source code here: https://code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/extensions/api/commands/command_service.cc&l=303&sq=package:chromium&rcl=1409677023
the key binding update run when onextensionwillbeinstalled callback triggered.
so need uninstall , reinstall local extension see default keyboard command appear in : chrome://extensions/configurecommands
i did uninstalled re-installed unpacked extension , checked default keyboard command appear in chrome://extensions/configurecommands
and started worked in extension...
many @cviejo , @stephane brillant...
may others.....
Comments
Post a Comment