Using a local proxy auto configuration (.pac) file for proxy settings from a chrome extension

5.6k views Asked by At

I want to modify the proxy settings of chrome using an extension. I want it to use a local .pac file which is present in my extension's root folder. I tried following ways to refer this pac file:

settings.pacScript.url = "proxyFile.pac"; 
settings.pacScript.url = "chrome-extension://adcccdddeeefffggghhhiiijjjkkklll/proxyFile.pac";

These two methods do not work. I tried using "chrome://net-internals" to inspect what is happening and found the following(there was no file not found error or pac javascript error):

PROXY_CONFIG_CHANGED  
                        --> old_config =
                               Use DIRECT connections.
                        --> new_config =
                               Use DIRECT connections.

Whereas the following two approaches work:

settings.pacScript.url = "C:\\Users\\username\\Desktop\\myChromeExtension\\proxyFile.pac";
settings.pacScript.url = "http://www.example.com/proxyFile.pac";

Now since I want to refer to the local file in my extension, I cannot use http url.For using file url, how do I know the url of my extension's root folder?

Looking for help on this. Thanks

1

There are 1 answers

0
fiddlemath On

In a chrome extension, you can get a URL for a file inside your extension with chrome.extension.getURL. This will return a chrome-extension:// URL.

In your case, you want:

settings.pacScript.url = chrome.extension.getURL("proxyFile.pac");