diff --git a/src/content/docs/browser-rendering/rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/rest-api/content-endpoint.mdx index 7c50f322f85c1b7..1157199b9ff575c 100644 --- a/src/content/docs/browser-rendering/rest-api/content-endpoint.mdx +++ b/src/content/docs/browser-rendering/rest-api/content-endpoint.mdx @@ -9,8 +9,26 @@ import { Tabs, TabItem, Render } from "~/components"; 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. +## Endpoint + +```txt +https://api.cloudflare.com/client/v4/accounts//browser-rendering/content +``` + +## Required fields +You must provide either `url` or `html`: +- `url` (string) +- `html` (string) + +## Common use cases + +- Capture the fully rendered HTML of a dynamic page +- Extract HTML for parsing, scraping, or downstream processing + ## Basic usage +### Fetch rendered HTML from a URL + Go to `https://developers.cloudflare.com/` and return the rendered HTML. @@ -43,6 +61,8 @@ console.log(content); ## Advanced usage +### Block specific resource types + 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`). The opposite can also be done, only allow requests that match `allowRequestPattern` or `allowResourceTypes`. ```bash diff --git a/src/content/docs/browser-rendering/rest-api/json-endpoint.mdx b/src/content/docs/browser-rendering/rest-api/json-endpoint.mdx index 0d9bba0df2b105e..fd185ec46c8bca5 100644 --- a/src/content/docs/browser-rendering/rest-api/json-endpoint.mdx +++ b/src/content/docs/browser-rendering/rest-api/json-endpoint.mdx @@ -17,12 +17,33 @@ By default, the `/json` endpoint leverages [Workers AI](/workers-ai/) for data e ::: -## Basic Usage +## Endpoint - +```txt +https://api.cloudflare.com/client/v4/accounts//browser-rendering/json +``` + +## Required fields +You must provide either `url` or `html`: +- `url` (string) +- `html` (string) + +And at least one of: +- `prompt` (string), or +- `response_format` (object with a JSON Schema) + +## Common use cases + +- Extract product info (title, price, availability) or listings (jobs, rentals) +- Normalize article metadata (title, author, publish date, canonical URL) +- Convert unstructured pages into typed JSON for downstream pipelines + +## Basic Usage ### With a Prompt and JSON schema + + This example captures webpage data by providing both a prompt and a JSON schema. The prompt guides the extraction process, while the JSON schema defines the expected structure of the output. ```bash diff --git a/src/content/docs/browser-rendering/rest-api/links-endpoint.mdx b/src/content/docs/browser-rendering/rest-api/links-endpoint.mdx index ac8cc44d9c79ed1..15f33a0f4dc831e 100644 --- a/src/content/docs/browser-rendering/rest-api/links-endpoint.mdx +++ b/src/content/docs/browser-rendering/rest-api/links-endpoint.mdx @@ -9,11 +9,29 @@ import { Tabs, TabItem, Render } from "~/components"; The `/links` endpoint retrieves all links from a webpage. It can be used to extract all links from a page, including those that are hidden. +## Endpoint + +```txt +https://api.cloudflare.com/client/v4/accounts//browser-rendering/links +``` + +## Required fields +You must provide either `url` or `html`: +- `url` (string) + +## Common use cases + +- Collect only user-visible links for UX or SEO analysis +- Crawl a site by discovering links on seed pages +- Validate navigation/footers and detect broken or external links + ## Basic usage +### Get all links on a page + -This example grabs all links from the Cloudflare Developers homepage. +This example grabs all links from the [Cloudflare Developer's homepage](https://developers.cloudflare.com/). The response will be a JSON array containing the links found on the page. ```bash diff --git a/src/content/docs/browser-rendering/rest-api/markdown-endpoint.mdx b/src/content/docs/browser-rendering/rest-api/markdown-endpoint.mdx index 44b04c2fc28e9d7..13785dbf07f4fa3 100644 --- a/src/content/docs/browser-rendering/rest-api/markdown-endpoint.mdx +++ b/src/content/docs/browser-rendering/rest-api/markdown-endpoint.mdx @@ -9,9 +9,26 @@ import { Tabs, TabItem, Render } from "~/components"; The `/markdown` endpoint retrieves a webpage's content and converts it into Markdown format. You can specify a URL and optional parameters to refine the extraction process. +## Endpoint + +```txt +https://api.cloudflare.com/client/v4/accounts//browser-rendering/markdown +``` + +## Required fields +You must provide either `url` or `html`: +- `url` (string) +- `html` (string) + +## Common use cases + +- Normalize content for downstream processing (summaries, diffs, embeddings) +- Save articles or docs for editing or storage +- Strip styling/scripts and keep readable content + links + ## Basic usage -### Using a URL +### Convert a URL to Markdown @@ -52,7 +69,7 @@ console.log(markdown); -### Use raw HTML +### Convert raw HTML to Markdown Instead of fetching the content by specifying the URL, you can provide raw HTML content directly. @@ -74,6 +91,8 @@ curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts//browse ## Advanced usage +### Exclude unwanted requests (for example, CSS) + You can refine the Markdown extraction by using the `rejectRequestPattern` parameter. In this example, requests matching the given regex pattern (such as CSS files) are excluded. ```bash diff --git a/src/content/docs/browser-rendering/rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/rest-api/scrape-endpoint.mdx index 86ea9575e0d06f8..4b4ca90d318a216 100644 --- a/src/content/docs/browser-rendering/rest-api/scrape-endpoint.mdx +++ b/src/content/docs/browser-rendering/rest-api/scrape-endpoint.mdx @@ -9,8 +9,26 @@ import { Tabs, TabItem, Render } from "~/components"; The `/scrape` endpoint extracts structured data from specific elements on a webpage, returning details such as element dimensions and inner HTML. +## Endpoint + +```txt +https://api.cloudflare.com/client/v4/accounts//browser-rendering/scrape +``` + +## Required fields +You must provide either `url` or `html`: +- `url` (string) +- `elements` (array of objects) — each object must include `selector` (string) + +## Common use cases + +- Extract headings, links, prices, or other repeated content with CSS selectors +- Collect metadata (for example, titles, descriptions, canonical links) + ## Basic usage +### Extract headings and links from a URL + Go to `https://example.com` and extract metadata from all `h1` and `a` elements in the DOM. diff --git a/src/content/docs/browser-rendering/rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/rest-api/screenshot-endpoint.mdx index 7591ccff540250f..5f4447d8e57b87f 100644 --- a/src/content/docs/browser-rendering/rest-api/screenshot-endpoint.mdx +++ b/src/content/docs/browser-rendering/rest-api/screenshot-endpoint.mdx @@ -9,9 +9,25 @@ import { Tabs, TabItem, Render } from "~/components"; The `/screenshot` endpoint renders the webpage by processing its HTML and JavaScript, then captures a screenshot of the fully rendered page. +## Endpoint + +```txt +https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot +``` + +## Required fields +You must provide either `url` or `html`: +- `url` (string) +- `html` (string) + +## Common use cases + +- Generate previews for websites, dashboards, or reports +- Capture screenshots for automated testing, QA, or visual regression + ## Basic usage -### Capture a screenshot from HTML +### Take a screenshot from custom HTML @@ -52,7 +68,7 @@ console.log(screenshot.status); -### Capture a screenshot from a URL +### Take a screenshot from a URL /browser- --output "authenticated-screenshot.png" ``` - ### Navigate and capture a full-page screenshot -Navigate to `https://cloudflare.com/`, changing the page size (`viewport`) and waiting until there are no active network connections (`waitUntil`) or up to a maximum of `4500ms` (`timeout`). Then take a `fullPage` screenshot. +Navigate to `https://cloudflare.com/`, change the page size (`viewport`) and wait until there are no active network connections (`waitUntil`) or up to a maximum of `4500ms` (`timeout`) before capturing a `fullPage` screenshot. ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ @@ -140,7 +155,9 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- }' \ --output "screenshot.png" ``` + ### Capture a specific element using the selector option + To capture a screenshot of a specific element on a webpage, use the `selector` option with a valid CSS selector. You can also configure the `viewport` to control the page dimensions during rendering. ```bash diff --git a/src/content/docs/browser-rendering/rest-api/snapshot.mdx b/src/content/docs/browser-rendering/rest-api/snapshot.mdx index 0d6faabed910e04..f618a5514dc4756 100644 --- a/src/content/docs/browser-rendering/rest-api/snapshot.mdx +++ b/src/content/docs/browser-rendering/rest-api/snapshot.mdx @@ -9,8 +9,27 @@ import { Tabs, TabItem, Render } from "~/components"; 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. +## Endpoint + +```txt +https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot +``` + +## Required fields +You must provide either `url` or `html`: +- `url` (string) +- `html` (string) + +## Common use cases + +- Capture both the rendered HTML and a visual screenshot in a single API call +- Archive pages with visual and structural data together +- Build monitoring tools that compare visual and DOM differences over time + ## Basic usage +### Capture a snapshot from a URL + 1. Go to `https://example.com/`. @@ -64,6 +83,8 @@ console.log(snapshot.content); ## Advanced usage +### Create a snapshot from custom HTML + The `html` property in the JSON payload, it sets the html to `Advanced Snapshot` then does the following steps: 1. Disable JavaScript.