Skip to content

Commit dc6943c

Browse files
authored
Merge pull request #1345 from grafana/update-k6-browser-docs
docs: update k6 browser documentation
2 parents c22b9c7 + 8acbb5c commit dc6943c

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

src/data/markdown/translated-guides/en/03 Using k6 browser/01 Overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This module aims to provide rough compatibility with the Playwright API, so you
1313

1414
<Blockquote mod="note" title="">
1515

16-
To work with the browser module, make sure you are using the latest [k6 version](https://github.com/grafana/k6/releases).
16+
To work with the browser module, make sure you are using the latest [k6 version](https://github.com/grafana/k6/releases), and install a Chromium-based browser on your machine (such as [Google Chrome](https://www.google.com/chrome/)).
1717

1818
</Blockquote>
1919

src/data/markdown/translated-guides/en/03 Using k6 browser/02 Running browser tests.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Note that providing an `executor` and setting the `browser` scenario option's `t
5050

5151
try {
5252
await page.goto('https://test.k6.io/');
53-
page.screenshot({ path: 'screenshot.png' });
53+
page.screenshot({ path: 'screenshots/screenshot.png' });
5454
} finally {
5555
page.close();
5656
}
@@ -90,7 +90,7 @@ $ k6 run script.js
9090
#
9191
# You can find an example of a hardened SECCOMP profile in:
9292
# https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json.
93-
docker run --rm -i grafana/k6:master-with-browser run - <script.js
93+
docker run --rm -i -v $(pwd):/home/k6/screenshots grafana/k6:master-with-browser run - <script.js
9494
```
9595

9696
```bash
@@ -122,7 +122,7 @@ $ K6_BROWSER_HEADLESS=false k6 run script.js
122122
#
123123
# You can find an example of a hardened SECCOMP profile in:
124124
# https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json.
125-
docker run --rm -i -e K6_BROWSER_HEADLESS=false grafana/k6:master-with-browser run - <script.js
125+
docker run --rm -i -v $(pwd):/home/k6/screenshots -e K6_BROWSER_HEADLESS=false grafana/k6:master-with-browser run - <script.js
126126
```
127127

128128
```bash
@@ -184,7 +184,7 @@ export default async function () {
184184
page.locator('input[name="login"]').type('admin');
185185
page.locator('input[name="password"]').type('123');
186186

187-
page.screenshot({ path: 'screenshot.png' });
187+
page.screenshot({ path: 'screenshots/screenshot.png' });
188188
} finally {
189189
page.close();
190190
}

src/data/markdown/translated-guides/en/03 Using k6 browser/04 Migrating to k6 v0-46.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ Now, all that is needed is to specify the `browser.type` within the [scenario op
112112

113113
With the removal of the `chromium.launch()` and `chromium.connect()` methods, setting browsers options is now done by using environment variables. For more information, refer to [Browser Module Options](/javascript-api/k6-experimental/browser/#browser-module-options).
114114

115+
### Launching a browser
116+
115117
Before:
116118

117119
<CodeGroup lineNumbers={[true]}>
@@ -161,6 +163,56 @@ PS C:\k6> $env:K6_BROWSER_HEADLESS="false" ; $env:K6_BROWSER_TIMEOUT='60s' ; k6
161163

162164
</CodeGroup>
163165

166+
### Connecting to a remote browser
167+
168+
Before:
169+
170+
<CodeGroup lineNumbers={[true]}>
171+
172+
<!-- eslint-skip -->
173+
174+
```javascript
175+
export default async function () {
176+
const remoteURL = 'REMOTE_URL'
177+
const browser = chromium.connect(remoteURL);
178+
const page = browser.newPage();
179+
}
180+
```
181+
182+
</CodeGroup>
183+
184+
After:
185+
186+
<CodeGroup labels={["Bash", "Docker", "Windows: CMD", "Windows: PowerShell"]} lineNumbers={[false]}>
187+
188+
```bash
189+
$ K6_BROWSER_WS_URL='REMOTE_URL' k6 run script.js
190+
```
191+
192+
```bash
193+
# WARNING!
194+
# The grafana/k6:master-with-browser image launches a Chrome browser by setting the
195+
# 'no-sandbox' argument. Only use it with trustworthy websites.
196+
#
197+
# As an alternative, you can use a Docker SECCOMP profile instead, and overwrite the
198+
# Chrome arguments to not use 'no-sandbox' such as:
199+
# docker container run --rm -i -e K6_BROWSER_ARGS='' --security-opt seccomp=$(pwd)/chrome.json grafana/k6:master-with-browser run - <script.js
200+
#
201+
# You can find an example of a hardened SECCOMP profile in:
202+
# https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json.
203+
docker run --rm -i -e K6_BROWSER_WS_URL='REMOTE_URL' grafana/k6:master-with-browser run - <script.js
204+
```
205+
206+
```bash
207+
C:\k6> set "K6_BROWSER_WS_URL='REMOTE_URL'" && set "K6_BROWSER_TIMEOUT='60s' && k6 run script.js
208+
```
209+
210+
```bash
211+
PS C:\k6> $env:K6_BROWSER_WS_URL='REMOTE_URL' ; k6 run script.js
212+
```
213+
214+
</CodeGroup>
215+
164216
<Blockquote mod="note" title="">
165217
166218
The following browser options are no longer supported: `devtools`, `env`, and `proxy` since they weren't providing much value. `slowMo` has been temporarily removed, and we're working on reintroducing it.

0 commit comments

Comments
 (0)