Google chrome 在Chrome扩展中侦听HTTPS连接请求

Google chrome 在Chrome扩展中侦听HTTPS连接请求,google-chrome,google-chrome-extension,proxy,Google Chrome,Google Chrome Extension,Proxy,我正在尝试通过Chrome扩展使用HTTPS代理进行身份验证。即使我使用chrome.webRequest.onBeforeSendHeaders来设置自定义头,HTTPS代理也无法工作 我怀疑这是因为Chrome会自动向代理发送连接请求,而不会引发事件。代理检查自定义身份验证头,如果不存在,则拒绝连接 关于如何侦听连接请求,有什么想法吗?webRequestAPI正在讨论中 另请参见该链接上被onBeforeSendHeaders忽略的标题列表 因此,您不能使用webRequest影响代理

我正在尝试通过Chrome扩展使用HTTPS代理进行身份验证。即使我使用
chrome.webRequest.onBeforeSendHeaders
来设置自定义头,HTTPS代理也无法工作

我怀疑这是因为Chrome会自动向代理发送连接请求,而不会引发事件。代理检查自定义身份验证头,如果不存在,则拒绝连接


关于如何侦听连接请求,有什么想法吗?

webRequest
API正在讨论中

另请参见该链接上被
onBeforeSendHeaders
忽略的标题列表

因此,您不能使用
webRequest
影响代理

  function interceptData() {
        var xhrOverrideScript = document.createElement('script');
        xhrOverrideScript.type = 'text/javascript';
        xhrOverrideScript.innerHTML = `
        function addXMLRequestCallback(callback) {
            var oldSend, i;
            if (XMLHttpRequest.callbacks) {
                XMLHttpRequest.callbacks.push(callback);
            } else {
                XMLHttpRequest.callbacks = [callback];
                oldSend = XMLHttpRequest.prototype.send;
                XMLHttpRequest.prototype.send = function () {
                    for (i = 0; i < XMLHttpRequest.callbacks.length; i++) {
                        XMLHttpRequest.callbacks[i](this);
                    }
                    oldSend.apply(this, arguments);
                }
            }
        }

        addXMLRequestCallback(function (a) {
            a.onloadend = (xhr) => {
                if (xhr.currentTarget.responseURL.includes("api.google.com")) {
                console.log(xhr.currentTarget.response);
                }
                if (xhr.currentTarget.responseURL.includes("https://api.google.com")) {  
                console.log(xhr.currentTarget.response);
                } else {

                }
            }
        });
        document.head.prepend(xhrOverrideScript);
      }
      function checkForDOM() {
        if (document.body && document.head) {
          interceptData();
        } else {
          requestIdleCallback(checkForDOM);
        }
      }
      requestIdleCallback(checkForDOM);

马坎塔,这很有效

是的,看起来是这样。我还发现了一条铬线,上面写着这是不可能的:
"run_at": "document_start"