2

I know there are 3 different contexts : background, popup, web page. I want to capture/intercept a web page's console log in my extension, How can I do that?

Here is my code:

contentScript.js:

    console.log('starting>>>>');

    var log = console.log;
    
    console.log = function () { 
        log.call(this, '**** MY Console**** ');
        log.apply(this, Array.prototype.slice.call(arguments));
        // ...
        }
    };

manifest.json:

{
    "name": "my extension 01",
    "version": "1.0",
    "description": "----",

    "permissions": ["activeTab","storage","declarativeContent"],
    "background":{
        "scripts":["background.js"],
        "persistent":false
    },
    "page_action": {
      "default_popup": "popup.html"
    },

    "options_page": "options.html",

    "content_scripts": [
      {
        "matches": ["https://MY-WEBSITE/*"],
        "run_at":"document_start",
        "js": ["contentScript.js"]
      }
    ],

    "manifest_version": 2
}
TheMah
  • 378
  • 5
  • 19

0 Answers0