I'm setting up a Chrome Extension (version 40) for myself and my work colleagues.
One of it's functions is to automatically redirect requests that are received within the browser to our staging server IP address. This allows us to avoid editing host files to switch between staging and production as is currently done. Every minute counts..
Anyway the following script that I set up works perfectly when using the proxy config for HTTP requests. But when trying to run it on sites that request the url using https it fails with the following error.
net::ERR_TUNNEL_CONNECTION_FAILED
Here's the main gist of the code that I've set up so far.
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";
}
And here's the script that generates the Chrome settings. Persistence is done elsewhere.
/**
* 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') })
The only resource I found that was even remotely relevant was this one. It seems to imply that for iOS the PAC file can't be used to redirect HTTPS traffic due to security implications.
I guess I want to see if this is the same with Chrome. Please provide any known potential workarounds.
webRequest
API to redirect requests in-flight. – XanonBeforeRequest
. This only seems to be available fromonResponseStarted
which is too late. – ifiokjr