How to Connect Puppeteer to a Remote Browser via Local IP
Connecting Puppeteer to a remote browser using a local IP address means launching Chrome or Chromium on one machine (the remote host) and controlling it from a Node.js script on another machine over your LAN. This is useful for testing on a different OS, reusing a long-running browser instance, or separating automation from the browser process. To do it, you start the browser with remote debugging enabled and bound to an address reachable from your network, then point Puppeteer at that WebSocket endpoint. The steps below assume both machines are on the same trusted local network and that you have administrative access to the remote host.
What You'll Need
- Node.js (version 18 or later recommended) and npm installed on the machine running Puppeteer.
- Google Chrome or Chromium installed on the remote machine, with the ability to launch it from the command line.
- The local IP address of the remote machine (for example, 192.168.1.50). You can find it with
ipconfigon Windows orip addron Linux/macOS. - Both machines on the same subnet, with no firewall blocking the debugging port (default 9222).
- Basic familiarity with the terminal and with editing a Node.js script.
Step-by-Step
- Find the remote machine's local IP address. On the remote host, run
ipconfig(Windows) orip addr show/ifconfig(Linux/macOS) and note the IPv4 address of the active network interface, such as 192.168.1.50. Avoid using 127.0.0.1, because that only works on the remote machine itself. - Launch the browser with remote debugging enabled and bound to all interfaces. On the remote machine, start Chrome with a command like:
google-chrome --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 --user-data-dir=/tmp/puppeteer-profile
On Windows, use the full path tochrome.exeand a writable folder for--user-data-dir. The0.0.0.0address makes the debugging endpoint listen on every network interface, so it is reachable from other machines. If you omit it, Chrome may bind only to localhost and remote connections will fail. - Confirm the endpoint is reachable. From the machine that will run Puppeteer, open a browser or use curl to visit
http://192.168.1.50:9222/json/version. You should see a JSON response containing awebSocketDebuggerUrlsuch asws://192.168.1.50:9222/devtools/browser/<id>. If the request times out, stop here and fix the network or firewall before writing any code. - Install Puppeteer in your project. On the controlling machine, run
npm init -yand thennpm install puppeteer(orpuppeteer-coreif you do not want Puppeteer to download its own browser). Usingpuppeteer-coreis often preferable here because you are connecting to an existing browser, not launching a bundled one. - Write a connection script. Create a file such as
connect.jswith code that callspuppeteer.connect({ browserWSEndpoint: 'ws://192.168.1.50:9222/devtools/browser/<id>' }). Replace the placeholder with the exact URL from the previous step. Then open a page withbrowser.newPage(), navigate to a test URL, and close the connection withbrowser.disconnect()rather thanbrowser.close()so the remote browser keeps running. - Run the script and verify. Execute
node connect.js. If the script prints the page title and exits without errors, the connection works. Check the remote machine's browser window to confirm a new tab appeared and navigated. - Harden the setup for regular use. Keep the debugging port open only on trusted networks. Consider launching the browser with a dedicated
--user-data-dirso profiles do not collide with normal browsing. If you need the browser to start automatically, wrap the launch command in a systemd service or a scheduled task, and log the WebSocket URL so your script can read it dynamically instead of hard-coding the ID.
Common Mistakes
- Using localhost in the WebSocket URL.
ws://127.0.0.1:9222only resolves on the remote machine. From another host you must use the remote machine's LAN IP. - Forgetting
--remote-debugging-address=0.0.0.0. Without it, Chrome may listen only on the loopback interface, and connections from other machines are refused. - Calling
browser.close()instead ofbrowser.disconnect(). Closing terminates the remote browser; disconnecting leaves it running for the next script. - Hard-coding the browser WebSocket ID. The ID changes each time Chrome restarts. Fetch
/json/versionat runtime and readwebSocketDebuggerUrlfrom the response. - Ignoring the firewall. A host firewall may allow the browser to run but block inbound TCP on port 9222. Add an explicit allow rule for that port on the trusted subnet.
- Reusing a normal user profile. Launching with the default profile can fail if Chrome is already running, and it mixes automation data with personal browsing. Always pass a separate
--user-data-dir.
Tips
- Prefer
puppeteer-corewhen connecting to an existing browser; it avoids downloading a second copy of Chromium. - Fetch the WebSocket URL programmatically with an HTTP request to
/json/versionso restarts do not break your script. - Use a fixed, non-default debugging port if 9222 is already taken by another tool.
- Keep the remote browser and your Puppeteer version reasonably close; very old browser builds may not support newer protocol commands.
- Log connection errors with the full endpoint URL; most failures are typos in the IP or port.
- Run the remote browser under a dedicated user account so its profile and permissions are isolated.
Troubleshooting
- Connection refused or timeout: Verify the IP with
ping, confirm the browser is running with the debugging flag, and check that the firewall allows TCP 9222 from your machine. /json/versionworks locally but not remotely: The browser is bound to localhost. Relaunch with--remote-debugging-address=0.0.0.0.- Puppeteer connects but commands hang: The WebSocket URL may be stale after a browser restart. Re-fetch it and reconnect.
- Browser exits immediately: Check the terminal output on the remote host; a locked or missing
--user-data-diris a common cause. - Script closes the remote browser unexpectedly: Replace
browser.close()withbrowser.disconnect(). - Works on one machine but not another: Compare subnet masks and any VLAN separation; devices on different subnets may not route to each other even with the port open.
Frequently Asked Questions
Can I connect Puppeteer to a browser on another computer?
Yes, as long as the browser is started with remote debugging enabled and bound to an address reachable over the network, and the debugging port is not blocked by a firewall.
Do I need puppeteer or puppeteer-core?
Either works. puppeteer-core is lighter because it does not download a browser, which suits connecting to an existing remote instance.
Why does my WebSocket URL stop working after a restart?
The browser ID in the URL is regenerated each launch. Query /json/version after every restart and use the returned webSocketDebuggerUrl.
Is it safe to expose the debugging port on my LAN?
Only on a trusted network. Anyone who can reach the port can control the browser, so restrict access with firewall rules and avoid exposing it to the internet.
Can multiple Puppeteer scripts connect at once?
Yes, a single browser endpoint can accept multiple connections, but coordinate page and tab usage to avoid scripts interfering with each other.
What if the remote machine has a dynamic IP?
Use a DHCP reservation or a local hostname so the address stays stable, and update your script or configuration when it changes.