I am currently developing a chrome extension, only, I am facing a problem since onCommand.addListener is not working in my background.js file. My manifest.json file looks like this:
{
"manifest_version": 3,
"name": "Copy",
"version": "1.0.0",
"permissions": [
"storage",
"activeTab",
"scripting"
],
"background": {
"service_worker": "js/background.js"
},
"commands": {
"run-foo": {
"suggested_key": {
"default": "Ctrl+Shift+Y",
"mac": "Command+Shift+Y"
},
"description": "Run \"foo\" on the current page."
},
"_execute_action": {
"suggested_key": {
"windows": "Ctrl+Shift+Y",
"mac": "Command+Shift+Y",
"chromeos": "Ctrl+Shift+U",
"linux": "Ctrl+Shift+J"
}
}
}
}
And my background.js file in the js folder looks like this:
console.log('test');
chrome.commands.onCommand.addListener(function(command){
if(command === 'run-foo'){
sendResponse({data: window.getSelection().toString()});
console.log('copié !!!');
let copieText = 'je suis le texte copié';
}
});
chrome.commands.onCommand.addListener(function(command) {
console.log('onCommand event received for message: ', command);
});
But my console only returns the test, even if I press Ctrl-C several times.
Thank you in advance