我爲自己和我的同事設置了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