Skip to main content
No Result Found
Get your setup working faster. Join our Discord for optimisation tips from elite testers. Join our DiscordJoin our Discord

Configure Local Testing with a PAC file

Use a Proxy Auto-Configuration (PAC) file to route BrowserStack Local traffic through your organization’s proxy, with example rules and supported PAC functions.

If your organization uses a PAC file to decide which requests go through a proxy, point BrowserStack Local at the same file. Local Testing then follows your organization’s proxy rules for every product, including Automate, App Automate, Live, and App Live.

Configure a proxy using a PAC file

A Proxy Auto-Configuration (PAC) file contains a JavaScript function, FindProxyForURL, that decides whether each request goes directly to its destination or through a proxy server. Point BrowserStack Local at your PAC file to apply the same rules to Local Testing traffic.

PAC files don’t support proxy authentication. If your proxy returns HTTP error 407, see Troubleshoot PAC file issues.

Sample PAC file

The following PAC file sends requests for plain hostnames, such as localhost, directly. All other requests go through the proxy:

Copy icon Copy

If you aren’t sure what your PAC file does, or you aren’t allowed to change it, contact your network or IT team. For more examples and the list of supported PAC functions, see Example PAC file rules.

Add the PAC file to BrowserStack Local

The PAC file must be on the machine that runs BrowserStack Local. If your PAC file is hosted at a URL, download it and use the absolute path of the downloaded file.

Choose how you run BrowserStack Local and complete the steps:

Add the absolute path of your PAC file to your browserstack.yml file:

browserstack.yml
Copy icon Copy

Example PAC file rules

BrowserStack Local evaluates the FindProxyForURL(url, host) function in your PAC file for each request. Write your rules using the host parameter, because rules based on the url parameter aren’t supported. Use the following examples as a starting point.

Route requests for one domain through a proxy, and send all other requests directly:

Copy icon Copy

Route requests for two domains through different proxies, and send all other requests directly:

Copy icon Copy

Route requests for private network addresses through a proxy, and send all other requests directly:

Copy icon Copy

Supported PAC functions

BrowserStack Local supports the following functions in PAC files:

Function Supported Notes
dateRange Yes N/A
dnsDomainIs Yes N/A
dnsDomainLevels Yes N/A
dnsResolve Yes N/A
isInNet Yes N/A
isPlainHostName Yes N/A
isResolvable Yes N/A
localHostOrDomainIs Yes N/A
myIpAddress Yes N/A
shExpMatch Yes N/A
timeRange Yes N/A
weekdayRange Yes N/A
split Yes Not part of the PAC specification. Implemented as String.prototype.split.
alert No N/A

Limitations

The following features don’t work with PAC files:

Not supported Alternative
Rules based on the url parameter of FindProxyForURL Write rules based on the host parameter.
Proxy authentication, including implicit methods such as Kerberos and NTLM Use a proxy that doesn’t require authentication, or contact your network or IT team for alternatives.
Debug Utility (--debug-utility, --debug-url) Find the proxy that your PAC file returns, and test it directly with the --proxy-host and --proxy-port flags.

Troubleshoot PAC file issues

Make sure that your PAC file is valid JavaScript and isn’t minified. In a minified file, comments can merge with the code, which stops BrowserStack Local from parsing the file.

Debug Utility (--debug-utility, --debug-url) doesn’t work with the --pac-file flag. To test connectivity, find the proxy that your PAC file returns for the site, and run the Local binary with the --proxy-host and --proxy-port flags instead.

To find the proxy, run the Local binary with your PAC file and verbose logging, --verbose 3. The logs show the proxy used for each host, for example:

[Pac Resolver] Proxy to use for example.com is proxy.example.com:8080

If these log lines don’t appear, add the --force-local and --force-proxy flags so that all traffic goes through the proxy.

PAC files don’t support authentication. If you get HTTP error 407 with BrowserStack Local but not in your browser, your network might use implicit authentication, such as Kerberos, NTLM, or a custom method. BrowserStack Local doesn’t support authentication with PAC files, so contact your network or IT team for alternatives.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle