在 Chrome 扩展中拦截 XMLHttpRequest 的问题

问题描述 投票:0回答:1

我试图在将本地文件附加到电子邮件时拦截 Outlook.com 突出显示的 http 上传请求。 upload request to intercept 但它似乎根本没有被拦截,而我确实看到日志中出现其他 XMLHTTPRequest 请求。 清单.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>"]
    }
  ]
}

注入.js:

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

我也尝试过https://github.com/jpillora/xhook,也没有用。

xhook.after(function (request, response) {
     console.log(request.url);
});
javascript google-chrome-extension xmlhttprequest
1个回答
0
投票

感谢woxxom,没有办法拦截worker请求。

© www.soinside.com 2019 - 2024. All rights reserved.