Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
onCommand.addListener not working in my chrome extension

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!