connectOverCDP to the session’s cdp_ws_url — no other code changes.
If you don’t need a local Playwright install and want your code to run co-located with the browser, use Playwright Execution instead. It runs the same Playwright API inside the browser’s VM and returns values back to your agent. This page covers connecting a Playwright client you run yourself.
Install
Create a browser and connect
Create a Kernel browser, then connect Playwright to itscdp_ws_url. Kernel opens a context and page for you — grab them from the connected browser rather than calling newContext.
Configure the viewport
Set the viewport when you create the browser, not through Playwright. Playwright’ssetViewportSize is a no-op over a CDP connection — the window size is fixed at browser creation. See Viewports for supported dimensions and refresh rates.
Stealth mode
Create the browser withstealth: true to harden it against bot detection. The connection is unchanged — you still connect Playwright to cdp_ws_url.
Why run Playwright on Kernel
- No local browser management. No Chromium download or version pinning on your machine — the browser runs in Kernel’s cloud.
- Persistent state. Keep cookies and login state across runs with Profiles.
- Scale out. Launch many sessions in parallel instead of contending for one local browser.
- Debuggable. Watch any session in real time with live view.
- No code rewrite. Existing Playwright scripts work as-is once you swap the launch for
connectOverCDP.
Next steps
- Playwright Execution — run Playwright inside the browser VM with no local install
- Live view — watch and debug your sessions
- Stealth mode — avoid bot detection
- Terminating sessions — clean up browsers when you’re done