Testing Internal Environments with BrowserStack Local Tunneling
Learn how to use BrowserStack Local to test internal staging environments and localhost applications on a remote cloud browser grid using secure tunneling.
27 May 2026, 09:49 UTC

Solving the Remote Access Gap
Testing a website on a cloud-based browser grid usually requires the application to be hosted on a publicly accessible URL. However, most development workflows rely on localhost or internal staging servers protected by corporate firewalls. The problem is that a remote browser in a data center cannot resolve your local IP address or bypass your network's security perimeter.
The solution is BrowserStack Local, a tunneling mechanism that creates a secure connection between your local machine (or internal network) and the BrowserStack cloud. This allows you to run tests against non-public environments without exposing your entire server to the open internet.
How the Tunnel Mechanism Works
BrowserStack Local uses a binary executable to establish a secure SSH-like tunnel. When you start the binary, it authenticates with your account and opens a communication channel. When a remote browser requests a URL like http://localhost:3000, the BrowserStack proxy identifies the active tunnel associated with your account and routes that request through the tunnel to your local machine.
Implementing a Local Session
To enable this, you must run the local binary and configure your test script to use the tunnel. This guide assumes you are using the BrowserStack Local binary on a Unix-based system (macOS/Linux) and a Selenium-based framework.
Step 1: Start the Tunnel
Run the following command in your terminal. You will need your BrowserStack Access Key found in your account dashboard.
# Run as a standard user; sudo is not required unless port binding is restricted
./BrowserStackLocal --key YOUR_ACCESS_KEY
Expected Check: The terminal should output Connected to BrowserStack. If it hangs or returns a connection error, verify that outbound traffic on port 443 is permitted by your firewall.
Step 2: Configure the Test Script
Simply running the binary is not enough; the remote browser must be told to route traffic through the tunnel. This is done via the browserstack.local capability.
// Example configuration for a Selenium WebDriver setup
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("browser_version", "latest");
// This is the critical setting that enables the tunnel
capabilities.setCapability("browserstack.local", "true");
// Now you can navigate to a local address
driver.get("http://localhost:8080/home");
Advanced Routing and DNS Mapping
In many enterprise environments, localhost is insufficient because the application depends on other internal services (e.g., an API at api.internal.dev). BrowserStack Local supports custom DNS mapping to resolve these internal hostnames.
You can pass a mapping file to the binary to ensure the remote browser resolves internal domains correctly:
./BrowserStackLocal --key YOUR_ACCESS_KEY --force-local --force-local-dns
Using --force-local-dns tells the BrowserStack cloud to use the DNS settings of the machine running the binary rather than the cloud's default DNS.
Performance Limits and Common Pitfalls
While tunneling solves the accessibility problem, it introduces specific engineering trade-offs:
- Increased Latency: Every request must travel from the BrowserStack cloud to your local machine and back. This can cause tests to time out or lead to "flaky" results if your local upload speed is slow.
- Orphaned Processes: If you start the binary in the background (e.g., using
&) and your CI/CD pipeline crashes, the tunnel may remain active, potentially blocking new sessions or consuming resources. - Port Conflicts: Ensure the application you are testing is actually listening on the port you specify. The tunnel only forwards the request; it does not start your local server.
Verification Checklist
| Check | Method | Success Indicator |
|---|---|---|
| Tunnel Status | Check terminal output of binary | "Connected to BrowserStack" |
| Capability Check | Review test config/capabilities | browserstack.local: true |
| Connectivity | Run a simple driver.get() |
Page loads without 404/DNS error |
Rollback and Cleanup
Because the Local binary changes the state of your network connection by opening a tunnel, it must be terminated to release the session.
- Manual: Press
Ctrl+Cin the terminal where the binary is running. - Automated: If running in a script, use
pkill BrowserStackLocalto ensure all instances are closed before starting a new test suite.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.