# Connect to an existing Chrome with CDP

> Connect to an existing Chrome with CDP: launch it with --remote-debugging-port and its own --user-data-dir, read /json/version, then attach a client.

Source: https://mosaicbrowser.com/guides/connect-to-an-existing-chrome-with-cdp

## How to connect to an existing Chrome with CDP

Start Chrome with --remote-debugging-port=9222 and a non-default --user-data-dir, read webSocketDebuggerUrl from http://127.0.0.1:9222/json/version, and attach Playwright, Puppeteer or a raw WebSocket to it. Since Chrome 136 the port is ignored on the default profile.

![Attach to a Chrome that is already running](https://mosaicbrowser.com/covers/connect-to-an-existing-chrome-with-cdp.webp)

"Existing" is the catch. Chrome only listens for DevTools Protocol clients if it was started with a debugging port, so the Chrome you opened this morning from the Dock has nothing to attach to. To connect to an existing Chrome with CDP, you start a Chrome that listens, then connect to it as many times as you like while it runs.

## Step 1: start Chrome with a debugging port

Quit Chrome first. If it is still running, a second launch with the flags hands its command line to the open browser and quits, and no port appears.

On a Mac:

```
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
  --remote-debugging-port=9222 \
  --user-data-dir="$HOME/chrome-cdp"

```

On Windows:

```
"C:\Program Files\Google\Chrome\Application\chrome.exe" ^
  --remote-debugging-port=9222 ^
  --user-data-dir=C:\chrome-cdp

```

The `--user-data-dir` is not optional any more. Google's Chrome blog says that from Chrome 136 the debugging switches "will no longer be respected if attempting to debug the default Chrome data directory" and must be "accompanied by the --user-data-dir switch to point to a non-standard directory" ([Chrome for Developers](https://developer.chrome.com/blog/remote-debugging-port), published 17 March 2025, read 2 November 2026). The reason it gives is that infostealers had taken to using the port to extract cookies. So you cannot attach to your everyday profile; you get a separate one, and you sign in to whatever the script needs inside it.

## Step 2: find the WebSocket address

With the port open, Chrome serves a few HTTP endpoints on it. The [DevTools Protocol documentation](https://chromedevtools.github.io/devtools-protocol/) (read 2 November 2026) lists them:

- `http://127.0.0.1:9222/json/version` returns version details and `webSocketDebuggerUrl`, the browser-level socket.
- `http://127.0.0.1:9222/json/list` lists the tabs, workers and other targets, each with its own socket.
- `/devtools/browser/<id>` is the browser socket; `/devtools/page/<id>` talks to one tab.

Open `/json/version` in another browser or with `curl`. If it answers, Chrome is listening.

Mosaic is a desktop app

Email yourself the link and open it on your computer.

[How it works: REST API](https://mosaicbrowser.com/features/rest-api)

## Step 3: connect to the existing Chrome with CDP

Playwright takes either address. Its documentation shows `connectOverCDP('http://localhost:9222')` and then `browser.contexts()[0]` for the default context ([Playwright docs](https://playwright.dev/docs/api/class-browsertype#browser-type-connect-over-cdp), read 2 November 2026):

```
const browser = await chromium.connectOverCDP('http://127.0.0.1:9222')
const context = browser.contexts()[0]
const page = context.pages()[0]

```

Puppeteer takes `browserURL` for the HTTP address or `browserWSEndpoint` for the socket ([Puppeteer docs](https://pptr.dev/api/puppeteer.connectoptions), read 2 November 2026):

```
const browser = await puppeteer.connect({ browserURL: 'http://127.0.0.1:9222', defaultViewport: null })

```

With no library at all, read `/json/list`, pick a target whose `type` is `page`, open a WebSocket to its `webSocketDebuggerUrl` and send JSON messages such as `{"id":1,"method":"Page.navigate","params":{"url":"https://example.com"}}`.

More than one client can be attached at once. The protocol documentation says Chrome 63 introduced support for multiple simultaneous clients, so your script and the DevTools window can watch the same tab.

## Pick a fixed port, not 0

`--remote-debugging-port=0` lets Chrome choose a free port and write it to a `DevToolsActivePort` file in the profile folder. It has a cost a page can read: MDN lists the `--remote-debugging-port` flag "specifying port 0" among the cases in which Chrome sets `navigator.webdriver` to `true` ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/webdriver), read 2 November 2026). A fixed port leaves it alone.

## When something does not connect

Three failures cover most of what goes wrong. If `/json/version` does not answer at all, Chrome did not take the flag: either another Chrome was already running and swallowed the launch, or the switch was given without `--user-data-dir` on Chrome 136 or later. Quit every Chrome window and launch again.

If `/json/version` answers but the client times out, check the address. Chrome listens on `127.0.0.1`, and on some machines `localhost` resolves to the IPv6 address first, which nothing is listening on. Writing `127.0.0.1` in full removes the guess.

If the client connects and sees no pages, it attached to the browser target and the window has no tab yet. Open one from the script, or point a raw WebSocket at a target from `/json/list` instead of the browser socket.

## What a site can still see

Connecting over CDP does not hide that a script is driving. The browser is your own machine with its own fingerprint and your own IP address. And Puppeteer and Playwright rely on the DevTools command `Runtime.Enable`, which the rebrowser project documents pages detecting ([the project's write-up on GitHub](https://github.com/rebrowser/rebrowser-patches), read 2 November 2026). On our engine we measured that one call flipping deviceandbrowserinfo's verdict from `isBot=false` to `isBot=true`, while `Page.enable` and `Input.dispatchKeyEvent` left it alone.

## The same thing for many profiles in Mosaic

In Mosaic you never pass the flags yourself. `POST /profiles/:id/start` on the [local REST API](https://mosaicbrowser.com/features/rest-api) launches the profile with its own data folder, fingerprint, proxy and cookies, picks a free port for it, and returns both `debugPort` and `wsEndpoint`. Each running profile has its own port, so ten profiles are ten separate CDP endpoints. `/json/list` on that port works exactly as above.

![Mosaic's API screen, Automation tab: start a profile, then attach Playwright to its wsEndpoint](https://mosaicbrowser.com/shots/api-automation.png)
*API › Automation has Playwright, Puppeteer and raw CDP examples*

The attach steps for each library, and the defaults to switch off, are in [using Playwright with an anti-detect browser](https://mosaicbrowser.com/guides/use-playwright-with-an-anti-detect-browser) and the [Puppeteer version](https://mosaicbrowser.com/guides/use-puppeteer-with-an-anti-detect-browser). What the rest of Mosaic's local API offers is in [the local API explainer](https://mosaicbrowser.com/guides/anti-detect-browser-local-api). It is part of Pro, $25 a month, charged at checkout.

## Sources

1. [Chrome for Developers: Changes to remote debugging switches to improve security](https://developer.chrome.com/blog/remote-debugging-port), read November 2, 2026
2. [Chrome DevTools Protocol documentation](https://chromedevtools.github.io/devtools-protocol/), read November 2, 2026
3. [Playwright docs: BrowserType.connectOverCDP](https://playwright.dev/docs/api/class-browsertype#browser-type-connect-over-cdp), read November 2, 2026
4. [Puppeteer docs: ConnectOptions](https://pptr.dev/api/puppeteer.connectoptions), read November 2, 2026
5. [rebrowser-patches: Runtime.Enable leak (GitHub)](https://github.com/rebrowser/rebrowser-patches), read November 2, 2026
6. [MDN: Navigator.webdriver](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/webdriver), read November 2, 2026

## Questions

### Can I attach to the Chrome I already have open?

Not unless it was started with a debugging port. A Chrome running without the flag has no port to connect to, and launching Chrome again with the flag while it is open hands the request to the running browser. Quit it and start it again with the flags.

### Why does --remote-debugging-port do nothing on my normal profile?

From Chrome 136, Google's blog says the switch is no longer respected on the default Chrome data directory. It must come with --user-data-dir pointing at a different folder, because infostealers were using the port to pull cookies out of people's main profiles.

### Is it safe to leave a debugging port open?

Treat it as a key to that browser. Any program on the computer can connect to it and read cookies or drive pages. Use a separate data folder, bind to 127.0.0.1, and close Chrome when the work is done.

### Can two tools be connected to the same Chrome at once?

Yes. The Chrome DevTools Protocol documentation says Chrome 63 added support for multiple simultaneous clients.

## Related

[How to use Playwright with an anti-detect browser](https://mosaicbrowser.com/guides/use-playwright-with-an-anti-detect-browser): Use Playwright with an anti-detect browser by starting the profile first and attaching with connectOverCDP. Keep its context; leave the fingerprint alone.

[How to use Puppeteer with an anti-detect browser](https://mosaicbrowser.com/guides/use-puppeteer-with-an-anti-detect-browser): Use Puppeteer with an anti-detect browser through puppeteer.connect: start the profile, pass its wsEndpoint, set defaultViewport to null, then disconnect.

[Anti-detect browser local API: what it is and what to check](https://mosaicbrowser.com/guides/anti-detect-browser-local-api): An anti-detect browser local API is an HTTP server on 127.0.0.1 that creates, starts and stops profiles and hands your script a DevTools endpoint.

[Anti-detect browser REST API: profiles from your scripts](https://mosaicbrowser.com/features/rest-api): Mosaic's anti-detect browser REST API runs on 127.0.0.1 with API keys. Create and start profiles, then attach Puppeteer or Playwright over CDP.

[Local first: your profiles stay on your computer](https://mosaicbrowser.com/features/local-first): Mosaic has no cloud copy of your profiles. Profiles, cookies and proxies stay on your computer, encrypted on disk, with app lock, daily backups and a trash.



[Sannysoft bot test explained, row by row](https://mosaicbrowser.com/guides/sannysoft-bot-test-explained): bot.sannysoft.com checks webdriver, window.chrome, plugins, languages, WebGL and a broken image for signs of a headless browser. What each row tests.



[Google's reCAPTCHA demo loads two libraries that race](https://mosaicbrowser.com/blog/grecaptcha-execute-not-a-function): grecaptcha.execute is not a function when the library is not ready, or when Enterprise owns window.grecaptcha. Google's own v3 demo loads both scripts.

## Run this guide on your own accounts

Every Mosaic profile is a fingerprint, a proxy IP and a cookie jar that agree with each other, kept on your computer. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

Mosaic is a desktop app

Email yourself the link and open it on your computer.
