Chrome extensions - bypass proxy programmatically

2.9k views Asked by At

I am working on an extension where proxy is set through my extension using chrome extension proxy api(chrome.proxy.settings). Everything works fine and I get all traffic on my proxy server except the ones in bypass list of course.

Now my question is: How do we bypass the proxy set dynamically? I mean Is there a way to bypass proxy for some URLs (not in proxy bypass list) programmatically? I understand bypass list included urls/patterns are bypassed. But I require some urls to bypass proxy on the go.

Anyone faced a similar requirement? Any direct method to bypass the same dynamically or any work around would be appreciated.

1

There are 1 answers

0
Correcter On

Bypass proxy on the go? You can pull any specify adressess from your web server. What's a problem?

For example:

chrome.windows.onCreated.addListener(function() {
  var config = {
      mode: 'fixed_servers',
      rules: {
        proxyForHttp: {
          scheme: 'http',
          host: '127.0.0.1',
          port: '80'
        },
        bypassList: []
      }
    },
    proxyByUrl = 'path/to/proxiesByUrl?path=' + window.location.href;

  $.get(proxyByUrl, function(data) {
    // Set up current proxy, dependent on request URL
    config.rules.proxyForHttp.host = data.proxyAddress;
    config.rules.proxyForHttp.port = data.proxyport;
    // Excluded URL's for this proxy
    bypassList.push(data.bypassUrls);
  });
});

Match all hostnames that match the pattern . A leading "." is interpreted as a "*.". Examples: "foobar.com", "foobar.com", ".foobar.com", "foobar.com:99", "https://x..y.com:99".

For more detailed patterns of bypassList, read the official documentation.