0

Is it possible to test a Proxy auto-config (PAC) script by manually executing the FindProxyForURL(url, host) function from the browser JavaScript console?

Can the internal implementation of the PAC functions (such as dnsDomainIs, shExpMatch, isInNet) be accessed from the console?

Alternatively can these functions be implemented within standard JavaScript to allow the FindProxyForURL function to be executed manually?

The only way I can find to debug the proxy.pac script within the browser is to add alert() statements and let the browser execute it internally. Being able to add breakpoints and manually step through the FindProxyForURL function would make debugging it easier.

There are many external tools for testing PAC scripts, such as pacparser (which uses Spidermonkey) and autoprox (which uses Microsofts implementation)

Similar questions have been asked:

How to discover de proxy used in a pac
How to get access log of PAC(proxy auto config)
Debugging autoproxy (PAC) javascript with alert()?
Where in Windows is the Javascript file which contains functions for executing PAC files?

Community
  • 1
  • 1
ryanmonk
  • 161
  • 1
  • 7

1 Answers1

2

Some of the PAC functions have been implemented by pactester and available in pac_utils.js: https://github.com/manugarg/pactester/blob/master/pac_utils.js

However it is missing the functions dnsResolve and myIpAddress as noted in the pactester readme:

PAC files use certain JavaScript functions. These functions have been defined in pac_utils.js file included with this tool (This file was generated using another file from Mozilla source code). Also, since JavaScript has no DNS resolving capability which is required by the "dnsResolve" and "myIpAddress" functions in the PAC files, these functions have been defined in perl and then exported to a JavaScript context.

There are implementations of these functions using web services but they won't work with local addresses without running your own server:

dnsResolve:
Can I perform a DNS lookup (hostname to IP address) using client-side Javascript?
Perform a DNS lookup to resolve a hostname to an IP address using JavaScript

myIpAddress:
How to get client's IP address using javascript only?

I don't know if it's possible to make any browsers grant access to manually execute scripts within the PAC sandbox environment which hosts the native implementation of these functions.

PAC files run in a browser sandbox thus don’t have access to the entire JavaScript programming language. Instead, PAC file functionality is implemented in a browser with a custom sanboxed function set.

Community
  • 1
  • 1
ryanmonk
  • 161
  • 1
  • 7