Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ The `/content` endpoint instructs the browser to navigate to a website and captu

<Tabs syncKey="workersExamples"> <TabItem label="curl">

Go to `https://example.com` and return the rendered HTML.
Go to `https://developers.cloudflare.com/` and return the rendered HTML.

```bash
curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/content' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <apiToken>' \
-d '{"url": "https://example.com"}'
-d '{"url": "https://developers.cloudflare.com/"}'
```

</TabItem> <TabItem label="TypeScript SDK">
Expand All @@ -28,12 +28,12 @@ curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browse
import Cloudflare from "cloudflare";

const client = new Cloudflare({
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
});

const content = await client.browserRendering.content.create({
account_id: "account_id",
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
url: "https://developers.cloudflare.com/",
});

console.log(content);
Expand Down
42 changes: 34 additions & 8 deletions src/content/docs/browser-rendering/rest-api/json-endpoint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID
"prompt": "Get me the list of AI products",
"response_format": {
"type": "json_schema",
"json_schema": {
"schema": {
"type": "object",
"properties": {
"products": {
Expand Down Expand Up @@ -130,7 +130,7 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID
--header 'content-type: application/json' \
--data '"response_format": {
"type": "json_schema",
"json_schema": {
"schema": {
"type": "object",
"properties": {
"products": {
Expand Down Expand Up @@ -233,14 +233,40 @@ Below is an example using the TypeScript SDK:
import Cloudflare from "cloudflare";

const client = new Cloudflare({
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
apiToken: process.env["CLOUDFLARE_API_TOKEN"], // This is the default and can be omitted
});

const json = await client.browserRendering.json.create({
account_id: "account_id",
});

account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
url: "https://developers.cloudflare.com/",
prompt: "Get me the list of AI products",
response_format: {
type: "json_schema",
schema: {
type: "object",
properties: {
products: {
type: "array",
items: {
type: "object",
properties: {
name: {
type: "string"
},
link: {
type: "string"
}
},
required: [
"name"
]
}
}
}
}
}
}
);
console.log(json);
```

Expand All @@ -267,7 +293,7 @@ curl --request POST \
"prompt": "Get the heading from the page in the form of an object like h1, h2. If there are many headings of the same kind then grab the first one.",
"response_format": {
"type": "json_schema",
"json_schema": {
"schema": {
"type": "object",
"properties": {
"h1": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
import Cloudflare from "cloudflare";

const client = new Cloudflare({
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
});

const links = await client.browserRendering.links.create({
account_id: "account_id",
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
url: "https://developers.cloudflare.com/",
});

console.log(links);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browse
import Cloudflare from "cloudflare";

const client = new Cloudflare({
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
});

const markdown = await client.browserRendering.markdown.create({
account_id: "account_id",
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
url: "https://developers.cloudflare.com/",
});

console.log(markdown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
import Cloudflare from "cloudflare";

const client = new Cloudflare({
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
});

const pdf = await client.browserRendering.pdf.create({
account_id: "account_id",
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
url: "https://example.com/",
addStyleTag: [
{ content: "body { font-family: Arial; }" }
]
});

console.log(pdf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
import Cloudflare from "cloudflare";

const client = new Cloudflare({
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
});

const scrapes = await client.browserRendering.scrape.create({
account_id: "account_id",
elements: [{ selector: "selector" }],
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
elements: [
{ selector: "h1" },
{ selector: "a" }
]
});

console.log(scrapes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
import Cloudflare from "cloudflare";

const client = new Cloudflare({
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
});

const screenshot = await client.browserRendering.screenshot.create({
account_id: "account_id",
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
html: "Hello World!",
screenshotOptions: {
omitBackground: true,
}
});

console.log(screenshot.status);
Expand Down
9 changes: 6 additions & 3 deletions src/content/docs/browser-rendering/rest-api/snapshot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
import Cloudflare from "cloudflare";

const client = new Cloudflare({
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
});

const snapshot = await client.browserRendering.snapshot.create({
account_id: "account_id",
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
url: "https://example.com/",
addScriptTag: [
{ content: "document.body.innerHTML = \"Snapshot Page\";" }
]
});

console.log(snapshot.content);
Expand Down
Loading