如何使用FindProxyForURL验证代理?

时间:2019-09-25 11:16:58

标签: google-chrome google-chrome-extension proxy

我想仅对某些URL使用代理(受基本身份验证保护),据我所知,在Chrome中,我们可以使用PAC来实现,如下所示:

function activate(host) {
        chrome.proxy.settings.set({
            value: {
                mode: 'pac_script',
                pacScript: {
                    data: "function FindProxyForURL(url, host) {\n" +
                        "        if (host.indexOf('" + host + "') !== -1) {\n" +
                        "            return \"PROXY proxy.example.com:3129\";\n" +
                        "        } else {\n" +
                        "            return \"DIRECT\";\n" +
                        "        }\n" +
                        "    }",
                }
            },
            scope: 'regular'
        });
        return true;
    }

但是这里的问题是chrome.webRequest.onAuthRequired不起作用:

const extraInfoSpecBlocking = ['blocking'];
    const requestFilter = {urls: ['<all_urls>'], types: ['main_frame']};
    chrome.webRequest.onAuthRequired.addListener((details, asyncCallback) => {
            console.log('AUTH REQUIRED!');

            if (!details.isProxy) {
                return {};
            }

            return getAuthCredentials();
        },
        requestFilter, extraInfoSpecBlocking,
    );

所以,问题是如何在代理服务器上进行身份验证?

0 个答案:

没有答案