我想仅对某些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,
);
所以,问题是如何在代理服务器上进行身份验证?