The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To attach Playwright to an already-running Chrome or other Chromium browser, start that browser with a Chrome DevTools Protocol (CDP) endpoint and use chromium.connectOverCDP(). If the browser was started by Playwright, connect to its Playwright WebSocket endpoint with browserType.connect() instead. If you only need a login to survive between runs, use a dedicated persistent profile or saved authentication state; neither method attaches to a separate live browser.
Choose the connection method that matches your browser
“Connect to an existing session” can mean reusing a tab that is open now, connecting to a browser process started by Playwright, or keeping login state between separate runs. Those require different approaches:
| # | Preview | Product | Price | |
|---|---|---|---|---|
| 1 |
|
Search+ For Google | Buy on Amazon | |
| 2 |
|
Amazon Silk - Web Browser | Buy on Amazon | |
| 3 |
|
Web Browser Engineering | $50.00 | Buy on Amazon |
| 4 |
|
Web Browser Surfer 3rd Edition (Web Surfer Series Book 1) | $0.99 | Buy on Amazon |
| 5 |
|
Downloader for Fire, Browser... | Buy on Amazon |
| What you need | Playwright method | Key constraint |
|---|---|---|
| Attach to a running Chrome, Chromium, Edge, Electron, or other Chromium-based browser and use its open tabs | chromium.connectOverCDP(endpoint) |
The browser must expose a CDP endpoint. This method supports Chromium-based browsers and has lower fidelity than Playwright’s own protocol. |
Connect to a browser launched by Playwright’s launchServer() |
browserType.connect(wsEndpoint) |
The connecting and launching Playwright versions must have matching major and minor versions. |
| Keep cookies and local storage for later automation runs | launchPersistentContext(userDataDir) or saved authentication state |
A persistent context launches a browser; it does not attach to a separate running process. Authentication state files can contain secrets. |
The JavaScript [BrowserType API](https://playwright.dev/docs/api/class-browsertype) documents these connection choices. Python offers corresponding connect and connect_over_cdp methods in its [BrowserType API](https://playwright.dev/python/docs/api/class-browsertype).
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Attach to an already-running Chromium browser with CDP
Use CDP when the browser is already running and you need its live context or tabs. The browser must have been started with remote debugging enabled and expose an HTTP endpoint such as http://localhost:9222/, or a CDP WebSocket endpoint such as ws://localhost:9222/devtools/browser/…. The actual endpoint depends on how the browser was started.
#1 Best Overall
- google search
- google map
- google plus
- youtube music
- youtube
JavaScript: connect and select an existing tab
Install Playwright for Node.js in your project if you have not already done so. Save this as an ES module, for example attach.mjs:
import { chromium } from 'playwright';
const endpoint = process.env.CDP_ENDPOINT ?? 'http://localhost:9222/';
const browser = await chromium.connectOverCDP(endpoint);
try {
const contexts = browser.contexts();
if (contexts.length === 0) {
throw new Error('Connected, but the browser has no accessible contexts.');
}
const context = contexts[0];
const pages = context.pages();
if (pages.length === 0) {
throw new Error('Connected, but the selected context has no open pages.');
}
const page = pages[0];
console.log('Current URL:', page.url());
console.log('Title:', await page.title());
await page.getByRole('button', { name: 'Continue' }).click();
} finally {
// Disconnect this Playwright client. Do not call browser.close()
// when you intend to keep using the existing browser process.
await browser.close();
}
Set CDP_ENDPOINT to the endpoint for your browser if it is not the local default, then run node attach.mjs. The example deliberately checks that a context and page exist: a successful connection does not guarantee the browser has an open tab in the context you expect. Replace the example button locator with an action appropriate to the page.
For a quick attachment, the essential pattern is:
const browser = await chromium.connectOverCDP('http://localhost:9222');
const context = browser.contexts()[0];
const page = context.pages()[0];
Use the longer version when writing a reusable script; it handles the common case where an endpoint is reachable but there is no page to operate on.
Free tools Windows power users keep installed
One-click scans. No signup required.
Python: connect to the same CDP endpoint
The Python binding uses snake_case method names. Install the Python package with pip install playwright. This example uses the synchronous API:
Rank #2
- Easily control web videos and music with Alexa or your Fire TV remote
- Watch videos from any website on the best screen in your home
- Bookmark sites and save passwords to quickly access your favorite content
import os
from playwright.sync_api import sync_playwright
endpoint = os.environ.get("CDP_ENDPOINT", "http://localhost:9222/")
with sync_playwright() as p:
browser = p.chromium.connect_over_cdp(endpoint)
contexts = browser.contexts
if not contexts:
raise RuntimeError("Connected, but the browser has no accessible contexts.")
context = contexts[0]
pages = context.pages
if not pages:
raise RuntimeError("Connected, but the selected context has no open pages.")
page = pages[0]
print("Current URL:", page.url)
print("Title:", page.title())
page.get_by_role("button", name="Continue").click()
# Leaving the sync_playwright block ends this client connection.
# Avoid explicitly closing the browser if you need its process to remain open.
The Python BrowserType API gives the binding-specific signatures. If you use Playwright’s asynchronous Python API, the connection method is still connect_over_cdp; use the async API’s await conventions for connecting, reading pages, and performing actions.
Starting the browser with a debugging endpoint
The connection code cannot enable debugging on a browser that was started without it. Start the browser with remote debugging configured, then connect to the endpoint it exposes. Startup steps and policies vary by operating system, browser distribution, and managed-device settings; use the current documentation for the specific browser and machine. Playwright’s [CLI attach and detach guide](https://playwright.dev/docs/cli) discusses CDP targets, while its [MCP browser extension guidance](https://github.com/microsoft/playwright-mcp) describes connecting to Chrome and Edge sessions and reusing tabs, cookies, and extensions.
Keep the endpoint local or access-controlled. A debugging endpoint can grant extensive control over the browser, and an exposed endpoint should be treated as a sensitive credential rather than a harmless status URL.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Connect to a browser launched by Playwright
If your application controls the browser launch, prefer Playwright’s own protocol connection. The process that launches the browser calls launchServer(), obtains wsEndpoint(), and gives that endpoint to the client. Do not pass a Chrome debugging URL to browserType.connect(); Chrome’s CDP endpoint belongs with connectOverCDP().
Rank #3
// launcher.mjs
import { chromium } from 'playwright';
const server = await chromium.launchServer({ headless: false });
console.log('Playwright WebSocket endpoint:', server.wsEndpoint());
// Keep this process alive while clients use the endpoint.
// client.mjs
import { chromium } from 'playwright';
const wsEndpoint = process.env.PLAYWRIGHT_WS_ENDPOINT;
if (!wsEndpoint) throw new Error('Set PLAYWRIGHT_WS_ENDPOINT first.');
const browser = await chromium.connect(wsEndpoint);
try {
const context = browser.contexts()[0];
const page = context?.pages()[0];
if (!page) throw new Error('No open page in the connected browser.');
console.log(await page.title());
} finally {
await browser.close();
}
For connect(), the Playwright instance on the client must match the launching instance’s major and minor version. This is the appropriate route when you control both ends and need the Playwright protocol rather than CDP’s compatibility trade-offs. See the [BrowserType API](https://playwright.dev/docs/api/class-browsertype) for current endpoint and version requirements.
Keep authentication between runs without attaching to a live browser
If your actual goal is “log in once, automate later,” use a separate automation profile with launchPersistentContext(userDataDir), or save and reload Playwright authentication state. Both preserve relevant session data without depending on a person’s currently open browser.
Persistent context: a dedicated browser profile
A persistent context starts the browser using the specified user data directory, where session data such as cookies and local storage can persist. It does not connect to an already-running Chrome process. Use a dedicated directory for automation; Playwright warns that automating Chrome’s regular default profile is unsupported after recent Chrome policy changes and can cause pages not to load or the browser to exit. Browsers also do not allow multiple instances to launch with the same user data directory.
import { chromium } from 'playwright';
const context = await chromium.launchPersistentContext('./automation-profile', {
headless: false,
});
const page = context.pages()[0] ?? await context.newPage();
await page.goto('https://example.com');
// Close this persistent context when the run is finished.
await context.close();
Only run one process against that profile directory at a time. A persistent profile is useful for repeatable automation, but it is not a safe shortcut for taking over a user’s everyday browser profile.
Saved authentication state: reuse login data in a new context
For a workflow that needs authenticated state but not the same live browser process, follow Playwright’s [authentication guide](https://playwright.dev/docs/auth) to save storage state and load it into a later context. State files may contain cookies and headers that let someone impersonate the account. Restrict file permissions, keep the files out of source control, and do not share them as ordinary test fixtures.
What changes when you attach over CDP
CDP is convenient because it can attach to an existing Chromium browser, but it is not the same protocol as a Playwright browser-server connection. Playwright documents CDP attachment as Chromium-only and significantly lower fidelity than connecting with browserType.connect(). That means behavior can differ, especially for advanced features; the documentation does not provide a complete feature-by-feature list, so check the current API documentation for the feature you rely on rather than assuming a specific limitation.
- Choose CDP when reusing a currently running Chromium browser or its open tabs matters most.
- Choose the Playwright WebSocket connection when you control a browser launched by Playwright and need its protocol connection.
- Choose persistent context or saved auth state when the requirement is durable login state, not a live user tab.
Browser launch arguments also matter. Playwright warns that connecting to a browser launched outside Playwright without the expected arguments can break some functionality. If a behavior fails only on the attached browser, check the connection type and startup configuration before rewriting locators or test logic.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsTroubleshoot connection and session problems
Connection refused or timeout at the endpoint
- Cause: The browser is not running, remote debugging is not enabled, the endpoint or port is wrong, or the endpoint is not reachable from the script’s environment.
- Fix: Start the browser with a CDP endpoint, verify the configured address and port, and make sure the script runs in an environment that can reach it. For containers or remote machines,
localhostrefers to the script’s own environment, not necessarily the browser host.
Connected, but there are no contexts or pages
- Cause: The attached browser has no accessible context or open page, or the script selected a context that does not contain the desired tab.
- Fix: Inspect
browser.contexts()and each context’spages(). Select a page by its URL or other identifying property instead of assuming that index zero is always the intended tab.
browserType.connect() rejects the endpoint
- Cause: A CDP debugging URL was passed to the Playwright protocol connection method, or the endpoint is not the WebSocket URL from a Playwright-launched browser server.
- Fix: Use
chromium.connectOverCDP()for a Chrome debugging endpoint. Forconnect(), supply the endpoint returned byBrowserServer.wsEndpoint().
Playwright protocol version mismatch
- Cause: The client and the Playwright process that launched the browser have different major or minor versions.
- Fix: Align the Playwright versions on both sides, then reconnect using the server’s current WebSocket endpoint.
Login disappears on the next run
- Cause: The script created a temporary context or did not load the saved authentication state.
- Fix: Use a persistent context with a dedicated user data directory, or save and load authentication state as described in the [authentication guide](https://playwright.dev/docs/auth). Protect the resulting profile or state file as sensitive data.
Chrome exits or pages fail when using a profile
- Cause: Automation is attempting to use Chrome’s regular default profile or a profile directory already in use by another browser process.
- Fix: Create a dedicated automation profile and ensure only one browser process uses that directory at a time.
Advanced action behaves differently after CDP attachment
- Cause: CDP is lower fidelity than Playwright’s own protocol, or the externally launched browser lacks expected launch arguments.
- Fix: Confirm the behavior against current Playwright documentation. If you control the browser launch and need the Playwright protocol, use
launchServer()withconnect()instead.
Security, reliability, and operating costs
Attaching to a browser means gaining access to its active pages and, potentially, its authenticated session. Do not expose a debugging endpoint to an untrusted network. Playwright’s browser-server API warns that a known WebSocket path can allow a process or web page to take control of the OS user. Restrict access to the endpoint, avoid logging secrets, and disconnect clients that no longer need access.
Best Value
- Directly enter the URL of the desired file
- Store frequently visited URLs in the favorites section for easy retrieval
- Open the downloaded files in the file manager
Protect both live-session access and saved state: a browser profile, cookie store, or authentication file may provide account access. Keep automation state in a separate location with restricted access, exclude secret-bearing files from version control, and use a dedicated test account where appropriate. For reliability, explicitly select the tab you intend to automate, confirm its URL before taking consequential actions, and avoid racing another person or process that is using the same session.
Or skip the browser setup
If your goal is a screenshot rather than interaction with a live tab, [ScreenshotNeo](https://screenshotneo.com) is a website screenshot API and MCP server for developers. One GET request can return a PNG, JPEG, WebP, or PDF; it does not require you to configure a local browser session. Use the API key from your account and see the [ScreenshotNeo API documentation](https://screenshotneo.com/docs/):
curl -G "https://api.screenshotneo.com/v1/shot"
-d access_key=YOUR_API_KEY
--data-urlencode url=https://stripe.com
-o shot.webp
ScreenshotNeo accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers identifying the page verdict and whether the request was billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.
Recommended Free Tools
Sign up for 1,000 free screenshots a month—no card required.
Sources and version-sensitive details
Playwright’s connection APIs, Chrome policies, and browser behavior can change. Consult the current [JavaScript BrowserType API](https://playwright.dev/docs/api/class-browsertype), [Python BrowserType API](https://playwright.dev/python/docs/api/class-browsertype), [authentication guide](https://playwright.dev/docs/auth), and [CLI attach and detach guide](https://playwright.dev/docs/cli) for the binding and release you use. Playwright’s [WebView2 guidance](https://playwright.dev/docs/webview2) covers an application-specific CDP case. No single CDP feature matrix is established here, so validate advanced behavior against the version and browser you run.
Frequently Asked Questions
Can Playwright attach to an already open Firefox or WebKit browser?
The CDP attachment method discussed here supports Chromium-based browsers only. This article does not establish a corresponding live-session attachment method for Firefox or WebKit.
Does closing the Playwright connection close the browser I attached to?
The CDP example uses browser.close() to end the client connection and notes that it should not be used when you intend to keep using the existing browser. For a Playwright-launched browser server, the server process owns the browser lifecycle.
Can two automation scripts share the same persistent profile directory?
No. Playwright documents that browsers do not allow multiple instances to launch with the same user data directory; use one process per automation profile.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

