Open source

close()

Closes the connection to the browser, along with all of its BrowserContexts and Pages.

Note

This method is only available on a browser returned by chromium.connectOverCDP(). The k6-managed browser doesn’t expose close(), because k6 owns its lifecycle.

Calling this method is optional. k6 closes the connection at the end of the iteration either way, so use close() only when you want to release it earlier. Closing an already closed browser is a no-op.

Since you manage the browser, closing the connection doesn’t stop the browser itself, which keeps running and stays available to later iterations.

Using the browser after you close it throws an error, so treat close() as the last thing you do with it.

Returns

TypeDescription
Promise<void>A Promise that fulfills when the browser connection is closed.

Example

JavaScript
import { chromium } from 'k6/browser';

export default async function () {
  const browser = await chromium.connectOverCDP(__ENV.CDP_WS_URL);
  const page = await browser.newPage();

  try {
    await page.goto('https://quickpizza.grafana.com/');
  } finally {
    await page.close();
    await browser.close(); // releases the connection, the browser keeps running
  }
}