Skip to content

Commit eba6937

Browse files
committed
Add browser rendering faq
1 parent 6ab44d4 commit eba6937

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/content/docs/browser-rendering/changelog.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Changelog
44
changelog_file_name:
55
- browser-rendering
66
sidebar:
7-
order: 8
7+
order: 9
88
head: []
99
description: Review recent changes to Worker Browser Rendering.
1010
---
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: FAQ
3+
pcx_content_type: faq
4+
sidebar:
5+
order: 8
6+
head:
7+
- tag: title
8+
content: Frequently asked questions about Cloudflare Browser Rendering
9+
---
10+
11+
import { GlossaryTooltip } from "~/components";
12+
13+
## Common issues
14+
15+
16+
17+
### Code generation from strings disallowed for this context while using an Xpath selector
18+
19+
Currently it's not possible to use Xpath to select elements since this poses a security risk to Workers
20+
21+
As an alternative try to use a css selector or `page.evaluate`
22+
23+
```ts
24+
const innerHtml = await page.evaluate(() => {
25+
return (
26+
// @ts-ignore this runs on browser context
27+
new XPathEvaluator()
28+
.createExpression("/html/body/div/h1")
29+
// @ts-ignore this runs on browser context
30+
.evaluate(document, XPathResult.FIRST_ORDERED_NODE_TYPE).singleNodeValue
31+
.innerHTML
32+
);
33+
});
34+
```
35+
36+
:::note
37+
38+
Keep in mind that `page.evaluate` can only return primitive types like strings, numbers, etc.
39+
40+
Returning an `HTMLElement` won't work.
41+
42+
:::
43+
44+
### Uncaught (in response) TypeError: Cannot read properties of undefined (reading 'fetch')
45+
46+
Make sure that you are passing your Browser binding to the `puppeteer.launch` api and that you have **workers paid** plan.
47+

src/content/docs/browser-rendering/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { CardGrid, Description, LinkTitleCard, Plan, RelatedProduct } from "~/co
1313

1414
<Description>
1515

16-
Browser automation for [Cloudflare Workers](/workers/).
16+
Browser automation for [Cloudflare Workers](/workers/).
1717
</Description>
1818

1919
<Plan type="workers-paid" />

0 commit comments

Comments
 (0)