Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/latest/javascript-api/k6-browser/close.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/latest/javascript-api/k6-browser/close/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
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-managedbrowserdoesn’t exposeclose(), 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
| Type | Description |
|---|---|
Promise<void> | A Promise that fulfills when the browser connection is closed. |
Example
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
}
}Related
- browser.isConnected - Check whether the CDP connection is still active
- chromium.connectOverCDP() - Attach to an existing browser over CDP
Was this page helpful?
Related resources from Grafana Labs

