Skip to content

Commit c6d9886

Browse files
inancgumusschalksnyman
authored andcommitted
Async frame.waitForLoadState
1 parent 8b64f7d commit c6d9886

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: 'waitForLoadState(state[, options])'
3+
description: 'Browser module: frame.waitForLoadState(state[, options]) method'
4+
---
5+
6+
# waitForLoadState(state[, options])
7+
8+
{{% admonition type="caution" %}}
9+
10+
This method has **known issues**. For details, refer to [#880](https://github.com/grafana/xk6-browser/issues/880).
11+
12+
{{% /admonition %}}
13+
14+
This waits for the given load state to be reached. It will immediately unblock if that lifecycle event has already been received.
15+
16+
<TableWithNestedRows>
17+
18+
| Parameter | Type | Default | Description |
19+
| --------------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
20+
| state | string | `load` | Optional load state to wait for. See [Events](#events) for more details. |
21+
| options | object | `null` | |
22+
| options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/). |
23+
24+
</TableWithNestedRows>
25+
26+
### Events
27+
28+
{{% admonition type="caution" %}}
29+
30+
`networkidle` is DISCOURAGED. Don't use this method for testing especially with chatty websites where the event may never fire, rely on web assertions to assess readiness instead.
31+
32+
{{% /admonition %}}
33+
34+
Events can be either:
35+
36+
- `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
37+
- `'load'` - consider operation to be finished when the `load` event is fired.
38+
- `'networkidle'` - Consider operation to be finished when there are no network connections for at least `500` ms.
39+
40+
### Returns
41+
42+
| Type | Description |
43+
| --------------- | ------------------------------------------------------- |
44+
| `Promise<void>` | A Promise that fulfills when the load state is reached. |

0 commit comments

Comments
 (0)