2

I am using proxy.pac file to route my traffic in chrome browser.Whenever I change my proxy.pac file I need to manually click reapply settings button here chrome://net-internals/#proxy to make it work. My proxy.pac file will change frequently so it is difficult to manually apply changes every time.Is there a way to automate this process like any add ons or scripts.

Foxyproxy add on has a option to reload pac file automatically in Firefox but in chrome that option is not provided.

4

2 回答 2

2

我刚刚根据 Pac-Script 代理设置修改了您的代码。这意味着它只有在您拥有代理模式 pacscript 时才有效。

document.addEventListener("DOMContentLoaded", function () {
   var errorHandler = new ProxyErrorHandler();
   var persistedSettings = ProxyFormController.getPersistedSettings();     

        if (persistedSettings !== null) {           
            if (persistedSettings.regular.mode == 'pac_script') {
               // Do something every 5 seconds                
               setInterval(function() {
                  // call URL with random string to avoid URL cache
                  persistedSettings.regular.pacScript.url = 'myfile/path/for/fun.pac?nocache'+Math.floor((Math.random() * 1000) + 1);
                  chrome.proxy.settings.set({'value': persistedSettings.regular});
             }, 5000);
            }               
            chrome.proxy.settings.set({'value': persistedSettings.regular});
        }       
});
于 2016-10-06T13:42:55.330 回答
1

下载此示例 chrome 扩展https://developer.chrome.com/extensions/examples/extensions/proxy_configuration.zip并将 background.js 替换为以下脚本。在开发人员模式下加载此扩展。

document.addEventListener("DOMContentLoaded", function () {
  var errorHandler = new ProxyErrorHandler();
   var persistedSettings = ProxyFormController.getPersistedSettings();   

    setInterval(function() {
         // Do something every 5 seconds   
        if (persistedSettings !== null) {
            chrome.proxy.settings.set({'value': 'myfile/path/for/fun.pac'});
        }
    }, 5000);

});

这将每 5 秒重新加载一次 PAC 文件。

于 2016-10-06T11:19:32.573 回答