Use BrowserType.ConnectAsync when the browser was started by Playwright Server or launchServer and you have its Playwright WebSocket endpoint. Use Chromium.ConnectOverCDPAsync when an already-running Chrome, Edge, Chromium, or WebView2 instance exposes a Chrome DevTools Protocol (CDP) endpoint. After connecting, inspect the existing contexts and pages; do not assume that NewPageAsync() is the right first operation.
Choose the connection method
| Method | Endpoint | Browser coverage | Fidelity and coupling |
|---|---|---|---|
ConnectAsync |
Playwright protocol WebSocket returned by BrowserServer.wsEndpoint or exposed by Playwright Server |
Playwright-supported browser types | Full Playwright protocol behavior; connecting client and launcher must share the same major and minor Playwright version |
ConnectOverCDPAsync |
CDP HTTP endpoint such as http://localhost:9222, or a browser WebSocket such as ws://127.0.0.1:9222/devtools/browser/<id> |
Chromium-based browsers only | Significantly lower fidelity than the Playwright protocol; useful for interoperability with an independently launched browser |
There is no discovery step built into either API. Your program must receive a reachable endpoint, and the remote browser must already be listening on it. A normal desktop Chrome started from a shortcut does not automatically expose CDP.
Prerequisites for a .NET client
- Install the
Microsoft.PlaywrightNuGet package and build your .NET application. - For a Playwright-protocol connection, run a Playwright server or start a browser with
launchServer, then copy its WebSocket endpoint. - For CDP, start Chromium with remote debugging enabled, or configure WebView2 to expose a remote-debugging port.
- Make sure the endpoint is reachable from the machine running the .NET client. A port bound to
127.0.0.1is not reachable from another host unless you provide a suitable tunnel or bind address.
Connect to Playwright Server with ConnectAsync
This route is the preferred choice when both sides are under your control and you need Playwright’s normal protocol semantics. The endpoint is a WebSocket URL, not the browser’s ordinary web address.
using Microsoft.Playwright;
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.ConnectAsync("ws://127.0.0.1:3000/");
var contexts = browser.Contexts;
if (contexts.Count == 0)
throw new InvalidOperationException("The connected browser has no contexts.");
var context = contexts[0];
var page = context.Pages.Count > 0
? context.Pages[0]
: await context.NewPageAsync();
Console.WriteLine($"URL: {page.Url}");
Obtaining the endpoint
A process that calls Playwright’s launchServer receives a BrowserServer.wsEndpoint. Pass that exact value to the .NET client’s ConnectAsync. Playwright Server similarly exposes a WebSocket endpoint for remote clients. Do not replace it with an HTTP URL or guess a port.
#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
Keep versions aligned
The Playwright instance that launches the browser and the instance that connects to it must match in major and minor version. For example, a 1.2.3 client is compatible with the 1.2.x line, but not with an arbitrary newer or older minor release. Pin the package version in both applications and upgrade them together when possible.
Attach to an existing Chrome or Chromium browser with CDP
Start Chrome, Edge, or another Chromium-based browser with remote debugging enabled. A common local endpoint is http://localhost:9222. Then attach from C#:
using Microsoft.Playwright;
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.ConnectOverCDPAsync("http://localhost:9222");
if (browser.Contexts.Count == 0)
throw new InvalidOperationException("CDP exposed no browser contexts.");
var defaultContext = browser.Contexts[0];
var page = defaultContext.Pages.Count > 0
? defaultContext.Pages[0]
: await defaultContext.NewPageAsync();
Console.WriteLine($"Attached to: {page.Url}");
ConnectOverCDPAsync also accepts a CDP browser WebSocket URL, for example ws://127.0.0.1:9222/devtools/browser/<id>. Current documented connection options include headers, a connection timeout, slow motion, and (where supported by your installed Playwright version) NoDefaults and IsLocal. Check the API surface of the exact package version you deploy before relying on a newer option.
Why CDP is not equivalent to Playwright protocol
CDP attachment is Chromium-only. Firefox and WebKit cannot be attached through this method; use a Playwright-supported launch or server workflow for those browsers. Playwright also describes CDP as significantly lower fidelity than ConnectAsync. A browser launched outside Playwright, without Playwright’s curated arguments, can leave some Playwright functionality unavailable or behave differently. Treat CDP as an interoperability path rather than a drop-in replacement for a Playwright-launched browser.
Find the right existing tab
A connected browser can contain several contexts and many tabs. The first context and first page are convenient for a controlled test, but production code should select deliberately.
Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
foreach (var context in browser.Contexts)
{
foreach (var candidate in context.Pages)
Console.WriteLine(candidate.Url);
}
var context = browser.Contexts[0];
var page = context.Pages.FirstOrDefault(p => p.Url.Contains("example.com"));
if (page is null)
page = context.Pages.Count > 0 ? context.Pages[0] : await context.NewPageAsync();
Use a page’s URL, title, or a page-level readiness locator to identify the tab your workflow expects. If the browser has no page in the selected context, create one only when that is part of your test or automation design.
Connect to WebView2
WebView2 must be configured to expose CDP before Playwright can attach. Add --remote-debugging-port=9222 through the WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS environment variable or through CoreWebView2EnvironmentOptions. Wait for the CoreWebView2InitializationCompleted event to report successful initialization, then connect:
var browser = await playwright.Chromium.ConnectOverCDPAsync("http://localhost:9222");
var context = browser.Contexts[0];
var page = context.Pages.Count > 0
? context.Pages[0]
: await context.NewPageAsync();
Attach only after WebView2 initialization succeeds; attempting the connection earlier can produce a refused connection or an empty target list. When running parallel test processes, give each WebView2 instance a distinct WEBVIEW2_USER_DATA_FOLDER. Sharing profile data can make instances interfere with one another and can prevent reliable startup.
Recommended Free Tools
Lifecycle and cleanup
A connected Browser represents a connection to a browser you do not necessarily own. Calling Browser.CloseAsync disconnects the client and clears contexts created by that connection; it is not the same as intentionally shutting down an independently managed desktop browser.
- Dispose the Playwright object and the connected browser with
usingorawait usingso sockets are released. - Close contexts that your code explicitly created when graceful page-close events or application cleanup matter.
- Do not close a shared context merely because your test finished; another process may be using it.
- Expect the connection to become invalid if the remote browser exits or its debugging endpoint is disabled. Reconnect only after the process has started and the endpoint responds again.
Connection options and operational guidance
Timeouts and startup ordering
Use a finite connection timeout rather than waiting indefinitely for a dead endpoint. Start the remote browser first, poll for the endpoint, and only then create the Playwright connection. For WebView2, use its initialization event as the readiness signal instead of a fixed sleep.
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Security
A debugging endpoint can provide extensive control over browser tabs and data. Keep it on a protected interface, restrict network access, and avoid exposing an unauthenticated CDP port to the public internet. If a remote service requires authentication, use the connection headers supported by your Playwright version and protect the endpoint itself.
Parallelism and profiles
Use separate user-data folders for parallel Chromium or WebView2 processes. A shared profile can lock, merge, or overwrite state. Select contexts and pages explicitly so concurrent tabs do not cause one test to operate on another test’s page.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchTroubleshooting
“No endpoint” or connection refused
Cause: the server was not started, the port is wrong, the browser is bound to another interface, or a firewall blocks it. Fix: verify the exact WebSocket returned by wsEndpoint for ConnectAsync; for CDP, verify the HTTP or WebSocket debugging endpoint from the same machine, then check host, port, and firewall rules.
Protocol version mismatch
Cause: the connecting and launching Playwright packages differ in major or minor version. Fix: pin both applications to matching versions and restart the Playwright server after upgrading.
Firefox or WebKit will not attach over CDP
Cause: CDP attachment is supported only for Chromium-based browsers. Fix: launch or serve Firefox/WebKit through Playwright and use ConnectAsync where the workflow supports it.
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
The connection succeeds but there is no page
Cause: the selected context contains no tabs, or the browser exposed a different context than expected. Fix: enumerate browser.Contexts and each context’s Pages; create a page only after confirming that the workflow requires one.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Features behave differently after CDP attachment
Cause: CDP has lower fidelity, and the browser was launched without Playwright’s expected arguments. Fix: use a Playwright Server connection for full protocol behavior, or simplify the workflow to APIs supported by the attached Chromium build.
WebView2 is not ready
Cause: the CDP port was queried before WebView2 finished initialization. Fix: wait for a successful CoreWebView2InitializationCompleted event, confirm the remote-debugging argument is applied, and then attach.
When to avoid attaching to an existing browser
Launching a browser through Playwright is usually easier to reproduce: the browser version, arguments, profile, and lifecycle are controlled by the test. Attach to an existing instance when you specifically need an interactive user’s session, a WebView2 host, a separately managed browser, or a remote browser service. For unattended CI, a Playwright-launched browser or Playwright Server generally reduces hidden state and CDP compatibility surprises.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If your goal is a clean website image or PDF rather than interactive browser automation, ScreenshotNeo provides a single HTTP request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. It also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
See the ScreenshotNeo API documentation for parameters. This is the one-call C#-independent approach:
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo includes full-page capture with lazy images, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF paper and page-range controls, custom CSS and JavaScript, clicks, selector or network-idle waits, request and resource blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, selectable cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, and an OpenAPI specification. Its parameter names are compatible with those used by other screenshot APIs, which can simplify migration. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.
FAQ
Can Playwright .NET attach to a normal Chrome window that I already opened?
Only if that Chrome process was started with remote debugging enabled and exposes a reachable CDP endpoint. A regular window without CDP cannot be discovered or attached automatically.
Should I use the HTTP CDP URL or the browser WebSocket URL?
Either form is accepted by ConnectOverCDPAsync. Use the endpoint your browser or hosting environment provides; do not convert one into the other by hand.
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 errorsDoes closing the connected browser close the user’s Chrome?
The connected object primarily disconnects the Playwright client and clears contexts created by that connection. Treat an independently managed browser as shared, and close only contexts or pages your application owns.
Frequently Asked Questions
Can Playwright .NET attach to a normal Chrome window that I already opened?
Only if that Chrome process was started with remote debugging enabled and exposes a reachable CDP endpoint. A regular window without CDP cannot be discovered or attached automatically.
Should I use the HTTP CDP URL or the browser WebSocket URL?
Either form is accepted by ConnectOverCDPAsync. Use the endpoint your browser or hosting environment provides; do not convert one into the other by hand.
Does closing the connected browser close the user’s Chrome?
The connected object primarily disconnects the Playwright client and clears contexts created by that connection. Treat an independently managed browser as shared, and close only contexts or pages your application owns.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →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.

