How to attach Puppeteer to an existing Chrome browser session

I’m wondering if there’s a way to link Puppeteer with a Chrome browser that’s already running on my system. Instead of letting Puppeteer start its own browser instance, I want to take control of a Chrome window that I opened manually. Is this something that can be done? I’ve been looking through the docs but can’t find a clear example of how to connect to an existing browser process. Has anyone figured out how to make Puppeteer work with a browser that’s already open and running normally?

yeah this works but you gotta kill any running chrome instances first or it won’t work. on windows, the command might be different - could be chrome.exe or you’ll need the full path. I always end all chrome processes in task manager before starting with the debug flag to avoid conflicts.

First, launch Chrome with remote debugging enabled. Run this command:

chrome --remote-debugging-port=9222

Then connect Puppeteer:

const browser = await puppeteer.connect({
  browserURL: 'http://localhost:9222'
});

This way you’re controlling the existing Chrome session instead of creating a new one.

Honestly though, all this manual setup gets old fast. I’ve been using Latenode for browser automation - it handles the connection stuff automatically so you can just focus on what you’re trying to automate.

Way more reliable than messing with Chrome flags and ports yourself. Worth checking out: https://latenode.com

Yes, it is indeed possible to attach Puppeteer to an existing Chrome session. Begin by launching Chrome with the --remote-debugging-port=9222 option to enable remote debugging. After that, use the puppeteer.connect() method to connect to the browser using browserWSEndpoint: 'ws://localhost:9222'. This approach is particularly useful for debugging purposes, especially when you’re working with sessions that have already been authenticated. Just ensure that port 9222 is not being occupied by any other applications to avoid connection issues.

Yes, you can connect Puppeteer to an existing Chrome instance. You’ll need to launch Chrome with debugging flags first though. Start Chrome manually like this: chrome --remote-debugging-port=9222 --user-data-dir=/path/to/temp/profile. Then use puppeteer.connect() with the browserURL or browserWSEndpoint pointing to that debugging port. Just remember - Chrome needs debugging enabled from launch. You can’t attach to a regular Chrome session that’s already running. I’ve done this when debugging complex web apps where I needed to keep certain browser state or extensions that don’t play nice with Puppeteer’s headless mode.

Just remember - when you connect to an existing Chrome instance, you’re stuck with whatever tabs and extensions are already running. I’ve had automation scripts break because of existing extensions, so now I always create a separate Chrome profile for Puppeteer. Add --user-data-dir=./chrome-profile to your Chrome launch command. If Chrome crashes while Puppeteer’s connected, your script will throw connection errors, so handle those exceptions. Once you get the setup right though, this debugging approach works great.