'Detect user's keyboard shortcut in a chrome extension
I am currently developing a chrome extension. Only, here I am confronted with a problem:
I would like my extension to detect when the user performs a keyboard shortcut and that triggers a JS function. For that, my manifest.json file looks like this:
{
"manifest_version": 3,
"name": "name",
"version": "1.0.0",
"description": "description.",
"icons":{
"16": "img/logo16.png",
"48": "img/logo48.png",
"128": "img/logo128.png"
},
"permissions": [
"storage",
"activeTab",
"scripting"
],
"background": {
"service_worker": "js/background.js"
},
"commands": {
"Restart App": {
"suggested_key": {
"default": "Ctrl+Shift+6",
"mac": "Command+Shift+6"
},
"description": "Restart my app (Debugging)"
}
}
}
My background.js file located in the js folder, contains this:
chrome.commands.onCommand.addListener(function (command)
{
if (command == "Restart App")
{
chrome.runtime.reload();
};
alert('app restart success !');
});
Only, when I launch the extension and execute the keyboard shortcut, nothing happens, no error is reported.
Would you have any ideas, thank you in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
