User Agents

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 ipconfig on Windows or ip addr on 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

  1. Find the remote machine's local IP address. On the remote host, run ipconfig (Windows) or ip 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.
  2. 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 to chrome.exe and a writable folder for --user-data-dir. The 0.0.0.0 address 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.
  3. 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 a webSocketDebuggerUrl such as ws://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.
  4. Install Puppeteer in your project. On the controlling machine, run npm init -y and then npm install puppeteer (or puppeteer-core if you do not want Puppeteer to download its own browser). Using puppeteer-core is often preferable here because you are connecting to an existing browser, not launching a bundled one.
  5. Write a connection script. Create a file such as connect.js with code that calls puppeteer.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 with browser.newPage(), navigate to a test URL, and close the connection with browser.disconnect() rather than browser.close() so the remote browser keeps running.
  6. 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.
  7. Harden the setup for regular use. Keep the debugging port open only on trusted networks. Consider launching the browser with a dedicated --user-data-dir so 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:9222 only 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 of browser.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/version at runtime and read webSocketDebuggerUrl from 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-core when connecting to an existing browser; it avoids downloading a second copy of Chromium.
  • Fetch the WebSocket URL programmatically with an HTTP request to /json/version so 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/version works 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-dir is a common cause.
  • Script closes the remote browser unexpectedly: Replace browser.close() with browser.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.