'Detect a user's copy with a chrome extension

I would like my chrome extension to detect the copy of a text from a user and inform me with a console log. For this, my manifest looks like this:

{
 ...
  "permissions": [
    "storage",
    "activeTab",
    "scripting"
  ],
  "background": {
    "service_worker": "js/background.js"
  },

  "commands": {
    "copy": {
      "suggested_key": {
        "default": "Ctrl+C",
        "mac": "Command+C"
      },
      "description": "Copy text",
      "global": true
    }
  }
}

and my background.js in a js file is composed of this code :

chrome.commands.onCommand.addListener(function(command){
    if(command === 'copy'){
      console.log('copié !!!');
    }
});

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