Actualmente estoy desarrollando una extensión de Chrome, solo que tengo un problema ya que onCommand.addListener no funciona en mi archivo background.js . Mi archivo manifest.json se ve así:
{ "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" } } } } Y mi archivo background.js en la carpeta js se ve así:
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); });Pero mi consola solo devuelve la prueba, incluso si presiono Ctrl-C varias veces.
Gracias de antemano