javascriptgoogle-chrome-extensionxmlhttprequest

problem with intercepting XMLHttpRequest in Chrome extension


I am trying to intercept hightlighted http upload request of outlook.com when attaching a local file to email. upload request to intercept But it seems it is not intercepted at all while i do see other XMLHTTPRequest requests coming in logs. manifest.json:

{
  "name": "my extension",
  "version": "1.0.0",
  "manifest_version": 3,
  "action": {
    "default_popup": "popup.html",
    "default_icon": {
      "16": "icons/icon-16.png",
      "48": "icons/icon-48.png",
      "128": "icons/icon-128.png"
    }
  },
  "content_scripts": [
    {
      "world": "MAIN",
      "matches": [ "http://*/*", "https://*/*" ],
      "js": [
        "js/inject.js"
      ],
      "run_at": "document_end",
      "all_frames": true
    }
  ],

  "permissions": [
    "storage"
  ],
  "web_accessible_resources": [
    {
      "resources": ["js/*"],
      "matches": ["<all_urls>"]
    }
  ]
}

inject.js:

(function hookXMLHttpRequest() {
    const realOpen = XMLHttpRequest.prototype.open;
  
    XMLHttpRequest.prototype.open = function(method, url) {
      console.log(method, url);
  
      realOpen.apply(this, arguments);
    };
})();

I also tried https://github.com/jpillora/xhook, it doesn't work either.

xhook.after(function (request, response) {
     console.log(request.url);
});

Solution

  • thanks to woxxom, there is no way to intercept worker requests.