Skip to content

Commit 66fcbea

Browse files
committed
Update k6 browser's BrowserType.Connect documentation (#1114)
This commit updates the documentation for the k6 browser's BrowserType.Connect method by fixing the method signature and adding a dedicated page which documents the supported arguments and provides an example.
1 parent eca512d commit 66fcbea

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/data/markdown/docs/02 javascript api/07 k6-experimental/01 browser/03 BrowserType.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The `BrowserType` is the entry point into launching a browser process; `chromium
77

88
| Method | Description |
99
|-----------------------------------------------------------------------------------------|------------------------------------------------------------------------------|
10-
| browserType.connect([options]) <BWIPT id="17"/> | Connect attaches k6 browser to an existing browser instance. |
10+
| [browserType.connect(wsURL, [options])](/javascript-api/k6-browser/api/browsertype/connect/) | Connect attaches k6 browser to an existing browser instance. |
1111
| [browserType.executablePath()](/javascript-api/k6-experimental/browser/browsertype/executablepath/) | Returns the path where the extension expects to find the browser executable. |
1212
| [browserType.launch([options])](/javascript-api/k6-experimental/browser/browsertype/launch/) | Launches a new browser process. |
1313
| browserType.launchPersistentContext(userDataDir, [options]) <BWIPT id="16"/> | Launches the browser with persistent storage. |
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: 'connect(wsURL, [options])'
3+
excerpt: 'Browser module: BrowserType.connect method'
4+
---
5+
6+
Connects to an existing browser instance.
7+
8+
| Parameter | Type | Default | Description |
9+
|-------------------|----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
10+
| debug | boolean | `false` | All CDP messages and internal fine grained logs will be logged if set to `true`. |
11+
| slowMo | string | `null` | Slow down input actions and navigation by the specified time e.g. `'500ms'`. |
12+
| timeout | string | `'30s'` | Default timeout to use for various actions and navigation. |
13+
14+
15+
### Returns
16+
17+
| Type | Description |
18+
|--------|--------------------------------------------------------|
19+
| object | [Browser](/javascript-api/k6-browser/api/browser/) object |
20+
21+
22+
## Example
23+
24+
<CodeGroup labels={[]}>
25+
26+
```javascript
27+
import { chromium } from 'k6/experimental/browser';
28+
29+
export default async function () {
30+
const wsURL = 'ws://localhost:9222/devtools/browser/a7ee4f2d-35cf-4478-a333-f597e1532ab0';
31+
const browser = chromium.connect(wsURL, {
32+
debug: true,
33+
slowMo: '500ms',
34+
timeout: '30s',
35+
});
36+
const context = browser.newContext();
37+
const page = context.newPage();
38+
39+
try {
40+
await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' });
41+
page.screenshot({ path: `example-chromium.png` });
42+
} finally {
43+
page.close();
44+
browser.close();
45+
}
46+
}
47+
```
48+
49+
</CodeGroup>

0 commit comments

Comments
 (0)