Kernel browsers were designed to be lightweight, fast, and efficient for cloud-based browser automations at scale. They can be used as part of the Kernel app platform or connected to from another service with the Chrome DevTools Protocol.

1. Create a Kernel browser

Use our SDK to create a browser:
import { Kernel } from '@onkernel/sdk';
const kernel = new Kernel();
const kernelBrowser = await kernel.browsers.create();

2. Connect to the browser with the Chrome DevTools Protocol

Then, you can connect to the browser with any Chrome DevTools Protocol framework, such as Playwright or Puppeteer.
// Playwright
const browser = await chromium.connectOverCDP(kernelBrowser.cdp_ws_url);

// Puppeteer
const browser = await puppeteer.connect({
  browserWSEndpoint,
  defaultViewport: null, // Optional: inherit viewport from the browser
});

3. Tear it down

When you’re finished with the browser, you can delete it:
await client.browsers.deleteByID(kernel_browser.session_id);
You can also delete the browser by specifiying a timeout when you create the browser.

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.
import { Kernel } from '@onkernel/sdk';
const kernel = new Kernel();

const kernelBrowser = await kernel.browsers.create();
const browser = await chromium.connectOverCDP(kernelBrowser.cdp_ws_url);
try {
const context = await browser.contexts()[0] || (await browser.newContext());
const page = await context.pages()[0] || (await context.newPage());
await page.goto("https://www.google.com");
const title = await page.title();
} catch (error) {
console.error(error);
} finally {
await browser.close();
await kernel.browsers.deleteByID(kernelBrowser.session_id);
}