diff --git a/src/content/docs/browser-rendering/changelog.mdx b/src/content/docs/browser-rendering/changelog.mdx index 6d74a98bf420433..f614e3025e4f749 100644 --- a/src/content/docs/browser-rendering/changelog.mdx +++ b/src/content/docs/browser-rendering/changelog.mdx @@ -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. --- diff --git a/src/content/docs/browser-rendering/faq.mdx b/src/content/docs/browser-rendering/faq.mdx new file mode 100644 index 000000000000000..fd4da8c2601a974 --- /dev/null +++ b/src/content/docs/browser-rendering/faq.mdx @@ -0,0 +1,50 @@ +--- +title: FAQ +pcx_content_type: faq +sidebar: + order: 8 +head: + - tag: title + content: Frequently asked questions about Cloudflare Browser Rendering +--- + +import { GlossaryTooltip } from "~/components"; + +Below you will find answers to our most commonly asked questions. If you cannot find the answer you are looking for, refer to the [Discord](https://discord.cloudflare.com) to explore additional resources. + +##### 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 for Platforms Paid plan](/cloudflare-for-platforms/workers-for-platforms/platform/pricing/). + +##### Will browser rendering bypass Cloudflare's Bot Protection? + +Browser rendering requests are always identified as bots by Cloudflare. + +## Puppeteer + +##### 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` for example: + +```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. + +::: diff --git a/src/content/docs/browser-rendering/index.mdx b/src/content/docs/browser-rendering/index.mdx index 08955586084908a..05ef8c4ae6dd127 100644 --- a/src/content/docs/browser-rendering/index.mdx +++ b/src/content/docs/browser-rendering/index.mdx @@ -13,7 +13,7 @@ import { CardGrid, Description, LinkTitleCard, Plan, RelatedProduct } from "~/co -Browser automation for [Cloudflare Workers](/workers/). +Browser automation for [Cloudflare Workers](/workers/).