Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging autoproxy (PAC) javascript with alert()?

I am writing a custom .pac script for use with Firefox. Following numerous examples I've seen, I intersperse alert()s in order to debug it, but no alerts popup, even though the script is clearly being invoked. (I am clicking "Reload" in the "Connection settings" after each change to my script. I have even tried restarting Firefox.)

Are alerts supposed to work from PAC scripts? Maybe this is an IE-only feature?

like image 833
Chris Noe Avatar asked Jun 23 '09 17:06

Chris Noe


People also ask

How do I view PAC files?

You can find your PAC file URL by navigating to Web Filter > Proxy Server under PAC Files.

How does proxy PAC work?

A proxy auto-configuration (PAC) file is a text file that instructs a browser to forward traffic to a proxy server, instead of directly to the destination server.

How do I use a PAC file in Firefox?

To configure PAC file mode in Mozilla Firefox:Click General. In the Network Settings section, click Settings. In the Connection Settings window, select Automatic proxy configuration URL, and enter http://<internal_IP_address>/proxy.pac . Click OK.


2 Answers

http://mxr.mozilla.org/mozilla-central/source/netwerk/base/src/nsProxyAutoConfig.js

The alert function is added to the sandbox:

80         // add predefined functions to pac
81         this._sandBox.importFunction(myIpAddress);
82         this._sandBox.importFunction(dnsResolve);
83         this._sandBox.importFunction(proxyAlert, "alert");

And the mapped function calls dump, which goes to the Error Console:

108 function proxyAlert(msg) {
109     msg = XPCSafeJSObjectWrapper(msg);
110     try {
111         // It would appear that the console service is threadsafe.
112         var cns = Components.classes["@mozilla.org/consoleservice;1"]
113                             .getService(Components.interfaces.nsIConsoleService);
114         cns.logStringMessage("PAC-alert: "+msg);
115     } catch (e) {
116         dump("PAC: proxyAlert ERROR: "+e+"\n");
117     }
like image 104
benc Avatar answered Sep 21 '22 05:09

benc


  1. Use alert function in your .pac file.

    • In Firefox Browser:

      Tools -> Web Developer -> Browser Console (Ctrl+Shift+J) [This is not Web Console!!] -> Filter output: PAC-alert

    • In Chrome Browser:

      Go to chrome://net-internals/#events -> Search for a record with description: PAC_JAVASCRIPT_ALERT

      (About Chrome, thank this answer)


Sample .pac file:

function FindProxyForURL(url, host) {
    alert("url = " + url + " *** host = " + host + " *** Resolved IP = " + dnsResolve(host));

    return "DIRECT";
}
like image 43
Mir-Ismaili Avatar answered Sep 19 '22 05:09

Mir-Ismaili