我为自己和我的同事设置了Chrome扩展程序(版本40)。在Chrome扩展中使用PAC文件重定向HTTPS请求似乎失败
它的一个功能是自动将在浏览器中接收到的请求重定向到我们的临时服务器IP地址。这使得我们可以避免编辑主机文件来按照目前的做法在分段和生产之间切换。每分钟计数..
无论如何,下面的脚本,我设置完美的作品使用代理配置HTTP请求。但是,当试图在使用https请求url的网站上运行它时,它会失败,并显示以下错误消息。
网:: ERR_TUNNEL_CONNECTION_FAILED
下面是我成立至今代码的主要依据。
PAC File:https://awesomeurl.com/proxy.pac
function FindProxyForURL(url, host) {
var domains = ["url1", "url2", "url3", "url4"], // fake company urls
base = ".awesomecompany.com",
ii;
// our local URLs from the domains below example.com don"t need a proxy:
for(ii=0; ii<domains.length; ii++) {
if(shExpMatch(host, domains[ii] + base)) {
return "PROXY 11.111.111.111"; // Fake IP Address
}
}
return "DIRECT";
}
而这里的产生Chrome浏览器设置的脚本。持久性在其他地方完成。
/**
* Checks which value has been selected and generates the proxy config that will
* be used for the the chrome settings and persisted.
*
* @param {string} mode The mode requested by the user
* @return {ProxyConfig} the proxy configuration reprensented by the user's selections
* @public
*
*/
function generateProxyConfig(mode) {
switch(mode) {
case proxyValues.NORMAL:
return { mode: 'system' }
case 'production':
return {
mode: 'pac_script',
pacScript: {
url: 'https://awesomeurl.com/proxy.pac',
mandatory: true
}
}
}
}
function applyChanges (mode, cb) {
config = generateProxyConfig(mode);
chrome.proxy.settings.set({
value: config,
scope: 'regular'
}, cb);
}
applyChanges('production', function() {console.log('Why doesn't this work for https') })
我发现的唯一资源甚至是远程相关的was this one。这似乎意味着对于iOS,由于安全隐患,PAC文件不能用于重定向HTTPS通信。
我想我想看看这是否与Chrome相同。请提供任何已知的潜在解决方法。
您可以使用['webRequest' API](https://developer.chrome.com/extensions/webRequest)完全绕过代理的使用来重定向正在进行的请求。 – Xan 2015-02-09 15:50:22
我曾看过 - 但我无法弄清楚如何在['onBeforeRequest'](https://developer.chrome.com/extensions/webRequest#event-onBeforeRequest)中切换IP地址。这似乎只能从['onResponseStarted'](https://developer.chrome.com/extensions/webRequest#event-onResponseStarted)得到,这太迟了。 – ifiokjr 2015-02-09 16:26:26