Skip to content

Commit e18940a

Browse files
authored
Merge pull request #1096 from grafana/update-k6-browser-example
update code example to include timeout parameter
2 parents a724418 + efc0dd8 commit e18940a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/data/markdown/docs/30 k6-browser/01 Get started/02 Running browser tests.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ To run a simple local script:
2828
import { chromium } from 'k6/experimental/browser';
2929

3030
export default async function () {
31-
const browser = chromium.launch({ headless: false });
31+
const browser = chromium.launch({
32+
headless: false,
33+
timeout: '60s', // Or whatever time you want to define
34+
});
3235
const page = browser.newPage();
3336

3437
try {
@@ -43,7 +46,9 @@ To run a simple local script:
4346

4447
</CodeGroup>
4548

46-
The preceding code imports the `chromium` [BrowserType](/javascript-api/k6-browser/api/browsertype) (currently the only available `BrowserType` implementation), and uses its `launch` method to start up a Chromium [Browser](/javascript-api/k6-browser/api/browser) process. After it starts, you can interact with it using the [browser-level APIs](/javascript-api/k6-browser/api/#browser-level-apis). This example visits a test URL, waits until the network is idle and takes a screenshot of the page. Afterwards, it closes the page and the browser.
49+
The preceding code imports the `chromium` [BrowserType](/javascript-api/k6-browser/api/browsertype) (currently the only available `BrowserType` implementation), and uses its `launch` method to start up a Chromium [Browser](/javascript-api/k6-browser/api/browser) process. Two parameters are passed to it. One is the `headless` parameter with the value `false` so you can see the browser launching, and `timeout` parameter with the value `60s` which will be the timeout used for various actions and navigation. For a full list of parameters that you can pass, check out the documentation for [BrowserType.launch()](/javascript-api/k6-browser/api/browsertype/launch/).
50+
51+
After it starts, you can interact with it using the [browser-level APIs](/javascript-api/k6-browser/api/#browser-level-apis). This example visits a test URL, waits until the network is idle and takes a screenshot of the page. Afterwards, it closes the page and the browser.
4752

4853
<Blockquote mod="note" title="">
4954

0 commit comments

Comments
 (0)