From 16d5d9e73955555b48815813f7e99c635b3bee14 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Fri, 21 Feb 2025 17:22:48 +0000 Subject: [PATCH 01/70] Guardails docs --- .../docs/ai-gateway/guardrails/index.mdx | 17 ++++++ .../guardrails/set-up-guardrail.mdx | 53 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/content/docs/ai-gateway/guardrails/index.mdx create mode 100644 src/content/docs/ai-gateway/guardrails/set-up-guardrail.mdx diff --git a/src/content/docs/ai-gateway/guardrails/index.mdx b/src/content/docs/ai-gateway/guardrails/index.mdx new file mode 100644 index 00000000000000..350ec573d19e7e --- /dev/null +++ b/src/content/docs/ai-gateway/guardrails/index.mdx @@ -0,0 +1,17 @@ +--- +title: Guardrails in AI Gateway +pcx_content_type: navigation +order: 1 +sidebar: + order: 8 + group: + badge: Beta +--- + +Guardrails help you deploy AI applications safely by intercepting and evaluating both user prompts and model responses for harmful content. Acting as a proxy between your application and [model providers](/ai-gateway/providers)(such as OpenAI, Anthropic, DeepSeek, and others), Guardrails ensures a consistent and secure experience across your entire AI ecosystem. + +Guardrails proactively monitor interactions between users and AI models, allowing you to: + +- Protect users by detecting and mitigating harmful content. +- Meet compliance requirements by aligning with evolving regulatory standards. +- Optimize costs by preventing unnecessary processing of harmful requests early. diff --git a/src/content/docs/ai-gateway/guardrails/set-up-guardrail.mdx b/src/content/docs/ai-gateway/guardrails/set-up-guardrail.mdx new file mode 100644 index 00000000000000..520c6927415171 --- /dev/null +++ b/src/content/docs/ai-gateway/guardrails/set-up-guardrail.mdx @@ -0,0 +1,53 @@ +--- +pcx_content_type: how-to +title: How Guardrails works +sidebar: + order: 3 +--- + +AI Gateway inspects all interactions in real time by evaluating content against predefined safety parameters. Below a breakdown of the process: + +1. Intercepting interactions: + AI Gateway proxies requests and responses, sitting between the user and the AI model. + +2. Inspecting content: + + - User prompts: AI Gateway checks prompts against safety parameters (for example, violence, hate, or sexual content). Based on your settings, prompts can be flagged or blocked before reaching the model. + - Model responses: Once processed, the AI model response is inspected. If hazardous content is detected, it can be flagged or blocked before being delivered to the user. + +3. Applying actions: + Depending on your configuration, flagged content is logged for review, while blocked content is prevented from proceeding. + +## Supported model types + +Guardrails determines the type of AI model being used and applies safety checks accordingly: + +- Text generation models: Both prompts and responses are evaluated. +- Embedding models: Only the prompt is evaluated, and the response is passed directly back to the user. +- Unknown models: If the model type cannot be determined, prompts are evaluated, but responses bypass Guardrails. + +If Guardrails cannot access the underlying model, requests set to "block" will result in an error, while flagged requests will proceed. + +## Configuration + +Within AI Gateway settings, you can customize Guardrails: + +- Enable or disable content moderation. +- Choose evaluation scope: Analyze user prompts, model responses, or both. +- Define hazard categories: Select categories like violence, hate, or sexual content and assign actions (ignore, flag, or block). + +## Workers AI and Guardrails + +Guardrails currently uses [Llama Guard 3 8B](https://ai.meta.com/research/publications/llama-guard-llm-based-input-output-safeguard-for-human-ai-conversations/) on [Workers AI](/workers-ai/) to perform content evaluations. The underlying model may be updated in the future, and we will reflect those changes within Guardrails. + +Since Guardrails runs on Workers AI, enabling it incurs usage on Workers AI. You can monitor usage through the Workers AI Dashboard. + +## Additional considerations + +- Latency impact: Enabling Guardrails adds some latency. Consider this when balancing safety and speed. + +:::note + +Llama Guard is provided as-is without any representations, warranties, or guarantees. Any rules or examples contained in blogs, developer docs, or other reference materials are provided for informational purposes only. You acknowledge and understand that you are responsible for the results and outcomes of your use of AI Gateway. + +::: From 912be66c1c026720501c03c33062ccc06b0990f7 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Mon, 24 Feb 2025 16:47:36 +0000 Subject: [PATCH 02/70] Initial commit --- .../quick-actions-rest-api/index.mdx | 12 ++++++++++++ .../browser-rendering-with-DO.mdx | 0 .../browser-rendering/workers-binding-api/index.mdx | 12 ++++++++++++ .../reuse-sessions.mdx | 0 .../screenshots.mdx | 0 5 files changed, 24 insertions(+) create mode 100644 src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx rename src/content/docs/browser-rendering/{get-started => workers-binding-api}/browser-rendering-with-DO.mdx (100%) create mode 100644 src/content/docs/browser-rendering/workers-binding-api/index.mdx rename src/content/docs/browser-rendering/{get-started => workers-binding-api}/reuse-sessions.mdx (100%) rename src/content/docs/browser-rendering/{get-started => workers-binding-api}/screenshots.mdx (100%) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx new file mode 100644 index 00000000000000..1d52dc83a74389 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx @@ -0,0 +1,12 @@ +--- +pcx_content_type: navigation +title: Workers Binding API +sidebar: + order: 2 + group: + hideIndex: true +--- + +import { DirectoryListing } from "~/components"; + + diff --git a/src/content/docs/browser-rendering/get-started/browser-rendering-with-DO.mdx b/src/content/docs/browser-rendering/workers-binding-api/browser-rendering-with-DO.mdx similarity index 100% rename from src/content/docs/browser-rendering/get-started/browser-rendering-with-DO.mdx rename to src/content/docs/browser-rendering/workers-binding-api/browser-rendering-with-DO.mdx diff --git a/src/content/docs/browser-rendering/workers-binding-api/index.mdx b/src/content/docs/browser-rendering/workers-binding-api/index.mdx new file mode 100644 index 00000000000000..1d52dc83a74389 --- /dev/null +++ b/src/content/docs/browser-rendering/workers-binding-api/index.mdx @@ -0,0 +1,12 @@ +--- +pcx_content_type: navigation +title: Workers Binding API +sidebar: + order: 2 + group: + hideIndex: true +--- + +import { DirectoryListing } from "~/components"; + + diff --git a/src/content/docs/browser-rendering/get-started/reuse-sessions.mdx b/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx similarity index 100% rename from src/content/docs/browser-rendering/get-started/reuse-sessions.mdx rename to src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx diff --git a/src/content/docs/browser-rendering/get-started/screenshots.mdx b/src/content/docs/browser-rendering/workers-binding-api/screenshots.mdx similarity index 100% rename from src/content/docs/browser-rendering/get-started/screenshots.mdx rename to src/content/docs/browser-rendering/workers-binding-api/screenshots.mdx From 9bc1e3da8692892dc3f136a64840224da9da5d1f Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Mon, 24 Feb 2025 17:44:06 +0000 Subject: [PATCH 03/70] quick actions endpoints --- .../browser-rendering/get-started/index.mdx | 4 +-- .../content-endpoint.mdx | 15 ++++++++++ .../quick-actions-rest-api/custom-css.mdx | 30 +++++++++++++++++++ .../quick-actions-rest-api/index.mdx | 8 ++--- .../quick-actions-rest-api/pdf-endpoint.mdx | 19 ++++++++++++ .../scrape-endpoint.mdx | 18 +++++++++++ .../screenshot-endpoint.mdx | 22 ++++++++++++++ .../quick-actions-rest-api/snapshot.mdx | 18 +++++++++++ .../workers-binding-api/index.mdx | 1 - 9 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx create mode 100644 src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx create mode 100644 src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx create mode 100644 src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx create mode 100644 src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx create mode 100644 src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx diff --git a/src/content/docs/browser-rendering/get-started/index.mdx b/src/content/docs/browser-rendering/get-started/index.mdx index d64864ac0a09c0..cb16361765ebe8 100644 --- a/src/content/docs/browser-rendering/get-started/index.mdx +++ b/src/content/docs/browser-rendering/get-started/index.mdx @@ -3,10 +3,10 @@ pcx_content_type: navigation title: Get started sidebar: order: 2 - group: - hideIndex: true --- import { DirectoryListing } from "~/components"; +Browser rendering can be used in two ways: the [Workers Binding API](/browser-rendering/workers-binding-api) for complex scripts and the Quick Actions REST API for [simple actions](/browser-rendering/quick-actions-rest-api/). + diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx new file mode 100644 index 00000000000000..746f912ebc46c2 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -0,0 +1,15 @@ +--- +pcx_content_type: how-to +title: Retrieve HTML content +sidebar: + order: 2 +--- + +Retrieve the HTML content of a specified URL by sending a POST request to the `/content` endpoint. + +``` +curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/content' \ + -H 'Content-Type: application/json' \ + -H 'Authorization: Bearer ' \ + -d '{"url": "https://example.com"}' +``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx new file mode 100644 index 00000000000000..367c60051f4d13 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx @@ -0,0 +1,30 @@ +--- +pcx_content_type: how-to +title: Customize CSS and take a screenshot +sidebar: + order: 4 +--- + +Customise the rendering by adding external JavaScript and CSS before capturing a screenshot. + +``` +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "addScriptTag": [ + { "url": "https://code.jquery.com/jquery-3.7.1.min.js" }, + { "content": "document.querySelector(`h1`).innerText = `Hello World!!!`" } + ], + "addStyleTag": [ + { + "content": "body { background: linear-gradient(45deg, #da5a44, #a32784); }" + }, + { + "url": "https://interactive-examples.mdn.mozilla.net/live-examples/css-examples/text-decoration/text-decoration-color.css" + } + ] + }' \ + --output "screenshot.webp" +``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx index 1d52dc83a74389..da144bac66924c 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx @@ -1,12 +1,10 @@ --- pcx_content_type: navigation -title: Workers Binding API +title: Quick Actions API sidebar: order: 2 - group: - hideIndex: true --- -import { DirectoryListing } from "~/components"; +The Quick Actions API is a RESTful interface that provides endpoints for common browser actions such as capturing screenshots, extracting HTML content, generating PDFs, and more. This API is designed to help you interact with web pages quickly and efficiently. - +Before you begin, make sure to create a custom **API Token** with your Account > **Browser Rendering**> **Edit** permissions from the [Cloudflare dashboard](https://dash.cloudflare.com/). diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx new file mode 100644 index 00000000000000..db9173c360d043 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -0,0 +1,19 @@ +--- +pcx_content_type: how-to +title: Generate PDF +sidebar: + order: 5 +--- + +``` +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "addStyleTag": [ + { "content": "body { font-family: Arial; }" } + ] + }' \ + --output "output.pdf" +``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx new file mode 100644 index 00000000000000..212d87b48199c8 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -0,0 +1,18 @@ +--- +pcx_content_type: how-to +title: Scrape content +sidebar: + order: 7 +--- + +``` +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/scrape' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "scrapeOptions": { + "selectors": ["h1", ".article"] + } + }' +``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx new file mode 100644 index 00000000000000..5c2778702f3de3 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -0,0 +1,22 @@ +--- +pcx_content_type: how-to +title: Render HTML and capture screenshot +sidebar: + order: 3 +--- + +Render a provided HTML string and capture a screenshot with specific options. + +``` +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "html": "Hello World!", + "screenshotOptions": { + "type": "webp", + "omitBackground": true + } + }' \ + --output "screenshot.webp" +``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx new file mode 100644 index 00000000000000..7a5a1d5aca4e30 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -0,0 +1,18 @@ +--- +pcx_content_type: how-to +title: Capture snapshot +sidebar: + order: 6 +--- + +``` +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "addScriptTag": [ + { "content": "document.title = \"Snapshot Page\";" } + ] + }' +``` diff --git a/src/content/docs/browser-rendering/workers-binding-api/index.mdx b/src/content/docs/browser-rendering/workers-binding-api/index.mdx index 1d52dc83a74389..84482a235bdd83 100644 --- a/src/content/docs/browser-rendering/workers-binding-api/index.mdx +++ b/src/content/docs/browser-rendering/workers-binding-api/index.mdx @@ -4,7 +4,6 @@ title: Workers Binding API sidebar: order: 2 group: - hideIndex: true --- import { DirectoryListing } from "~/components"; From 7a32d66cbde6082e8a3b8152c3b136b75beb9ff2 Mon Sep 17 00:00:00 2001 From: kodster28 Date: Mon, 24 Feb 2025 15:19:06 -0600 Subject: [PATCH 04/70] Fix --- src/content/docs/browser-rendering/workers-binding-api/index.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/content/docs/browser-rendering/workers-binding-api/index.mdx b/src/content/docs/browser-rendering/workers-binding-api/index.mdx index 84482a235bdd83..04497463a62ad9 100644 --- a/src/content/docs/browser-rendering/workers-binding-api/index.mdx +++ b/src/content/docs/browser-rendering/workers-binding-api/index.mdx @@ -3,7 +3,6 @@ pcx_content_type: navigation title: Workers Binding API sidebar: order: 2 - group: --- import { DirectoryListing } from "~/components"; From 33e5fa8e2639243058d4fed1ca4d8274a0fb5354 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Tue, 25 Feb 2025 14:39:05 +0000 Subject: [PATCH 05/70] change to bullets --- src/content/docs/browser-rendering/get-started/index.mdx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/content/docs/browser-rendering/get-started/index.mdx b/src/content/docs/browser-rendering/get-started/index.mdx index cb16361765ebe8..fdef7accca9b26 100644 --- a/src/content/docs/browser-rendering/get-started/index.mdx +++ b/src/content/docs/browser-rendering/get-started/index.mdx @@ -5,8 +5,7 @@ sidebar: order: 2 --- -import { DirectoryListing } from "~/components"; +Browser rendering can be used in two ways: -Browser rendering can be used in two ways: the [Workers Binding API](/browser-rendering/workers-binding-api) for complex scripts and the Quick Actions REST API for [simple actions](/browser-rendering/quick-actions-rest-api/). - - +- [Workers Binding API](/browser-rendering/workers-binding-api) for complex scripts. +- Quick Actions REST API for [simple actions](/browser-rendering/quick-actions-rest-api/). From 0e582ac9978c9d03b84be1944495060daddb1d60 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 16:20:21 +0000 Subject: [PATCH 06/70] moved get started to a file --- .../browser-rendering/{get-started/index.mdx => get-started.mdx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/content/docs/browser-rendering/{get-started/index.mdx => get-started.mdx} (100%) diff --git a/src/content/docs/browser-rendering/get-started/index.mdx b/src/content/docs/browser-rendering/get-started.mdx similarity index 100% rename from src/content/docs/browser-rendering/get-started/index.mdx rename to src/content/docs/browser-rendering/get-started.mdx From 1ac96e4cb8d0f2bf44c25eb3e127befe85881d82 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 16:48:57 +0000 Subject: [PATCH 07/70] summary --- .../quick-actions-rest-api/content-endpoint.mdx | 2 +- .../quick-actions-rest-api/screenshot-endpoint.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index 746f912ebc46c2..d58eb67ba319f3 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -5,7 +5,7 @@ sidebar: order: 2 --- -Retrieve the HTML content of a specified URL by sending a POST request to the `/content` endpoint. +- The content API navigates to a website and captures the page’s complete HTML including the `` section after it has been rendered, returning a `Content-Type: text/html` response. This is ideal for pages with dynamic JavaScript or heavy interactivity. ``` curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/content' \ diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 5c2778702f3de3..4c8d0699499f94 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -5,7 +5,7 @@ sidebar: order: 3 --- -Render a provided HTML string and capture a screenshot with specific options. +This endpoint renders the webpage by processing its HTML and JavaScript, then captures a screenshot of the fully rendered page. ``` curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ From 963a7f3a25a4708618a8a12905e7f588eb0e07bf Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 17:10:48 +0000 Subject: [PATCH 08/70] summar of endpoints --- .../quick-actions-rest-api/content-endpoint.mdx | 2 +- .../browser-rendering/quick-actions-rest-api/custom-css.mdx | 2 +- .../browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx | 2 ++ .../quick-actions-rest-api/scrape-endpoint.mdx | 2 ++ .../docs/browser-rendering/quick-actions-rest-api/snapshot.mdx | 2 ++ 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index d58eb67ba319f3..3240165a42cfd4 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -5,7 +5,7 @@ sidebar: order: 2 --- -- The content API navigates to a website and captures the page’s complete HTML including the `` section after it has been rendered, returning a `Content-Type: text/html` response. This is ideal for pages with dynamic JavaScript or heavy interactivity. +The content API navigates to a website and captures the complete HTML of a page including the `` section after it has been rendered, returning a `Content-Type: text/html` response. This is ideal for pages with dynamic JavaScript or heavy interactivity. ``` curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/content' \ diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx index 367c60051f4d13..cce45012e7bae0 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx @@ -5,7 +5,7 @@ sidebar: order: 4 --- -Customise the rendering by adding external JavaScript and CSS before capturing a screenshot. +This endpoint lets you inject CSS into the page before capturing a screenshot, allowing control over the rendering process and enabling tailored visual adjustments. ``` curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index db9173c360d043..c804c7908b0e3d 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -5,6 +5,8 @@ sidebar: order: 5 --- +The PDF API navigates to a site and converts the rendered page into a PDF document, returning a `Content-Type: application/pdf` response along with a PDF buffer. + ``` curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ -H 'Authorization: Bearer ' \ diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index 212d87b48199c8..2cc598350f99cb 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -5,6 +5,8 @@ sidebar: order: 7 --- +The scrape API extracts structured data from specific elements on a webpage using CSS selectors, returning details such as element dimensions and inner HTML for efficient data extraction + ``` curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/scrape' \ -H 'Authorization: Bearer ' \ diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index 7a5a1d5aca4e30..dad22ac1c01d3e 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -5,6 +5,8 @@ sidebar: order: 6 --- +The snapshot API captures both the HTML content and a screenshot of the webpage in one request. It returns the HTML as a text string and the screenshot as a Base64-encoded image. + ``` curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ -H 'Authorization: Bearer ' \ From 423edaa538499458456c4488c188c81d3964077a Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 18:12:51 +0000 Subject: [PATCH 09/70] code samples --- .../content-endpoint.mdx | 25 +++++- .../quick-actions-rest-api/custom-css.mdx | 30 ++++++- .../quick-actions-rest-api/index.mdx | 2 +- .../quick-actions-rest-api/pdf-endpoint.mdx | 28 ++++++- .../scrape-endpoint.mdx | 83 ++++++++++++++++++- .../quick-actions-rest-api/snapshot.mdx | 51 +++++++++++- 6 files changed, 207 insertions(+), 12 deletions(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index 3240165a42cfd4..91a21367b460f2 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -7,9 +7,30 @@ sidebar: The content API navigates to a website and captures the complete HTML of a page including the `` section after it has been rendered, returning a `Content-Type: text/html` response. This is ideal for pages with dynamic JavaScript or heavy interactivity. -``` -curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/content' \ +## Basic usage + +```bash +curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/content' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{"url": "https://example.com"}' ``` + +## Advanced usage + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/content' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "html": "Hello World", + "setJavaScriptEnabled": false, + "viewport": { + "width": 1200, + "height": 800 + }, + "allowRequestPattern": [ + "https?://fonts.(googleapis|gstatic).com.*" + ] + }' +``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx index cce45012e7bae0..afa3b79563f972 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx @@ -7,8 +7,10 @@ sidebar: This endpoint lets you inject CSS into the page before capturing a screenshot, allowing control over the rendering process and enabling tailored visual adjustments. -``` -curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ +## Basic usage + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ -H 'Authorization: Bearer ' \ -H 'Content-Type: application/json' \ -d '{ @@ -28,3 +30,27 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser }' \ --output "screenshot.webp" ``` + +## Advanced usage + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "addScriptTag": [ + { "url": "https://code.jquery.com/jquery-3.7.1.min.js" }, + { "content": "document.querySelector(`h1`).innerText = `Hello World!!!`" } + ], + "addStyleTag": [ + { "content": "body { background: linear-gradient(45deg, #da5a44, #a32784); }" }, + { "url": "https://interactive-examples.mdn.mozilla.net/live-examples/css-examples/text-decoration/text-decoration-color.css" } + ], + "viewport": { + "width": 1280, + "height": 720 + } + }' \ + --output "advanced-custom-screenshot.webp" +``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx index da144bac66924c..7dea27eb3928e2 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: navigation -title: Quick Actions API +title: Quick Actions REST API sidebar: order: 2 --- diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index c804c7908b0e3d..27bc4f29205bbc 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -7,8 +7,10 @@ sidebar: The PDF API navigates to a site and converts the rendered page into a PDF document, returning a `Content-Type: application/pdf` response along with a PDF buffer. -``` -curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ +## Basic usage + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ -H 'Authorization: Bearer ' \ -H 'Content-Type: application/json' \ -d '{ @@ -19,3 +21,25 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser }' \ --output "output.pdf" ``` + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "html": "PDF Advanced Rendering", + "setExtraHTTPHeaders": { + "X-Custom-Header": "value" + }, + "viewport": { + "width": 1200, + "height": 800 + }, + "gotoOptions": { + "waitUntil": "networkidle2", + "timeout": 45000 + } + }' \ + --output "advanced-output.pdf" +``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index 2cc598350f99cb..a1ae6ec57dd586 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -5,10 +5,12 @@ sidebar: order: 7 --- -The scrape API extracts structured data from specific elements on a webpage using CSS selectors, returning details such as element dimensions and inner HTML for efficient data extraction +The scrape API extracts structured data from specific elements on a webpage using CSS selectors, returning details such as element dimensions and inner HTML for efficient data extraction. -``` -curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/scrape' \ +## Basic usage + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/scrape' \ -H 'Authorization: Bearer ' \ -H 'Content-Type: application/json' \ -d '{ @@ -18,3 +20,78 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser } }' ``` + +### json response + +```json title="json response" +{ + "status": true, + "errors": [], + "result": { + "elements": [ + { + "selector": "h1", + "height": 50, + "html": "

Example Heading

" + }, + { + "selector": ".article", + "height": 150, + "html": "
Content here
" + } + ] + } +} +``` + +## Advanced usage + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/scrape' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "html": "

Advanced Scrape

", + "setJavaScriptEnabled": false, + "viewport": { + "width": 1200, + "height": 800 + }, + "gotoOptions": { + "waitUntil": "networkidle0", + "timeout": 45000 + }, + "scrapeOptions": { + "selectors": ["h1", ".article", "p"] + } + }' +``` + +### json response + +```json title="json response" +{ + "status": true, + "errors": [], + "result": { + "elements": [ + { + "selector": "h1", + "height": 60, + "html": "

Advanced Scrape Heading

" + }, + { + "selector": ".article", + "height": 200, + "html": "
Advanced content
" + }, + { + "selector": "p", + "height": 80, + "html": "

Paragraph content

" + } + ] + } +} +``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index dad22ac1c01d3e..77f0b5f5e78ef4 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -7,8 +7,10 @@ sidebar: The snapshot API captures both the HTML content and a screenshot of the webpage in one request. It returns the HTML as a text string and the screenshot as a Base64-encoded image. -``` -curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ +## Basic usage + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ -H 'Authorization: Bearer ' \ -H 'Content-Type: application/json' \ -d '{ @@ -18,3 +20,48 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser ] }' ``` + +### json response + +```json title="json response" +{ + "status": true, + "errors": [], + "result": { + "screenshot": "Base64EncodedScreenshotString", + "content": "..." + } +} +``` + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "html": "Advanced Snapshot", + "setJavaScriptEnabled": false, + "viewport": { + "width": 1200, + "height": 800 + }, + "gotoOptions": { + "waitUntil": "domcontentloaded", + "timeout": 30000 + } + }' +``` + +### json response + +```json title="json response" +{ + "status": true, + "errors": [], + "result": { + "screenshot": "AdvancedBase64Screenshot", + "content": "Advanced Snapshot" + } +} +``` From 7f85bbc15ba79a0c28445fe35bdfb6a74a303a22 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 18:28:05 +0000 Subject: [PATCH 10/70] code samples and title change --- .../content-endpoint.mdx | 2 +- .../quick-actions-rest-api/custom-css.mdx | 2 +- .../quick-actions-rest-api/pdf-endpoint.mdx | 2 +- .../scrape-endpoint.mdx | 2 +- .../screenshot-endpoint.mdx | 34 +++++++++++++++++-- .../quick-actions-rest-api/snapshot.mdx | 2 +- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index 91a21367b460f2..988bb11f1f0586 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: how-to -title: Retrieve HTML content +title: content API sidebar: order: 2 --- diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx index afa3b79563f972..d269278ecc3878 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: how-to -title: Customize CSS and take a screenshot +title: Screenshot API with custom CSS sidebar: order: 4 --- diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index 27bc4f29205bbc..8cfb5f713c3434 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: how-to -title: Generate PDF +title: PDF API sidebar: order: 5 --- diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index a1ae6ec57dd586..51c8790df14cbb 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: how-to -title: Scrape content +title: Scrape API sidebar: order: 7 --- diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 4c8d0699499f94..633061a545a56e 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -1,14 +1,16 @@ --- pcx_content_type: how-to -title: Render HTML and capture screenshot +title: Screenshot API sidebar: order: 3 --- This endpoint renders the webpage by processing its HTML and JavaScript, then captures a screenshot of the fully rendered page. -``` -curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ +## Basic usage + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ -H 'Authorization: Bearer ' \ -H 'Content-Type: application/json' \ -d '{ @@ -20,3 +22,29 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser }' \ --output "screenshot.webp" ``` + +## Advanced usage + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "html": "

Advanced Screenshot

", + "screenshotOptions": { + "type": "webp", + "omitBackground": true, + "quality": 80 + }, + "viewport": { + "width": 1280, + "height": 720 + }, + "gotoOptions": { + "waitUntil": "networkidle0", + "timeout": 45000 + } + }' \ + --output "advanced-screenshot.webp" +``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index 77f0b5f5e78ef4..22eb8fb071fa39 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: how-to -title: Capture snapshot +title: Snapshot API sidebar: order: 6 --- From 888f77b36601036b9b4602e1c98004188a4973a5 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 18:28:55 +0000 Subject: [PATCH 11/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com> --- .../quick-actions-rest-api/scrape-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index 51c8790df14cbb..fccc44062cd2f3 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -21,7 +21,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- }' ``` -### json response +### JSON response ```json title="json response" { From 13fbe0bb3929476ccb7279f90ac2a681e67ba267 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 18:29:02 +0000 Subject: [PATCH 12/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com> --- .../docs/browser-rendering/quick-actions-rest-api/snapshot.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index 22eb8fb071fa39..63f768fd39dbaa 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -21,7 +21,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- }' ``` -### json response +### JSON response ```json title="json response" { From 8a9346defaaf02dbdf3e11cc650e03a94168f187 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 18:29:12 +0000 Subject: [PATCH 13/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com> --- .../docs/browser-rendering/quick-actions-rest-api/snapshot.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index 63f768fd39dbaa..2c16a838f364e7 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -53,7 +53,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- }' ``` -### json response +### JSON response ```json title="json response" { From 412e75edb56fd3f1e702df3ae11602afd567cb74 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 18:29:21 +0000 Subject: [PATCH 14/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com> --- .../quick-actions-rest-api/scrape-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index fccc44062cd2f3..a967ac6f4fe868 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -68,7 +68,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- }' ``` -### json response +### JSON response ```json title="json response" { From 08f7fe5a0693ef12a321453efb7f5447da444a46 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 18:43:12 +0000 Subject: [PATCH 15/70] director listing --- .../docs/browser-rendering/quick-actions-rest-api/index.mdx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx index 7dea27eb3928e2..e2d99351489378 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx @@ -6,5 +6,10 @@ sidebar: --- The Quick Actions API is a RESTful interface that provides endpoints for common browser actions such as capturing screenshots, extracting HTML content, generating PDFs, and more. This API is designed to help you interact with web pages quickly and efficiently. +The following are the available options: + +import { DirectoryListing } from "~/components"; + + Before you begin, make sure to create a custom **API Token** with your Account > **Browser Rendering**> **Edit** permissions from the [Cloudflare dashboard](https://dash.cloudflare.com/). From 1e91167d8c13cf1c3c5c446a280b840e7d6bf93b Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 18:53:57 +0000 Subject: [PATCH 16/70] added code sample --- .../quick-actions-rest-api/pdf-endpoint.mdx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index 8cfb5f713c3434..e86a7b14fa8708 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -22,6 +22,8 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- --output "output.pdf" ``` +## Advanced usage + ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ -H 'Authorization: Bearer ' \ @@ -43,3 +45,19 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- }' \ --output "advanced-output.pdf" ``` + +## PDF with no images or CSS + +This is ideal when the user wants to so speed up the scanning process and does not need the images. + +```bash +curl -X POST https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://cloudflare.com/", + "rejectResourceTypes": ["image"], + "rejectRequestPattern": ["/^.*\\.(css)"] +}' \ + --output "cloudflare.pdf" +``` From 864b0ee2d408cb9e6680fa0b07e8e773d80e6e38 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 19:24:16 +0000 Subject: [PATCH 17/70] index descriptions --- .../docs/browser-rendering/quick-actions-rest-api/index.mdx | 4 +++- .../docs/browser-rendering/workers-binding-api/index.mdx | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx index e2d99351489378..50a23cf42a437f 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx @@ -12,4 +12,6 @@ import { DirectoryListing } from "~/components"; -Before you begin, make sure to create a custom **API Token** with your Account > **Browser Rendering**> **Edit** permissions from the [Cloudflare dashboard](https://dash.cloudflare.com/). +Use the Quick Actions API when you need a fast, simple way to perform common browser tasks like capturing screenshots, extracting HTML, or generating PDFs without writing complex scripts. If you require more advanced automation, custom workflows, or persistent browser sessions, the [Workers Binding API](/browser-rendering/workers-binding-api/) is the better choice. + +Before you begin, make sure to [create a custom **API Token**](/fundamentals/api/get-started/create-token/) with your Account > **Browser Rendering**> **Edit** permissions from the [Cloudflare dashboard](https://dash.cloudflare.com/). diff --git a/src/content/docs/browser-rendering/workers-binding-api/index.mdx b/src/content/docs/browser-rendering/workers-binding-api/index.mdx index 04497463a62ad9..0fca5260371fd6 100644 --- a/src/content/docs/browser-rendering/workers-binding-api/index.mdx +++ b/src/content/docs/browser-rendering/workers-binding-api/index.mdx @@ -7,4 +7,8 @@ sidebar: import { DirectoryListing } from "~/components"; +The Workers Binding API allows you to execute advanced browser rendering scripts within Cloudflare Workers. It provides developers with the flexibility to automate and control complex workflows and browser interactions. The following options are available for browser rendering tasks: + + +Use the Workers Binding API when you need advanced browser automation, custom workflows, or complex interactions beyond basic rendering. For quick, one-off tasks like capturing screenshots or extracting HTML, the [Quick Actions REST API](/browser-rendering/quick-actions-rest-api/) is the simpler choice. From 7159abb4bf96b7171d4bd4f9df2a76b04671b322 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 19:49:05 +0000 Subject: [PATCH 18/70] redirects --- public/_redirects | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/public/_redirects b/public/_redirects index 07b10d48849d63..1e3cdedb6da1f4 100644 --- a/public/_redirects +++ b/public/_redirects @@ -179,6 +179,11 @@ /bots/reference/verified-bot-categories/ /bots/concepts/bot/verified-bots/categories/ 301 /bots/reference/verified-bot-policy/ /bots/concepts/bot/verified-bots/policy/ 301 +#browser-rendering +/browser-rendering/get-started/browser-rendering-with-DO/ /browser-rendering/workers-binding-api/browser-rendering-with-do/ 301 +/browser-rendering/get-started/reuse-sessions/ /browser-rendering/workers-binding-api/reuse-sessions/ 301 +/browser-rendering/get-started/screenshots/ /browser-rendering/workers-binding-api/screenshots/ 301 + # byoip /byoip/about/dynamic-advertisement/ /byoip/concepts/dynamic-advertisement/ 301 /byoip/best-practices/dynamic-advertisement/ /byoip/concepts/dynamic-advertisement/best-practices/ 301 From f01f28d4eaee072772e59d45f2a981cdbe2bd036 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 19:52:16 +0000 Subject: [PATCH 19/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/content-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index 988bb11f1f0586..8a1e8ead463d65 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -5,7 +5,7 @@ sidebar: order: 2 --- -The content API navigates to a website and captures the complete HTML of a page including the `` section after it has been rendered, returning a `Content-Type: text/html` response. This is ideal for pages with dynamic JavaScript or heavy interactivity. +The content API navigates to a website and captures the fully rendered HTML of a page, including the section, after JavaScript execution. This is ideal for capturing content from JavaScript-heavy or interactive websites. ## Basic usage From 7602ec43502c6660a262cd7cd4622e57f7cb373a Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 19:58:42 +0000 Subject: [PATCH 20/70] delete custom css --- .../content-endpoint.mdx | 17 ++---- .../quick-actions-rest-api/custom-css.mdx | 56 ------------------- .../screenshot-endpoint.mdx | 24 ++++++++ 3 files changed, 30 insertions(+), 67 deletions(-) delete mode 100644 src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index 988bb11f1f0586..1b90e8b53acf21 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: how-to -title: content API +title: Content API sidebar: order: 2 --- @@ -23,14 +23,9 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -H 'Authorization: Bearer ' \ -H 'Content-Type: application/json' \ -d '{ - "html": "Hello World", - "setJavaScriptEnabled": false, - "viewport": { - "width": 1200, - "height": 800 - }, - "allowRequestPattern": [ - "https?://fonts.(googleapis|gstatic).com.*" - ] - }' + "url": "https://cloudflare.com/", + "rejectResourceTypes": ["image"], + "rejectRequestPattern": ["/^.*\\.(css)"] +} + ``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx deleted file mode 100644 index d269278ecc3878..00000000000000 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/custom-css.mdx +++ /dev/null @@ -1,56 +0,0 @@ ---- -pcx_content_type: how-to -title: Screenshot API with custom CSS -sidebar: - order: 4 ---- - -This endpoint lets you inject CSS into the page before capturing a screenshot, allowing control over the rendering process and enabling tailored visual adjustments. - -## Basic usage - -```bash -curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ - -H 'Authorization: Bearer ' \ - -H 'Content-Type: application/json' \ - -d '{ - "url": "https://example.com/", - "addScriptTag": [ - { "url": "https://code.jquery.com/jquery-3.7.1.min.js" }, - { "content": "document.querySelector(`h1`).innerText = `Hello World!!!`" } - ], - "addStyleTag": [ - { - "content": "body { background: linear-gradient(45deg, #da5a44, #a32784); }" - }, - { - "url": "https://interactive-examples.mdn.mozilla.net/live-examples/css-examples/text-decoration/text-decoration-color.css" - } - ] - }' \ - --output "screenshot.webp" -``` - -## Advanced usage - -```bash -curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ - -H 'Authorization: Bearer ' \ - -H 'Content-Type: application/json' \ - -d '{ - "url": "https://example.com/", - "addScriptTag": [ - { "url": "https://code.jquery.com/jquery-3.7.1.min.js" }, - { "content": "document.querySelector(`h1`).innerText = `Hello World!!!`" } - ], - "addStyleTag": [ - { "content": "body { background: linear-gradient(45deg, #da5a44, #a32784); }" }, - { "url": "https://interactive-examples.mdn.mozilla.net/live-examples/css-examples/text-decoration/text-decoration-color.css" } - ], - "viewport": { - "width": 1280, - "height": 720 - } - }' \ - --output "advanced-custom-screenshot.webp" -``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 633061a545a56e..f3df5c5de63989 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -48,3 +48,27 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- }' \ --output "advanced-screenshot.webp" ``` + +## Customise CSS + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "addScriptTag": [ + { "url": "https://code.jquery.com/jquery-3.7.1.min.js" }, + { "content": "document.querySelector(`h1`).innerText = `Hello World!!!`" } + ], + "addStyleTag": [ + { + "content": "body { background: linear-gradient(45deg, #da5a44, #a32784); }" + }, + { + "url": "https://interactive-examples.mdn.mozilla.net/live-examples/css-examples/text-decoration/text-decoration-color.css" + } + ] + }' \ + --output "screenshot.webp" +``` From daa44b8854cc94a7aa6d1b199126a83a22925b00 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 20:12:02 +0000 Subject: [PATCH 21/70] fixes from responses --- .../content-endpoint.mdx | 2 +- .../quick-actions-rest-api/pdf-endpoint.mdx | 1 - .../scrape-endpoint.mdx | 101 ++++++------------ .../screenshot-endpoint.mdx | 3 +- .../quick-actions-rest-api/snapshot.mdx | 5 +- 5 files changed, 38 insertions(+), 74 deletions(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index a3e0a433598f2f..b4bdca093fbf80 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -5,7 +5,7 @@ sidebar: order: 2 --- -The content API navigates to a website and captures the fully rendered HTML of a page, including the section, after JavaScript execution. This is ideal for capturing content from JavaScript-heavy or interactive websites. +The content API navigates to a website and captures the fully rendered HTML of a page, including the `head` section, after JavaScript execution. This is ideal for capturing content from JavaScript-heavy or interactive websites. ## Basic usage diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index e86a7b14fa8708..ed6a544acf7fd6 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -30,7 +30,6 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -H 'Content-Type: application/json' \ -d '{ "url": "https://example.com/", - "html": "PDF Advanced Rendering", "setExtraHTTPHeaders": { "X-Custom-Header": "value" }, diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index a967ac6f4fe868..36e8f26eecc834 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -25,73 +25,38 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- ```json title="json response" { - "status": true, - "errors": [], - "result": { - "elements": [ - { - "selector": "h1", - "height": 50, - "html": "

Example Heading

" - }, - { - "selector": ".article", - "height": 150, - "html": "
Content here
" - } - ] - } -} -``` - -## Advanced usage - -```bash -curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/scrape' \ - -H 'Authorization: Bearer ' \ - -H 'Content-Type: application/json' \ - -d '{ - "url": "https://example.com/", - "html": "

Advanced Scrape

", - "setJavaScriptEnabled": false, - "viewport": { - "width": 1200, - "height": 800 - }, - "gotoOptions": { - "waitUntil": "networkidle0", - "timeout": 45000 - }, - "scrapeOptions": { - "selectors": ["h1", ".article", "p"] - } - }' -``` - -### JSON response - -```json title="json response" -{ - "status": true, - "errors": [], - "result": { - "elements": [ - { - "selector": "h1", - "height": 60, - "html": "

Advanced Scrape Heading

" - }, - { - "selector": ".article", - "height": 200, - "html": "
Advanced content
" - }, - { - "selector": "p", - "height": 80, - "html": "

Paragraph content

" - } - ] - } + "success": true, + "result": [ + { + "results": [ + { + "attributes": [], + "height": 39, + "html": "Example Domain", + "left": 100, + "text": "Example Domain", + "top": 133.4375, + "width": 600 + } + ], + "selector": "h1" + }, + { + "results": [ + { + "attributes": [ + { "name": "href", "value": "https://www.iana.org/domains/example" } + ], + "height": 20, + "html": "More information...", + "left": 100, + "text": "More information...", + "top": 249.875, + "width": 142 + } + ], + "selector": "a" + } + ] } ``` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index f3df5c5de63989..b7cd721f22036f 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -30,8 +30,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -H 'Authorization: Bearer ' \ -H 'Content-Type: application/json' \ -d '{ - "url": "https://example.com/", - "html": "

Advanced Screenshot

", + "url": "https://cloudflare.com/", "screenshotOptions": { "type": "webp", "omitBackground": true, diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index 2c16a838f364e7..a881e3ad7a19b6 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -16,7 +16,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -d '{ "url": "https://example.com/", "addScriptTag": [ - { "content": "document.title = \"Snapshot Page\";" } + { "content": "document.body.innerHTML = "Snapshot Page";" } ] }' ``` @@ -34,12 +34,13 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- } ``` +## Advanced usage + ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ -H 'Authorization: Bearer ' \ -H 'Content-Type: application/json' \ -d '{ - "url": "https://example.com/", "html": "Advanced Snapshot", "setJavaScriptEnabled": false, "viewport": { From 17a693189f6d677fe6fb85092664b4a18df47d24 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 20:58:37 +0000 Subject: [PATCH 22/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/scrape-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index 36e8f26eecc834..cb14f499dabc61 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -5,7 +5,7 @@ sidebar: order: 7 --- -The scrape API extracts structured data from specific elements on a webpage using CSS selectors, returning details such as element dimensions and inner HTML for efficient data extraction. +The scrape API extracts structured data from specific elements on a webpage, returning details such as element dimensions and inner HTML. ## Basic usage From 10d25f4ffea6939735eaa062e2f3aa52bfccfd71 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 21:01:24 +0000 Subject: [PATCH 23/70] code fixes --- .../quick-actions-rest-api/scrape-endpoint.mdx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index cb14f499dabc61..1253862607badb 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -14,11 +14,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -H 'Authorization: Bearer ' \ -H 'Content-Type: application/json' \ -d '{ - "url": "https://example.com/", - "scrapeOptions": { - "selectors": ["h1", ".article"] - } - }' + { "url": "https://example.com", "elements": [ { "selector": "h1" }, { "selector": "a" } ] } ``` ### JSON response From 105a878d1c02516093de783aad906c95ef7915d5 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 26 Feb 2025 21:28:04 +0000 Subject: [PATCH 24/70] parameters added --- .../content-endpoint.mdx | 6 +++++ .../quick-actions-rest-api/pdf-endpoint.mdx | 17 ++++++++++++++ .../scrape-endpoint.mdx | 22 ++++++++++++++++++- .../screenshot-endpoint.mdx | 22 +++++++++++++++++++ .../quick-actions-rest-api/snapshot.mdx | 19 ++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index b4bdca093fbf80..026ebbb9832708 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -29,3 +29,9 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- } ``` + +### Parameters + +- `url` _(string)_ - The URL of the webpage to extract content from. +- `rejectResourceTypes` _(array)_ - Blocks specific resource types such as images, fonts from loading to improve performance. +- `rejectRequestPattern` _(array of regex patterns)_ - Prevents loading of resources matching specified patterns such as CSS files. diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index ed6a544acf7fd6..ba2110ed46828a 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -60,3 +60,20 @@ curl -X POST https://api.cloudflare.com/client/v4/accounts//browser- }' \ --output "cloudflare.pdf" ``` + +## Parameters + +- `url` _(string)_ - The webpage URL to render as a PDF. +- `addStyleTag` _(array of objects)_ - Injects custom CSS before generating the PDF. + - `content` _(string)_ - Inline CSS styles. + - `url` _(string)_ - URL of an external stylesheet. +- `setExtraHTTPHeaders` _(object)_ - Adds custom HTTP headers when making the request. + - `X-Custom-Header` _(string)_ - Example of a custom header. +- `viewport` _(object)_ - Defines the browser viewport size. + - `width` _(number)_ - Viewport width in pixels. + - `height` _(number)_ - Viewport height in pixels. +- `gotoOptions` _(object)_ - Configures page navigation settings. + - `waitUntil` _(string)_ - Defines when the browser considers the page fully loaded. + - `timeout` _(number)_ - Maximum wait time before failing the request. +- `rejectResourceTypes` _(array)_ - Blocks specific resource types to improve rendering performance. +- `rejectRequestPattern` _(array of regex patterns)_ - Prevents loading of resources matching certain patterns. diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index 1253862607badb..e4cd68b1915d9d 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -14,7 +14,11 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -H 'Authorization: Bearer ' \ -H 'Content-Type: application/json' \ -d '{ - { "url": "https://example.com", "elements": [ { "selector": "h1" }, { "selector": "a" } ] } + "url": "https://example.com/", + "elements": { + "selectors": ["h1", ".article"] + } + }' ``` ### JSON response @@ -56,3 +60,19 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- ] } ``` + +## Parameters + +- `url` _(string)_ - The webpage to extract data from. +- `elements` _(object)_ - Defines the elements to extract from the page. + - `selectors` _(array of strings)_ - List of CSS selectors identifying elements to scrape (e.g., `"h1"`, `".article"`). + +### Response fields + +- `results` _(array of objects)_ - Contains extracted data for each selector. + - `selector` _(string)_ - The CSS selector used. + - `results` _(array of objects)_ - List of extracted elements matching the selector. + - `text` _(string)_ - Inner text of the element. + - `html` _(string)_ - Inner HTML of the element. + - `attributes` _(array of objects)_ - List of extracted attributes such as `href` for links. + - `height`, `width`, `top`, `left` _(number)_ - Position and dimensions of the element. diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index b7cd721f22036f..2540178de3af93 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -71,3 +71,25 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- }' \ --output "screenshot.webp" ``` + +## Parameters + +- `url` _(string)_ - The webpage URL to take a screenshot of. +- `html` _(string)_ - Instead of a URL, allows rendering custom HTML for the screenshot. +- `screenshotOptions` _(object)_ - Configures the screenshot format and quality. + - `type` _(string)_ - Defines the image format (`jpeg`, `png`, `webp`). + - `omitBackground` _(boolean)_ - Removes the default white background when taking a screenshot. + - `quality` _(number)_ - (For JPEG/WebP) Compression quality from 0 to 100\. +- `viewport` _(object)_ - Sets the browser viewport dimensions for rendering. + - `width` _(number)_ - Viewport width in pixels. + - `height` _(number)_ - Viewport height in pixels. +- `gotoOptions` _(object)_ - Configures how and when the page is considered fully loaded. + - `waitUntil` _(string)_ - Defines when the browser considers navigation complete (`networkidle0`, `domcontentloaded`). + - `networkidle0` - Waits until there are no more than 0 network connections for at least 500ms before taking a screenshot. + - `timeout` _(number)_ - Maximum wait time (in milliseconds) before navigation times out. +- `addScriptTag` _(array of objects)_ - Injects JavaScript code before taking a screenshot. + - `url` _(string)_ - Loads an external script file before rendering. + - `content` _(string)_ - Runs inline JavaScript before rendering. +- `addStyleTag` _(array of objects)_ - Injects CSS styles before rendering. + - `content` _(string)_ - Defines inline CSS rules. + - `url` _(string)_ - Loads external stylesheets before rendering. diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index a881e3ad7a19b6..a9526b617bb625 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -66,3 +66,22 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- } } ``` + +## Parameters + +- `url` _(string)_ - The URL of the page to snapshot. +- `html` _(string)_ - Allows passing custom HTML instead of a URL. +- `setJavaScriptEnabled` _(boolean)_ - Enables or disables JavaScript execution on the page. +- `viewport` \*(object)- Sets the rendering viewport dimensions. + - `width` _(number)_ - Width in pixels. + - `height` _(number)_ - Height in pixels. +- `gotoOptions` _(object)_ - Determines when the page is fully loaded. + - `waitUntil` _(string)_ - Defines the loading strategy (`domcontentloaded`, `networkidle2`). + - `timeout` _(number)_ - Timeout duration in milliseconds. +- `allowResourceTypes` _(array of strings)_ - Restricts the types of resources allowed to load. + - Example: [`document`, `script`] - Only allows HTML documents and scripts to load, preventing images, stylesheets, and other resources. + +### Response fields + +- `screenshot` _(string)_ - Base64-encoded image of the rendered page. +- `content` _(string)_ - Fully rendered HTML of the page. From d17637acf5dc751e32ca9cb24e3e08ae8c28e356 Mon Sep 17 00:00:00 2001 From: Kathy <153706637+kathayl@users.noreply.github.com> Date: Wed, 26 Feb 2025 14:52:05 -0800 Subject: [PATCH 25/70] Update get-started.mdx updated where link to quick actions api lives --- src/content/docs/browser-rendering/get-started.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/get-started.mdx b/src/content/docs/browser-rendering/get-started.mdx index fdef7accca9b26..5abf934d66a51b 100644 --- a/src/content/docs/browser-rendering/get-started.mdx +++ b/src/content/docs/browser-rendering/get-started.mdx @@ -8,4 +8,4 @@ sidebar: Browser rendering can be used in two ways: - [Workers Binding API](/browser-rendering/workers-binding-api) for complex scripts. -- Quick Actions REST API for [simple actions](/browser-rendering/quick-actions-rest-api/). +- [Quick Actions REST API](/browser-rendering/quick-actions-rest-api/) for simple actions. From 7863d7c56c9da26a031b62dca80b3d43ecc4acd6 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:56:48 +0000 Subject: [PATCH 26/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/content-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index 026ebbb9832708..b170536f2c9c7c 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: how-to -title: Content API +title: Fetch HTML sidebar: order: 2 --- From b5bb84fec7e8340ef5361abe58f9ccac60d09d99 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:56:59 +0000 Subject: [PATCH 27/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/content-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index b170536f2c9c7c..5c5f2a0afa0643 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -5,7 +5,7 @@ sidebar: order: 2 --- -The content API navigates to a website and captures the fully rendered HTML of a page, including the `head` section, after JavaScript execution. This is ideal for capturing content from JavaScript-heavy or interactive websites. +The `/content` endpoint instructs the browser to navigate to a website and capture the fully rendered HTML of a page, including the `head` section, after JavaScript execution. This is ideal for capturing content from JavaScript-heavy or interactive websites. ## Basic usage From e90f198730ba2ec22fbe6cd287355712102a2370 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:57:13 +0000 Subject: [PATCH 28/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx Co-authored-by: Sofia --- .../docs/browser-rendering/quick-actions-rest-api/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx index 50a23cf42a437f..2f444de6c312da 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx @@ -5,7 +5,7 @@ sidebar: order: 2 --- -The Quick Actions API is a RESTful interface that provides endpoints for common browser actions such as capturing screenshots, extracting HTML content, generating PDFs, and more. This API is designed to help you interact with web pages quickly and efficiently. +The Quick Actions API is a RESTful interface that provides endpoints for common browser actions such as capturing screenshots, extracting HTML content, generating PDFs, and more. The following are the available options: import { DirectoryListing } from "~/components"; From 43ba4b12ed8719230cbc6e38c4d137acde1462a6 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:57:26 +0000 Subject: [PATCH 29/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/content-endpoint.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index 5c5f2a0afa0643..d088856c218390 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -9,6 +9,8 @@ The `/content` endpoint instructs the browser to navigate to a website and captu ## Basic usage +Navigate to `https://example.com` and return the rendered HTML. + ```bash curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/content' \ -H 'Content-Type: application/json' \ From 8afb47ec765b96dafe3a4067b1fe5cbfbd9e076a Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:57:36 +0000 Subject: [PATCH 30/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx Co-authored-by: Sofia --- .../browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index ba2110ed46828a..65296b834798a3 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -5,7 +5,7 @@ sidebar: order: 5 --- -The PDF API navigates to a site and converts the rendered page into a PDF document, returning a `Content-Type: application/pdf` response along with a PDF buffer. +The `/pdf` endpoint instructs the browser to render the webpage as a PDF document. ## Basic usage From 41a5fc8b057a676b1ce40e12b8e46cf2b7216d9c Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:57:44 +0000 Subject: [PATCH 31/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx Co-authored-by: Sofia --- .../docs/browser-rendering/quick-actions-rest-api/snapshot.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index a9526b617bb625..fa8a35628a0ccf 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: how-to -title: Snapshot API +title: Take a webpage snapshot sidebar: order: 6 --- From b8655d5df5a5b3e81b33dd6259cba329237eb310 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:57:58 +0000 Subject: [PATCH 32/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx Co-authored-by: Sofia --- .../docs/browser-rendering/quick-actions-rest-api/snapshot.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index fa8a35628a0ccf..4a299b9cebc3af 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -5,7 +5,7 @@ sidebar: order: 6 --- -The snapshot API captures both the HTML content and a screenshot of the webpage in one request. It returns the HTML as a text string and the screenshot as a Base64-encoded image. +The `/snapshot` endpoint captures both the HTML content and a screenshot of the webpage in one request. It returns the HTML as a text string and the screenshot as a Base64-encoded image. ## Basic usage From 93bff6e47ef038ccbc72952c7bdeaeaaae9e9b94 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:58:24 +0000 Subject: [PATCH 33/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx Co-authored-by: Sofia --- .../docs/browser-rendering/quick-actions-rest-api/snapshot.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index 4a299b9cebc3af..0feae946a73acc 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -9,6 +9,8 @@ The `/snapshot` endpoint captures both the HTML content and a screenshot of the ## Basic usage +Navigate to `https://example.com/`, injecting custom JavaScript and then capturing the rendered HTML and taking a screenshot. + ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ -H 'Authorization: Bearer ' \ From 581c2d36ed233977f8f2273fdf83cda7f1f585b4 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:58:34 +0000 Subject: [PATCH 34/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/scrape-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index e4cd68b1915d9d..c155b4cf86bb1f 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: how-to -title: Scrape API +title: Scrape HTML elements sidebar: order: 7 --- From 31091640ffa55c2c9720b102400fef90018449b8 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:58:44 +0000 Subject: [PATCH 35/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/scrape-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index c155b4cf86bb1f..600aa121febb62 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -5,7 +5,7 @@ sidebar: order: 7 --- -The scrape API extracts structured data from specific elements on a webpage, returning details such as element dimensions and inner HTML. +The `/scrape` endpoint extracts structured data from specific elements on a webpage, returning details such as element dimensions and inner HTML. ## Basic usage From 8ee92dd2617fa16dfb9e7bde0cd2fa2a00e35273 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:58:57 +0000 Subject: [PATCH 36/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/screenshot-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 2540178de3af93..830d31a4485c92 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -5,7 +5,7 @@ sidebar: order: 3 --- -This endpoint renders the webpage by processing its HTML and JavaScript, then captures a screenshot of the fully rendered page. +The `/screenshot` endpoint renders the webpage by processing its HTML and JavaScript, then captures a screenshot of the fully rendered page. ## Basic usage From 161492dd2676a9c20576e86f760eb47c9810f169 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 11:59:20 +0000 Subject: [PATCH 37/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx Co-authored-by: Sofia --- .../docs/browser-rendering/quick-actions-rest-api/snapshot.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index 0feae946a73acc..8ebea5204cd516 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -38,6 +38,8 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- ## Advanced usage +Sets the HTML content of the page, disables JavaScript, changes the page size (`viewport`) and waits up to `30000ms` or until the `DOMContentLoaded` event fires. Then, returns the rendered HTML content and a base-64 encoded screenshot of the page. + ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ -H 'Authorization: Bearer ' \ From 5335a26cfbb3b28a2a5a950ae31952cb3c301bd4 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 12:06:59 +0000 Subject: [PATCH 38/70] minor fixes --- .../quick-actions-rest-api/scrape-endpoint.mdx | 13 ++++++++----- .../quick-actions-rest-api/screenshot-endpoint.mdx | 4 ---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx index 600aa121febb62..95d79405c0a305 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -14,11 +14,14 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -H 'Authorization: Bearer ' \ -H 'Content-Type: application/json' \ -d '{ - "url": "https://example.com/", - "elements": { - "selectors": ["h1", ".article"] - } - }' + "url": "https://example.com/", + "elements": [{ + "selector": "h1" + }, + { + "selector": "a" + }] +} ``` ### JSON response diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 830d31a4485c92..3f774cb8f782c2 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -32,9 +32,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -d '{ "url": "https://cloudflare.com/", "screenshotOptions": { - "type": "webp", "omitBackground": true, - "quality": 80 }, "viewport": { "width": 1280, @@ -77,9 +75,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- - `url` _(string)_ - The webpage URL to take a screenshot of. - `html` _(string)_ - Instead of a URL, allows rendering custom HTML for the screenshot. - `screenshotOptions` _(object)_ - Configures the screenshot format and quality. - - `type` _(string)_ - Defines the image format (`jpeg`, `png`, `webp`). - `omitBackground` _(boolean)_ - Removes the default white background when taking a screenshot. - - `quality` _(number)_ - (For JPEG/WebP) Compression quality from 0 to 100\. - `viewport` _(object)_ - Sets the browser viewport dimensions for rendering. - `width` _(number)_ - Viewport width in pixels. - `height` _(number)_ - Viewport height in pixels. From e5fe66300cbbd01a10fc8c4f412610953cc90652 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:12:44 +0000 Subject: [PATCH 39/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/screenshot-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 3f774cb8f782c2..2aebce5706fd79 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -63,7 +63,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- "content": "body { background: linear-gradient(45deg, #da5a44, #a32784); }" }, { - "url": "https://interactive-examples.mdn.mozilla.net/live-examples/css-examples/text-decoration/text-decoration-color.css" + "url": "https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" } ] }' \ From 3db0a710351c22730597b87eafa962930b5891ed Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:12:58 +0000 Subject: [PATCH 40/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/screenshot-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 2aebce5706fd79..26aecfe9af1ebe 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -60,7 +60,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- ], "addStyleTag": [ { - "content": "body { background: linear-gradient(45deg, #da5a44, #a32784); }" + "content": "div { background: linear-gradient(45deg, #2980b9 , #82e0aa ); }" }, { "url": "https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" From 048a6e2bdd9f9ab39edfc9c370566851d1c6f1dc Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:13:10 +0000 Subject: [PATCH 41/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/screenshot-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 26aecfe9af1ebe..a96d17d9a8cf03 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -55,7 +55,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -d '{ "url": "https://example.com/", "addScriptTag": [ - { "url": "https://code.jquery.com/jquery-3.7.1.min.js" }, + { "content": "document.querySelector(`h1`).innerText = `Hello World!!!`" } ], "addStyleTag": [ From 5371bdf149783b4f892515592d809f0b88c2e6d3 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:13:22 +0000 Subject: [PATCH 42/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/screenshot-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index a96d17d9a8cf03..8e0dd1974e9fac 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -46,7 +46,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- --output "advanced-screenshot.webp" ``` -## Customise CSS +## Customize CSS and embed custom JavaScript ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ From d6b0ad71ba104bb1ae8e99e3cb37f9df33daa3f6 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:13:35 +0000 Subject: [PATCH 43/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx Co-authored-by: Sofia --- .../docs/browser-rendering/quick-actions-rest-api/snapshot.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index 8ebea5204cd516..532711e906e269 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -18,7 +18,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -d '{ "url": "https://example.com/", "addScriptTag": [ - { "content": "document.body.innerHTML = "Snapshot Page";" } + { "content": "document.body.innerHTML = \"Snapshot Page\";" } ] }' ``` From 0de2ee89ebcb33d81d8f8c5641bcd77acde8f1b0 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:14:03 +0000 Subject: [PATCH 44/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx Co-authored-by: Sofia --- .../docs/browser-rendering/quick-actions-rest-api/snapshot.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index 532711e906e269..9076c0401385a4 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -28,7 +28,6 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- ```json title="json response" { "status": true, - "errors": [], "result": { "screenshot": "Base64EncodedScreenshotString", "content": "..." From 51803f985d9364d8137b68953514d4cb62ee08a4 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:15:11 +0000 Subject: [PATCH 45/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/screenshot-endpoint.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 8e0dd1974e9fac..68b6fc787240c3 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -16,7 +16,6 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -d '{ "html": "Hello World!", "screenshotOptions": { - "type": "webp", "omitBackground": true } }' \ From 69f7a8d79f71e266ebe3bab986158aae972bd362 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:15:29 +0000 Subject: [PATCH 46/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx Co-authored-by: Maddy <130055405+Maddy-Cloudflare@users.noreply.github.com> --- .../quick-actions-rest-api/content-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index d088856c218390..cb03927b7c7e66 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -9,7 +9,7 @@ The `/content` endpoint instructs the browser to navigate to a website and captu ## Basic usage -Navigate to `https://example.com` and return the rendered HTML. +Go to `https://example.com` and return the rendered HTML. ```bash curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/content' \ From 5adf461f42526af6321e24ae3c910155cddaa0b5 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:15:58 +0000 Subject: [PATCH 47/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx Co-authored-by: Maddy <130055405+Maddy-Cloudflare@users.noreply.github.com> --- .../docs/browser-rendering/quick-actions-rest-api/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx index 2f444de6c312da..038e1e16c35e44 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx @@ -12,6 +12,6 @@ import { DirectoryListing } from "~/components"; -Use the Quick Actions API when you need a fast, simple way to perform common browser tasks like capturing screenshots, extracting HTML, or generating PDFs without writing complex scripts. If you require more advanced automation, custom workflows, or persistent browser sessions, the [Workers Binding API](/browser-rendering/workers-binding-api/) is the better choice. +Use the Quick Actions API when you need a fast, simple way to perform common browser tasks such as capturing screenshots, extracting HTML, or generating PDFs without writing complex scripts. If you require more advanced automation, custom workflows, or persistent browser sessions, the [Workers Binding API](/browser-rendering/workers-binding-api/) is the better choice. Before you begin, make sure to [create a custom **API Token**](/fundamentals/api/get-started/create-token/) with your Account > **Browser Rendering**> **Edit** permissions from the [Cloudflare dashboard](https://dash.cloudflare.com/). From 92256371bd7583e823052672fe19a9df6f9034cd Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:16:25 +0000 Subject: [PATCH 48/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx Co-authored-by: Maddy <130055405+Maddy-Cloudflare@users.noreply.github.com> --- .../docs/browser-rendering/quick-actions-rest-api/index.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx index 038e1e16c35e44..b4a097078967df 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx @@ -14,4 +14,8 @@ import { DirectoryListing } from "~/components"; Use the Quick Actions API when you need a fast, simple way to perform common browser tasks such as capturing screenshots, extracting HTML, or generating PDFs without writing complex scripts. If you require more advanced automation, custom workflows, or persistent browser sessions, the [Workers Binding API](/browser-rendering/workers-binding-api/) is the better choice. -Before you begin, make sure to [create a custom **API Token**](/fundamentals/api/get-started/create-token/) with your Account > **Browser Rendering**> **Edit** permissions from the [Cloudflare dashboard](https://dash.cloudflare.com/). +Before you begin, make sure you [create a custom **API Token**](/fundamentals/api/get-started/create-token/): + +1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/). +2. Go to your account, then select **Browser Rendering**. +3. Select **Edit** permissions. From 21bb019b59f21510cbe7033ea6dd4b8510c78f86 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:16:41 +0000 Subject: [PATCH 49/70] Update src/content/docs/browser-rendering/workers-binding-api/index.mdx Co-authored-by: Maddy <130055405+Maddy-Cloudflare@users.noreply.github.com> --- .../docs/browser-rendering/workers-binding-api/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/workers-binding-api/index.mdx b/src/content/docs/browser-rendering/workers-binding-api/index.mdx index 0fca5260371fd6..dbfac2ebb499ad 100644 --- a/src/content/docs/browser-rendering/workers-binding-api/index.mdx +++ b/src/content/docs/browser-rendering/workers-binding-api/index.mdx @@ -7,7 +7,7 @@ sidebar: import { DirectoryListing } from "~/components"; -The Workers Binding API allows you to execute advanced browser rendering scripts within Cloudflare Workers. It provides developers with the flexibility to automate and control complex workflows and browser interactions. The following options are available for browser rendering tasks: +The Workers Binding API allows you to execute advanced browser rendering scripts within Cloudflare Workers. It provides developers the flexibility to automate and control complex workflows and browser interactions. The following options are available for browser rendering tasks: From a4d75c97b35dd3fced61e569d3ce4f8bed28b64d Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:25:41 +0000 Subject: [PATCH 50/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx Co-authored-by: Maddy <130055405+Maddy-Cloudflare@users.noreply.github.com> --- .../browser-rendering/quick-actions-rest-api/snapshot.mdx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index 9076c0401385a4..30c98e6647ae47 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -9,7 +9,12 @@ The `/snapshot` endpoint captures both the HTML content and a screenshot of the ## Basic usage -Navigate to `https://example.com/`, injecting custom JavaScript and then capturing the rendered HTML and taking a screenshot. + +1. Go to `https://example.com/`. +2. Inject custom JavaScript. +3. Capture the rendered HTML. +4. Take a screenshot. + ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ From b68d7e66ff4ae4d1b7c1f021cad7c25727d8e893 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:26:02 +0000 Subject: [PATCH 51/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx Co-authored-by: Maddy <130055405+Maddy-Cloudflare@users.noreply.github.com> --- .../browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index 65296b834798a3..28928d958e01fa 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -47,7 +47,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- ## PDF with no images or CSS -This is ideal when the user wants to so speed up the scanning process and does not need the images. +Use PDF with no images or CSS if you want to accelerate the scanning process and you do not need the images. ```bash curl -X POST https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf \ From 35e2abdcd9d7ef1b3d0c4498bdddc6233d475f80 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:26:18 +0000 Subject: [PATCH 52/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx Co-authored-by: Maddy <130055405+Maddy-Cloudflare@users.noreply.github.com> --- .../quick-actions-rest-api/screenshot-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 68b6fc787240c3..62e471655c08fa 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -80,7 +80,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- - `height` _(number)_ - Viewport height in pixels. - `gotoOptions` _(object)_ - Configures how and when the page is considered fully loaded. - `waitUntil` _(string)_ - Defines when the browser considers navigation complete (`networkidle0`, `domcontentloaded`). - - `networkidle0` - Waits until there are no more than 0 network connections for at least 500ms before taking a screenshot. + - `networkidle0` - Waits until there are no more than 0 network connections for at least 500 ms before taking a screenshot. - `timeout` _(number)_ - Maximum wait time (in milliseconds) before navigation times out. - `addScriptTag` _(array of objects)_ - Injects JavaScript code before taking a screenshot. - `url` _(string)_ - Loads an external script file before rendering. From 6fb4b3b189e03b34495687fec8fe5abd0a4937b3 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:30:06 +0000 Subject: [PATCH 53/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/screenshot-endpoint.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 62e471655c08fa..83a1c836e44a10 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -31,6 +31,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -d '{ "url": "https://cloudflare.com/", "screenshotOptions": { + "fullPage": true, "omitBackground": true, }, "viewport": { From a80e9c88e8bc74dc3e875de2d9ce2787cc67cd05 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:30:31 +0000 Subject: [PATCH 54/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/content-endpoint.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx index cb03927b7c7e66..d4bb17611e512b 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -20,6 +20,8 @@ curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts//browse ## Advanced usage +Navigate to `https://cloudflare.com/` but block images and stylesheets from loading. Undesired requests can be blocked by resource type (`rejectResourceTypes`) or by using a regex pattern (`rejectRequestPattern`). + ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/content' \ -H 'Authorization: Bearer ' \ From ad050ce6a3f3e7387930ff0adeb53598e9300d35 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:31:14 +0000 Subject: [PATCH 55/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx Co-authored-by: Sofia --- .../browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index 28928d958e01fa..3e164c7e3cce88 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: how-to -title: PDF API +title: Render PDF sidebar: order: 5 --- From 11c235f928b21a357df1fef7bf2617dda44207db Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:31:38 +0000 Subject: [PATCH 56/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx Co-authored-by: Sofia --- .../browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index 3e164c7e3cce88..4b7a17bf37642c 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -9,6 +9,8 @@ The `/pdf` endpoint instructs the browser to render the webpage as a PDF documen ## Basic usage +Navigate to `https://example.com/` and inject custom CSS and an external stylesheet. Then return the rendered page as a PDF. + ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ -H 'Authorization: Bearer ' \ From 4653fd5902ec6cef23822c63ba45df0ca8d1eea7 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:32:23 +0000 Subject: [PATCH 57/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx Co-authored-by: Sofia --- .../browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index 4b7a17bf37642c..e6a61fe08750bd 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -18,7 +18,8 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- -d '{ "url": "https://example.com/", "addStyleTag": [ - { "content": "body { font-family: Arial; }" } + { "content": "body { font-family: Arial; }" }, + { "url": "https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" } ] }' \ --output "output.pdf" From 96fe9a2bdc02fa04abef5402291e4174c3419073 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:32:49 +0000 Subject: [PATCH 58/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx Co-authored-by: Sofia --- .../browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx index e6a61fe08750bd..7ca1c02a0a1543 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -27,6 +27,10 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- ## Advanced usage +Navigate to `https://example.com`, first setting an additional HTTP request header and configuring the page size (`viewport`). Then, wait until there are no more than 2 network connections for at least 500 ms, or until the maximum timeout of 4500 ms is reached, before considering the page loaded and returning the rendered PDF document. + +The `goToOptions` parameter exposes most of [Puppeteer'd API](https://pptr.dev/api/puppeteer.gotooptions). + ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ -H 'Authorization: Bearer ' \ From e0d80029ee9780984ddf8722d18d41688829bd20 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 13:51:32 +0000 Subject: [PATCH 59/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/screenshot-endpoint.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 83a1c836e44a10..d64cc15920f895 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -1,6 +1,6 @@ --- pcx_content_type: how-to -title: Screenshot API +title: Capture screenshot sidebar: order: 3 --- From 048a8b1875cf8ff9d93f3effcc917527b10acc6a Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 14:38:23 +0000 Subject: [PATCH 60/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/screenshot-endpoint.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index d64cc15920f895..362c39f4bc32d8 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -9,6 +9,8 @@ The `/screenshot` endpoint renders the webpage by processing its HTML and JavaSc ## Basic usage +Sets the HTML content of the page to `Hello World!` and then takes a screenshot. The option `omitBackground` hides the default white background and allows capturing screenshots with transparency. + ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ -H 'Authorization: Bearer ' \ From d567aafad83ba891d427cb0971f4e4743b499765 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 14:39:07 +0000 Subject: [PATCH 61/70] Update src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx Co-authored-by: Sofia --- .../quick-actions-rest-api/screenshot-endpoint.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx index 362c39f4bc32d8..63d665dc7f1adc 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -26,6 +26,8 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- ## Advanced usage +Navigate to `https://cloudflare.com/`, changing the page size and waiting until there are no active network connections or up to a maximum of `4500ms`. Then take a `fullPage` screenshot. + ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ -H 'Authorization: Bearer ' \ From eff3d93a41a1a365ba8cbb039d2bb3964d295506 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 14:44:02 +0000 Subject: [PATCH 62/70] minor fixes --- .../quick-actions-rest-api/snapshot.mdx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx index 30c98e6647ae47..8bbb4263e3a2d5 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -9,13 +9,11 @@ The `/snapshot` endpoint captures both the HTML content and a screenshot of the ## Basic usage - 1. Go to `https://example.com/`. 2. Inject custom JavaScript. 3. Capture the rendered HTML. 4. Take a screenshot. - ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ -H 'Authorization: Bearer ' \ @@ -42,7 +40,12 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- ## Advanced usage -Sets the HTML content of the page, disables JavaScript, changes the page size (`viewport`) and waits up to `30000ms` or until the `DOMContentLoaded` event fires. Then, returns the rendered HTML content and a base-64 encoded screenshot of the page. +The `html` property in the JSON payload, it sets the html to `Advanced Snapshot` then does the following steps: + +1. Disable JavaScript. +2. Changes the page size `(viewport)`. +3. Waits up to `30000ms` or until the `DOMContentLoaded` event starts. +4. Returns the rendered HTML content and a base-64 encoded screenshot of the page. ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ From e31c9ad5038b9d7ac5ef7f591c41a08e332e85a2 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 15:41:44 +0000 Subject: [PATCH 63/70] links fix --- .../docs/browser-rendering/how-to/pdf-generation.mdx | 7 +++---- src/content/docs/browser-rendering/platform/puppeteer.mdx | 2 +- .../workers-binding-api/reuse-sessions.mdx | 7 ++++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/content/docs/browser-rendering/how-to/pdf-generation.mdx b/src/content/docs/browser-rendering/how-to/pdf-generation.mdx index 22a40c370f7163..243ff0afb296b7 100644 --- a/src/content/docs/browser-rendering/how-to/pdf-generation.mdx +++ b/src/content/docs/browser-rendering/how-to/pdf-generation.mdx @@ -7,7 +7,7 @@ sidebar: import { Aside, WranglerConfig } from "~/components"; -As seen in the [Getting Started guide](/browser-rendering/get-started/screenshots/), Browser Rendering can be used to generate screenshots for any given URL. Alongside screenshots, you can also generate full PDF documents for a given webpage, and can also provide the webpage markup and style ourselves. +As seen in the [Getting Started guide](/browser-rendering/workers-binding-api/screenshots/), Browser Rendering can be used to generate screenshots for any given URL. Alongside screenshots, you can also generate full PDF documents for a given webpage, and can also provide the webpage markup and style ourselves. ## Prerequisites @@ -26,9 +26,8 @@ npm install @cloudflare/puppeteer --save-dev 3. Add your Browser Rendering binding to your new Wrangler configuration: -```toml -browser = { binding = "BROWSER" } -``` + ```toml browser = {(binding = "BROWSER")} + ``` 4. Replace the contents of `src/index.ts` (or `src/index.js` for JavaScript projects) with the following skeleton script: diff --git a/src/content/docs/browser-rendering/platform/puppeteer.mdx b/src/content/docs/browser-rendering/platform/puppeteer.mdx index 6e8b6717cb0031..efdd6ea548404e 100644 --- a/src/content/docs/browser-rendering/platform/puppeteer.mdx +++ b/src/content/docs/browser-rendering/platform/puppeteer.mdx @@ -67,7 +67,7 @@ This script [launches](https://pptr.dev/api/puppeteer.puppeteernode.launch) the ### Keep Alive -If users omit the `browser.close()` statement, it will stay open, ready to be connected to again and [re-used](/browser-rendering/get-started/reuse-sessions/) but it will, by default, close automatically after 1 minute of inactivity. Users can optionally extend this idle time up to 10 minutes, by using the `keep_alive` option, set in milliseconds: +If users omit the `browser.close()` statement, it will stay open, ready to be connected to again and [re-used](/browser-rendering/workers-binding-api/reuse-sessions/) but it will, by default, close automatically after 1 minute of inactivity. Users can optionally extend this idle time up to 10 minutes, by using the `keep_alive` option, set in milliseconds: ```js const browser = await puppeteer.launch(env.MYBROWSER, { keep_alive: 600000 }); diff --git a/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx b/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx index 9c1f54f8d5ec77..9f647e47774d92 100644 --- a/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx +++ b/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx @@ -7,7 +7,7 @@ sidebar: import { Render, PackageManagers, WranglerConfig } from "~/components"; -The best way to improve the performance of your browser rendering worker is to reuse sessions. One way to do that is via [Durable Objects](/browser-rendering/get-started/browser-rendering-with-do/), which allows you to keep a long running connection from a worker to a browser. Another way is to keep the browser open after you've finished with it, and connect to that session each time you have a new request. +The best way to improve the performance of your browser rendering worker is to reuse sessions. One way to do that is via [Durable Objects](/browser-rendering/workers-binding-api/browser-rendering-with-do/), which allows you to keep a long running connection from a worker to a browser. Another way is to keep the browser open after you've finished with it, and connect to that session each time you have a new request. In short, this entails using `browser.disconnect()` instead of `browser.close()`, and, if there are available sessions, using `puppeteer.connect(env.MY_BROWSER, sessionID)` instead of launching a new browser session. @@ -51,7 +51,8 @@ compatibility_date = "2023-03-14" compatibility_flags = [ "nodejs_compat" ] browser = { binding = "MYBROWSER" } -``` + +```` ## 4. Code @@ -133,7 +134,7 @@ export default { return sessionId!; }, }; -``` +```` Besides `puppeteer.sessions()`, we've added other methods to facilitate [Session Management](/browser-rendering/platform/puppeteer/#session-management). From 227b7b13ce3e60d751b491ef53aa22b294e804a7 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 15:44:02 +0000 Subject: [PATCH 64/70] Update src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com> --- .../browser-rendering/workers-binding-api/reuse-sessions.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx b/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx index 9f647e47774d92..5b767eaab24d5a 100644 --- a/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx +++ b/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx @@ -7,7 +7,7 @@ sidebar: import { Render, PackageManagers, WranglerConfig } from "~/components"; -The best way to improve the performance of your browser rendering worker is to reuse sessions. One way to do that is via [Durable Objects](/browser-rendering/workers-binding-api/browser-rendering-with-do/), which allows you to keep a long running connection from a worker to a browser. Another way is to keep the browser open after you've finished with it, and connect to that session each time you have a new request. +The best way to improve the performance of your browser rendering Worker is to reuse sessions. One way to do that is via [Durable Objects](/browser-rendering/workers-binding-api/browser-rendering-with-do/), which allows you to keep a long running connection from a Worker to a browser. Another way is to keep the browser open after you've finished with it, and connect to that session each time you have a new request. In short, this entails using `browser.disconnect()` instead of `browser.close()`, and, if there are available sessions, using `puppeteer.connect(env.MY_BROWSER, sessionID)` instead of launching a new browser session. From ffd76d674cd7a60ec7db8a59ffe827590850c3f6 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 15:54:19 +0000 Subject: [PATCH 65/70] code fix --- .../browser-rendering/workers-binding-api/reuse-sessions.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx b/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx index 5b767eaab24d5a..97a19866dacea0 100644 --- a/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx +++ b/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx @@ -52,7 +52,7 @@ compatibility_flags = [ "nodejs_compat" ] browser = { binding = "MYBROWSER" } -```` +``` ## 4. Code @@ -134,7 +134,7 @@ export default { return sessionId!; }, }; -```` +``` Besides `puppeteer.sessions()`, we've added other methods to facilitate [Session Management](/browser-rendering/platform/puppeteer/#session-management). From d4c37cadce6b9f026d1a49c2fe33425942f6871d Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Thu, 27 Feb 2025 16:14:21 +0000 Subject: [PATCH 66/70] removed link --- src/content/docs/browser-rendering/platform/puppeteer.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/browser-rendering/platform/puppeteer.mdx b/src/content/docs/browser-rendering/platform/puppeteer.mdx index efdd6ea548404e..76a21ed5057e6a 100644 --- a/src/content/docs/browser-rendering/platform/puppeteer.mdx +++ b/src/content/docs/browser-rendering/platform/puppeteer.mdx @@ -11,7 +11,7 @@ import { TabItem, Tabs } from "~/components"; Puppeteer typically connects to a local Chrome or Chromium browser using the DevTools port. Refer to the [Puppeteer API documentation on the `Puppeteer.connect()` method](https://pptr.dev/api/puppeteer.puppeteer.connect) for more information. -The Workers team forked a version of Puppeteer and patched it to connect to the Workers Browser Rendering API instead. The [changes between Workers Puppeteer fork and the Puppeteer core](https://github.com/cloudflare/puppeteer/blob/main/src/puppeteer-core.ts) are minimal. After connecting, the developers can then use the full [Puppeteer API](https://github.com/cloudflare/puppeteer/blob/main/docs/api/index.md) as they would on a standard setup. +The Workers team forked a version of Puppeteer and patched it to connect to the Workers Browser Rendering API instead. After connecting, the developers can then use the full [Puppeteer API](https://github.com/cloudflare/puppeteer/blob/main/docs/api/index.md) as they would on a standard setup. Our version is open sourced and can be found in [Cloudflare's fork of Puppeteer](https://github.com/cloudflare/puppeteer). The npm can be installed from [npmjs](https://www.npmjs.com/) as [@cloudflare/puppeteer](https://www.npmjs.com/package/@cloudflare/puppeteer): From bd711a5a7872f0a119f4f9d5f87197d9eb9ecaf3 Mon Sep 17 00:00:00 2001 From: kodster28 Date: Thu, 27 Feb 2025 12:04:16 -0600 Subject: [PATCH 67/70] Fix error --- .../docs/browser-rendering/how-to/pdf-generation.mdx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/content/docs/browser-rendering/how-to/pdf-generation.mdx b/src/content/docs/browser-rendering/how-to/pdf-generation.mdx index 243ff0afb296b7..fd78e0b7f04bb5 100644 --- a/src/content/docs/browser-rendering/how-to/pdf-generation.mdx +++ b/src/content/docs/browser-rendering/how-to/pdf-generation.mdx @@ -26,8 +26,10 @@ npm install @cloudflare/puppeteer --save-dev 3. Add your Browser Rendering binding to your new Wrangler configuration: - ```toml browser = {(binding = "BROWSER")} - ``` + +```toml title="wrangler.toml" +browser = { binding = "BROWSER" } +``` 4. Replace the contents of `src/index.ts` (or `src/index.js` for JavaScript projects) with the following skeleton script: From 0540b696e67a26f101e0ccd22700cf0beac56dfe Mon Sep 17 00:00:00 2001 From: kodster28 Date: Thu, 27 Feb 2025 12:34:37 -0600 Subject: [PATCH 68/70] Added beta badge --- .../docs/browser-rendering/quick-actions-rest-api/index.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx index b4a097078967df..915916bbce18a1 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx @@ -3,6 +3,8 @@ pcx_content_type: navigation title: Quick Actions REST API sidebar: order: 2 + group: + badge: Beta --- The Quick Actions API is a RESTful interface that provides endpoints for common browser actions such as capturing screenshots, extracting HTML content, generating PDFs, and more. From 7034b6ef30ab970b773cc430e2cb9130a4081439 Mon Sep 17 00:00:00 2001 From: Kody Jackson Date: Thu, 27 Feb 2025 12:54:08 -0600 Subject: [PATCH 69/70] Update public/_redirects --- public/_redirects | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/_redirects b/public/_redirects index 1e3cdedb6da1f4..2ab4f23fe407b2 100644 --- a/public/_redirects +++ b/public/_redirects @@ -180,7 +180,7 @@ /bots/reference/verified-bot-policy/ /bots/concepts/bot/verified-bots/policy/ 301 #browser-rendering -/browser-rendering/get-started/browser-rendering-with-DO/ /browser-rendering/workers-binding-api/browser-rendering-with-do/ 301 +/browser-rendering/get-started/browser-rendering-with-do/ /browser-rendering/workers-binding-api/browser-rendering-with-do/ 301 /browser-rendering/get-started/reuse-sessions/ /browser-rendering/workers-binding-api/reuse-sessions/ 301 /browser-rendering/get-started/screenshots/ /browser-rendering/workers-binding-api/screenshots/ 301 From 84accea8e44f4b17be1bf699a0f11d0b843ab5fc Mon Sep 17 00:00:00 2001 From: kodster28 Date: Thu, 27 Feb 2025 13:00:09 -0600 Subject: [PATCH 70/70] Small edit --- .../browser-rendering/quick-actions-rest-api/index.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx index 915916bbce18a1..fb9435a6bfb51b 100644 --- a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx @@ -16,8 +16,8 @@ import { DirectoryListing } from "~/components"; Use the Quick Actions API when you need a fast, simple way to perform common browser tasks such as capturing screenshots, extracting HTML, or generating PDFs without writing complex scripts. If you require more advanced automation, custom workflows, or persistent browser sessions, the [Workers Binding API](/browser-rendering/workers-binding-api/) is the better choice. -Before you begin, make sure you [create a custom **API Token**](/fundamentals/api/get-started/create-token/): +## Before you begin -1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/). -2. Go to your account, then select **Browser Rendering**. -3. Select **Edit** permissions. +Before you begin, make sure you [create a custom API Token](/fundamentals/api/get-started/create-token/) with the following permissions: + +- `Browser Rendering - Edit`