Skip to content

Commit

Permalink
Add browser rendering faq
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgek committed Nov 5, 2024
1 parent 6ab44d4 commit eba6937
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/content/docs/browser-rendering/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Changelog
changelog_file_name:
- browser-rendering
sidebar:
order: 8
order: 9
head: []
description: Review recent changes to Worker Browser Rendering.
---
Expand Down
47 changes: 47 additions & 0 deletions src/content/docs/browser-rendering/faq.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: FAQ
pcx_content_type: faq
sidebar:
order: 8
head:
- tag: title
content: Frequently asked questions about Cloudflare Browser Rendering
---

import { GlossaryTooltip } from "~/components";

## Common issues



### Code generation from strings disallowed for this context while using an Xpath selector

Currently it's not possible to use Xpath to select elements since this poses a security risk to Workers

As an alternative try to use a css selector or `page.evaluate`

```ts
const innerHtml = await page.evaluate(() => {
return (
// @ts-ignore this runs on browser context
new XPathEvaluator()
.createExpression("/html/body/div/h1")
// @ts-ignore this runs on browser context
.evaluate(document, XPathResult.FIRST_ORDERED_NODE_TYPE).singleNodeValue
.innerHTML
);
});
```

:::note

Keep in mind that `page.evaluate` can only return primitive types like strings, numbers, etc.

Returning an `HTMLElement` won't work.

:::

### Uncaught (in response) TypeError: Cannot read properties of undefined (reading 'fetch')

Make sure that you are passing your Browser binding to the `puppeteer.launch` api and that you have **workers paid** plan.

2 changes: 1 addition & 1 deletion src/content/docs/browser-rendering/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { CardGrid, Description, LinkTitleCard, Plan, RelatedProduct } from "~/co

<Description>

Browser automation for [Cloudflare Workers](/workers/).
Browser automation for [Cloudflare Workers](/workers/).
</Description>

<Plan type="workers-paid" />
Expand Down

0 comments on commit eba6937

Please sign in to comment.