1. Create a Kernel browser
First, install the Kernel SDK:
- Typescript/Javascript:
npm install @onkernel/sdk - Python:
pip install kernel
2. Connect over CDP
Then, you can connect to the browser with any Chrome DevTools Protocol framework, such as Playwright or Puppeteer.3. Tear it down
When you’re finished with the browser, you can delete it:Full example
Once you’ve connected to the Kernel browser, you can do anything with it.Kernel browsers launch with a default context and page. Make sure to access
the existing context and
page
(
contexts()[0] and pages()[0]), rather than trying to create a new one.Connection notes
- CDP connections are meant to be long-lived but may eventually close. Websocket connections typically can remain active for up to 1 hour, after which they may close automatically. Browser sessions themselves are unaffected—reconnect to the same
cdp_ws_urlto continue using the browser. - Browsers persist independently of CDP. Depending on your browser persistence or timeout configuration, it will continue running even if the CDP connection closes. You can reconnect to the same
cdp_ws_urlif you’re unexpectedly disconnected. - We recommend implementing reconnect logic, as network interruptions or lifecycle events can cause CDP sessions to close. Detect disconnects and automatically re-establish a CDP connection when this occurs.

