Skip to content

browser: add chromium.connectOverCDP for external browsers#6074

Open
pkiv wants to merge 3 commits into
grafana:masterfrom
pkiv:chromium-connect
Open

browser: add chromium.connectOverCDP for external browsers#6074
pkiv wants to merge 3 commits into
grafana:masterfrom
pkiv:chromium-connect

Conversation

@pkiv

@pkiv pkiv commented Jun 11, 2026

Copy link
Copy Markdown

What?

Scripts can connect to external CDP-compatible browsers at runtime without declaring options.browser.

import { chromium } from 'k6/browser';

export default async function () {
  const browser = await chromium.connectOverCDP('ws://...');
  const page = await browser.newPage();
  // ...
  await page.close();
  await browser.close();
}

The naming follows Playwright's chromium.connectOverCDP().

Why?

Users with their own browser infrastructure want to run k6 browser tests against their own browsers. Their flow requires a fresh WebSocket URL per session, obtained at runtime via an API call.

Note

CI failures are not related to this PR.


Re-opened from #6005 (original work by @inancgumus); commit authorship preserved.

Scripts can now connect to external browser instances at
runtime via import { chromium } from 'k6/browser' and
chromium.connect(wsURL). This bypasses the managed browser
registry entirely - users control the browser lifecycle.

Enables use cases like Browserbase where session URLs are
dynamic and fetched per-iteration from an external API.
No cloud or SM platform changes needed: scripts without
options.browser skip the entire managed browser pipeline.
Shows chromium.connectOverCDP() with an external browser
provided via K6_BROWSER_WS_URL. No options.browser needed.
@pkiv pkiv requested a review from a team as a code owner June 11, 2026 20:38
@pkiv pkiv requested review from mstoykov and szkiba and removed request for a team June 11, 2026 20:38
@cla-assistant

cla-assistant Bot commented Jun 11, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ inancgumus
❌ pkiv
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants