Skip to content

Commit 9b68315

Browse files
authored
docs(browser-rendering): add waitUntil guidance for JS-heavy pages (#26998)
* docs(browser-rendering): add waitUntil guidance for JS-heavy pages - Add new partial explaining gotoOptions.waitUntil for JavaScript-heavy pages - Add partial to all REST API endpoint docs - Clean up timeouts reference page with dedicated waitUntil options table - Fix default waitUntil value to domcontentloaded per API reference * docs(browser-rendering): clarify networkidle as simplest solution, waitForSelector for advanced users
1 parent de34ded commit 9b68315

File tree

10 files changed

+71
-8
lines changed

10 files changed

+71
-8
lines changed

src/content/docs/browser-rendering/reference/timeouts.mdx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,27 @@ If any of these timers exceed their limit, the request returns a timeout error.
1111

1212
Each timer controls a specific part of the rendering lifecycle — from page load, to selector load, to action.
1313

14-
| Timer | Scope |Default |Max |
15-
| -------------------------------------- | --------------- | --------------- | --------------- |
16-
| `goToOptions.timeout` | Time to wait for the page to load before timeout. | 30 s | 60 s |
17-
| `goToOptions.waitUntil` | Time until page load considered complete: <br />`load` = full page load, including resources, like images and stylesheets. <br />`Event.domcontentloaded` = waits until the DOM content has been fully loaded, fires before the page `load` event. <br />`Event.networkidle0` = there are no active network connections for at least 500 ms. <br />`Event.networkidle2` = there are no more than two active network connections for at least 500 ms. |||
18-
| `waitForSelector` | Time to wait for a specific element (any CSS selector) to appear on the page. | null | 60 s |
19-
| `waitForTimeout` | Additional amount of time to wait after the page has loaded to proceed with actions. | null | 60 s |
20-
| `actionTimeout` | Time to wait for the action itself (for example: a screenshot, PDF, or scrape) to complete after the page has loaded. | null | 5 min |
21-
| `PDFOptions.timeout` | Same as `actionTimeout`, but only applies to the [/pdf endpoint](/browser-rendering/rest-api/pdf-endpoint/). | 30 s | 5 min |
14+
| Timer | Scope | Default | Max |
15+
| ------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------- | ------ |
16+
| `goToOptions.timeout` | Time to wait for the page to load before timeout. | 30 s | 60 s |
17+
| `goToOptions.waitUntil` | Determines when page load is considered complete. Refer to [`waitUntil` options](#waituntil-options) for details. | `domcontentloaded` ||
18+
| `waitForSelector` | Time to wait for a specific element (any CSS selector) to appear on the page. | null | 60 s |
19+
| `waitForTimeout` | Additional amount of time to wait after the page has loaded to proceed with actions. | null | 60 s |
20+
| `actionTimeout` | Time to wait for the action itself (for example: a screenshot, PDF, or scrape) to complete after the page has loaded. | null | 5 min |
21+
| `PDFOptions.timeout` | Same as `actionTimeout`, but only applies to the [/pdf endpoint](/browser-rendering/rest-api/pdf-endpoint/). | 30 s | 5 min |
22+
23+
### `waitUntil` options
24+
25+
The `goToOptions.waitUntil` parameter controls when the browser considers page navigation complete. This is important for JavaScript-heavy pages where content is rendered dynamically after the initial page load.
26+
27+
| Value | Behavior |
28+
| ------------------ | ------------------------------------------------------------------------ |
29+
| `load` | Waits for the `load` event, including all resources like images and stylesheets |
30+
| `domcontentloaded` | Waits until the DOM content has been fully loaded, which fires before the `load` event (default) |
31+
| `networkidle0` | Waits until there are no network connections for at least 500 ms |
32+
| `networkidle2` | Waits until there are no more than two network connections for at least 500 ms |
33+
34+
For pages that rely on JavaScript to render content, use `networkidle0` or `networkidle2` to ensure the page is fully rendered before extraction.
2235

2336
## Notes and recommendations
2437
You can set multiple timers — as long as one is complete, the request will fire.

src/content/docs/browser-rendering/rest-api/content-endpoint.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
8383

8484
Many more options exist, like setting HTTP headers using `setExtraHTTPHeaders`, setting `cookies`, and using `gotoOptions` to control page load behaviour - check the endpoint [reference](/api/resources/browser_rendering/subresources/content/methods/create/) for all available parameters.
8585

86+
<Render
87+
file="javascript-heavy-pages"
88+
product="browser-rendering"
89+
/>
90+
8691
<Render
8792
file="setting-custom-user-agent"
8893
product="browser-rendering"

src/content/docs/browser-rendering/rest-api/json-endpoint.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ In this example, Browser Rendering first calls Anthropic's Claude Sonnet 4 model
375375
]
376376
```
377377
378+
<Render file="javascript-heavy-pages" product="browser-rendering" />
379+
378380
<Render file="setting-custom-user-agent" product="browser-rendering" />
379381
380382
<Render file="faq" product="browser-rendering" />

src/content/docs/browser-rendering/rest-api/links-endpoint.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
255255
}'
256256
```
257257

258+
<Render file="javascript-heavy-pages" product="browser-rendering" />
259+
258260
<Render file="setting-custom-user-agent" product="browser-rendering" />
259261

260262
<Render file="faq" product="browser-rendering" />

src/content/docs/browser-rendering/rest-api/markdown-endpoint.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browse
116116
}
117117
```
118118

119+
<Render
120+
file="javascript-heavy-pages"
121+
product="browser-rendering"
122+
/>
123+
119124
<Render
120125
file="setting-custom-user-agent"
121126
product="browser-rendering"

src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
201201

202202
If your PDF requires a font that is not pre-installed in the Browser Rendering environment, you can load custom fonts using the `addStyleTag` parameter. For instructions and examples, refer to [Use your own custom font](/browser-rendering/reference/supported-fonts/#rest-api).
203203

204+
<Render
205+
file="javascript-heavy-pages"
206+
product="browser-rendering"
207+
/>
208+
204209
<Render
205210
file="setting-custom-user-agent"
206211
product="browser-rendering"

src/content/docs/browser-rendering/rest-api/scrape-endpoint.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ Many more options exist, like setting HTTP credentials using `authenticate`, set
126126
Visit the [Browser Rendering API reference](/api/resources/browser_rendering/subresources/scrape/methods/create/) for all available parameters, such as setting HTTP credentials using `authenticate`, setting `cookies`, and customizing load behavior using `gotoOptions`.
127127
:::
128128

129+
<Render
130+
file="javascript-heavy-pages"
131+
product="browser-rendering"
132+
/>
133+
129134
<Render
130135
file="setting-custom-user-agent"
131136
product="browser-rendering"

src/content/docs/browser-rendering/rest-api/screenshot-endpoint.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
186186

187187
Many more options exist, like setting HTTP credentials using `authenticate`, setting `cookies`, and using `gotoOptions` to control page load behaviour - check the endpoint [reference](/api/resources/browser_rendering/subresources/screenshot/methods/create/) for all available parameters.
188188

189+
<Render
190+
file="javascript-heavy-pages"
191+
product="browser-rendering"
192+
/>
193+
189194
<Render
190195
file="setting-custom-user-agent"
191196
product="browser-rendering"

src/content/docs/browser-rendering/rest-api/snapshot.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
133133
product="browser-rendering"
134134
/>
135135

136+
<Render
137+
file="javascript-heavy-pages"
138+
product="browser-rendering"
139+
/>
140+
136141
<Render
137142
file="setting-custom-user-agent"
138143
product="browser-rendering"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### Handling JavaScript-heavy pages
2+
3+
For JavaScript-heavy pages or Single Page Applications (SPAs), the default page load behavior may return empty or incomplete results. This happens because the browser considers the page loaded before JavaScript has finished rendering the content.
4+
5+
The simplest solution is to use the `gotoOptions.waitUntil` parameter set to `networkidle0` or `networkidle2`:
6+
7+
```json
8+
{
9+
"url": "https://example.com",
10+
"gotoOptions": {
11+
"waitUntil": "networkidle0"
12+
}
13+
}
14+
```
15+
16+
For faster responses, advanced users can use `waitForSelector` to wait for a specific element instead of waiting for all network activity to stop. This requires knowing which CSS selector indicates the content you need has loaded. For more details, refer to [REST API timeouts](/browser-rendering/reference/timeouts/).

0 commit comments

Comments
 (0)