# Browser Rendering
# Content
## Get HTML content.
`client.browserRendering.content.create(ContentCreateParamsparams, RequestOptionsoptions?): ContentCreateResponse`
**post** `/accounts/{account_id}/browser-rendering/content`
Fetches rendered HTML content from provided URL or HTML. Check available options like `gotoOptions` and `waitFor*` to control page load behaviour.
### Parameters
- `ContentCreateParams = Variant0 | Variant1`
- `ContentCreateParamsBase`
- `Variant0 extends ContentCreateParamsBase`
- `Variant1 extends ContentCreateParamsBase`
### Returns
- `ContentCreateResponse = string`
HTML content.
### Example
```node
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});
const content = await client.browserRendering.content.create({
account_id: 'account_id',
url: 'https://www.example.com/',
});
console.log(content);
```
#### Response
```json
{
"meta": {
"status": 0,
"title": "title"
},
"success": true,
"errors": [
{
"code": 0,
"message": "message"
}
],
"result": "result"
}
```
## Domain Types
### Content Create Response
- `ContentCreateResponse = string`
HTML content.
# PDF
## Get PDF.
`client.browserRendering.pdf.create(PDFCreateParamsparams, RequestOptionsoptions?): Response`
**post** `/accounts/{account_id}/browser-rendering/pdf`
Fetches rendered PDF from provided URL or HTML. Check available options like `gotoOptions` and `waitFor*` to control page load behaviour.
### Parameters
- `PDFCreateParams = Variant0 | Variant1`
- `PDFCreateParamsBase`
- `Variant0 extends PDFCreateParamsBase`
- `Variant1 extends PDFCreateParamsBase`
### Returns
- `unnamed_schema_11 = Response`
### Example
```node
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});
const pdf = await client.browserRendering.pdf.create({
account_id: 'account_id',
html: '
Hello World!
',
});
console.log(pdf);
const content = await pdf.blob();
console.log(content);
```
#### Response
```json
{
"errors": [
{
"code": 2001,
"message": "Rate limit exceeded"
}
],
"success": false
}
```
# Scrape
## Scrape elements.
`client.browserRendering.scrape.create(ScrapeCreateParamsparams, RequestOptionsoptions?): ScrapeCreateResponse`
**post** `/accounts/{account_id}/browser-rendering/scrape`
Get meta attributes like height, width, text and others of selected elements.
### Parameters
- `ScrapeCreateParams = Variant0 | Variant1`
- `ScrapeCreateParamsBase`
- `Variant0 extends ScrapeCreateParamsBase`
- `Variant1 extends ScrapeCreateParamsBase`
### Returns
- `ScrapeCreateResponse = Array`
- `results: Results`
- `attributes: Array`
- `name: string`
Attribute name.
- `value: string`
Attribute value.
- `height: number`
Element height.
- `html: string`
HTML content.
- `left: number`
Element left.
- `text: string`
Text content.
- `top: number`
Element top.
- `width: number`
Element width.
- `selector: string`
Selector.
### Example
```node
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});
const scrapes = await client.browserRendering.scrape.create({
account_id: 'account_id',
elements: [{ selector: 'h1' }],
html: 'Hello World!
',
});
console.log(scrapes);
```
#### Response
```json
{
"result": [
{
"results": {
"attributes": [
{
"name": "name",
"value": "value"
}
],
"height": 0,
"html": "html",
"left": 0,
"text": "text",
"top": 0,
"width": 0
},
"selector": "selector"
}
],
"success": true,
"errors": [
{
"code": 0,
"message": "message"
}
]
}
```
## Domain Types
### Scrape Create Response
- `ScrapeCreateResponse = Array`
- `results: Results`
- `attributes: Array`
- `name: string`
Attribute name.
- `value: string`
Attribute value.
- `height: number`
Element height.
- `html: string`
HTML content.
- `left: number`
Element left.
- `text: string`
Text content.
- `top: number`
Element top.
- `width: number`
Element width.
- `selector: string`
Selector.
# Screenshot
## Get screenshot.
`client.browserRendering.screenshot.create(ScreenshotCreateParamsparams, RequestOptionsoptions?): ScreenshotCreateResponse`
**post** `/accounts/{account_id}/browser-rendering/screenshot`
Takes a screenshot of a webpage from provided URL or HTML. Control page loading with `gotoOptions` and `waitFor*` options. Customize screenshots with `viewport`, `fullPage`, `clip` and others.
### Parameters
- `ScreenshotCreateParams = Variant0 | Variant1`
- `ScreenshotCreateParamsBase`
- `Variant0 extends ScreenshotCreateParamsBase`
- `Variant1 extends ScreenshotCreateParamsBase`
### Returns
- `ScreenshotCreateResponse`
- `success: boolean`
Response status.
- `errors?: Array`
- `code: number`
Error code.
- `message: string`
Error message.
### Example
```node
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});
const screenshot = await client.browserRendering.screenshot.create({
account_id: 'account_id',
html: 'Hello World!
',
});
console.log(screenshot.success);
```
#### Response
```json
{
"success": true,
"errors": [
{
"code": 0,
"message": "message"
}
]
}
```
## Domain Types
### Screenshot Create Response
- `ScreenshotCreateResponse`
- `success: boolean`
Response status.
- `errors?: Array`
- `code: number`
Error code.
- `message: string`
Error message.
# Snapshot
## Get HTML content and screenshot.
`client.browserRendering.snapshot.create(SnapshotCreateParamsparams, RequestOptionsoptions?): SnapshotCreateResponse`
**post** `/accounts/{account_id}/browser-rendering/snapshot`
Returns the page's HTML content and screenshot. Control page loading with `gotoOptions` and `waitFor*` options. Customize screenshots with `viewport`, `fullPage`, `clip` and others.
### Parameters
- `SnapshotCreateParams = Variant0 | Variant1`
- `SnapshotCreateParamsBase`
- `Variant0 extends SnapshotCreateParamsBase`
- `Variant1 extends SnapshotCreateParamsBase`
### Returns
- `SnapshotCreateResponse`
- `content: string`
HTML content.
- `screenshot: string`
Base64 encoded image.
### Example
```node
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});
const snapshot = await client.browserRendering.snapshot.create({
account_id: 'account_id',
html: 'Hello World!
',
});
console.log(snapshot.content);
```
#### Response
```json
{
"meta": {
"status": 0,
"title": "title"
},
"success": true,
"errors": [
{
"code": 0,
"message": "message"
}
],
"result": {
"content": "content",
"screenshot": "screenshot"
}
}
```
## Domain Types
### Snapshot Create Response
- `SnapshotCreateResponse`
- `content: string`
HTML content.
- `screenshot: string`
Base64 encoded image.
# Json
## Get json.
`client.browserRendering.json.create(JsonCreateParamsparams, RequestOptionsoptions?): JsonCreateResponse`
**post** `/accounts/{account_id}/browser-rendering/json`
Gets json from a webpage from a provided URL or HTML. Pass `prompt` or `schema` in the body. Control page loading with `gotoOptions` and `waitFor*` options.
### Parameters
- `JsonCreateParams = Variant0 | Variant1`
- `JsonCreateParamsBase`
- `Variant0 extends JsonCreateParamsBase`
- `Variant1 extends JsonCreateParamsBase`
### Returns
- `JsonCreateResponse = Record`
### Example
```node
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
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',
html: 'Hello World!
',
});
console.log(json);
```
#### Response
```json
{
"result": {
"foo": {}
},
"success": true,
"errors": [
{
"code": 0,
"message": "message"
}
]
}
```
## Domain Types
### Json Create Response
- `JsonCreateResponse = Record`
# Links
## Get Links.
`client.browserRendering.links.create(LinkCreateParamsparams, RequestOptionsoptions?): LinkCreateResponse`
**post** `/accounts/{account_id}/browser-rendering/links`
Get links from a web page.
### Parameters
- `LinkCreateParams = Variant0 | Variant1`
- `LinkCreateParamsBase`
- `Variant0 extends LinkCreateParamsBase`
- `Variant1 extends LinkCreateParamsBase`
### Returns
- `LinkCreateResponse = Array`
### Example
```node
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});
const links = await client.browserRendering.links.create({
account_id: 'account_id',
html: 'Hello World!
',
});
console.log(links);
```
#### Response
```json
{
"result": [
"string"
],
"success": true,
"errors": [
{
"code": 0,
"message": "message"
}
]
}
```
## Domain Types
### Link Create Response
- `LinkCreateResponse = Array`
# Markdown
## Get markdown.
`client.browserRendering.markdown.create(MarkdownCreateParamsparams, RequestOptionsoptions?): MarkdownCreateResponse`
**post** `/accounts/{account_id}/browser-rendering/markdown`
Gets markdown of a webpage from provided URL or HTML. Control page loading with `gotoOptions` and `waitFor*` options.
### Parameters
- `MarkdownCreateParams = Variant0 | Variant1`
- `MarkdownCreateParamsBase`
- `Variant0 extends MarkdownCreateParamsBase`
- `Variant1 extends MarkdownCreateParamsBase`
### Returns
- `MarkdownCreateResponse = string`
Markdown content.
### Example
```node
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});
const markdown = await client.browserRendering.markdown.create({
account_id: 'account_id',
url: 'https://www.example.com/',
});
console.log(markdown);
```
#### Response
```json
{
"success": true,
"errors": [
{
"code": 0,
"message": "message"
}
],
"result": "result"
}
```
## Domain Types
### Markdown Create Response
- `MarkdownCreateResponse = string`
Markdown content.
# Crawl
## Crawl websites.
`client.browserRendering.crawl.create(CrawlCreateParamsparams, RequestOptionsoptions?): CrawlCreateResponse`
**post** `/accounts/{account_id}/browser-rendering/crawl`
Starts a crawl job for the provided URL and its children. Check available options like `gotoOptions` and `waitFor*` to control page load behaviour.
### Parameters
- `CrawlCreateParams = Variant0 | Variant1`
- `CrawlCreateParamsBase`
- `Variant0 extends CrawlCreateParamsBase`
- `Variant1 extends CrawlCreateParamsBase`
### Returns
- `CrawlCreateResponse = string`
Crawl job ID.
### Example
```node
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});
const crawl = await client.browserRendering.crawl.create({
account_id: 'account_id',
url: 'https://example.com',
});
console.log(crawl);
```
#### Response
```json
{
"result": "result",
"success": true,
"errors": [
{
"code": 0,
"message": "message"
}
]
}
```
## Get crawl result.
`client.browserRendering.crawl.get(stringjobId, CrawlGetParamsparams, RequestOptionsoptions?): CrawlGetResponse`
**get** `/accounts/{account_id}/browser-rendering/crawl/{job_id}`
Returns the result of a crawl job.
### Parameters
- `jobId: string`
Crawl job ID.
- `params: CrawlGetParams`
- `account_id: string`
Path param: Account ID.
- `cacheTTL?: number`
Query param: Cache TTL default is 5s. Set to 0 to disable.
- `cursor?: number`
Query param: Cursor for pagination.
- `limit?: number`
Query param: Limit for pagination.
- `status?: "queued" | "errored" | "completed" | 3 more`
Query param: Filter by URL status.
- `"queued"`
- `"errored"`
- `"completed"`
- `"disallowed"`
- `"skipped"`
- `"cancelled"`
### Returns
- `CrawlGetResponse`
- `id: string`
Crawl job ID.
- `browserSecondsUsed: number`
Total seconds spent in browser so far.
- `finished: number`
Total number of URLs that have been crawled so far.
- `records: Array`
List of crawl job records.
- `metadata: Metadata`
- `status: number`
HTTP status code of the crawled page.
- `url: string`
Final URL of the crawled page.
- `title?: string`
Title of the crawled page.
- `status: "queued" | "errored" | "completed" | 3 more`
Current status of the crawled URL.
- `"queued"`
- `"errored"`
- `"completed"`
- `"disallowed"`
- `"skipped"`
- `"cancelled"`
- `url: string`
Crawled URL.
- `html?: string`
HTML content of the crawled URL.
- `json?: Record`
JSON of the content of the crawled URL.
- `markdown?: string`
Markdown of the content of the crawled URL.
- `skipped: number`
Total number of URLs that were skipped due to include/exclude/subdomain filters. Skipped URLs are included in records but are not counted toward total/finished.
- `status: string`
Current crawl job status.
- `total: number`
Total current number of URLs in the crawl job.
- `cursor?: string`
Cursor for pagination.
### Example
```node
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});
const crawl = await client.browserRendering.crawl.get('x', { account_id: 'account_id' });
console.log(crawl.id);
```
#### Response
```json
{
"result": {
"id": "id",
"browserSecondsUsed": 0,
"finished": 0,
"records": [
{
"metadata": {
"status": 0,
"url": "url",
"title": "title"
},
"status": "queued",
"url": "url",
"html": "html",
"json": {
"foo": {}
},
"markdown": "markdown"
}
],
"skipped": 0,
"status": "status",
"total": 0,
"cursor": "cursor"
},
"success": true,
"errors": [
{
"code": 0,
"message": "message"
}
]
}
```
## Cancel a crawl job.
`client.browserRendering.crawl.delete(stringjobId, CrawlDeleteParamsparams, RequestOptionsoptions?): CrawlDeleteResponse`
**delete** `/accounts/{account_id}/browser-rendering/crawl/{job_id}`
Cancels an ongoing crawl job by setting its status to cancelled and stopping all queued URLs.
### Parameters
- `jobId: string`
The ID of the crawl job to cancel.
- `params: CrawlDeleteParams`
- `account_id: string`
Account ID.
### Returns
- `CrawlDeleteResponse`
- `job_id: string`
The ID of the cancelled job.
- `message: string`
Cancellation confirmation message.
### Example
```node
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});
const crawl = await client.browserRendering.crawl.delete('job_id', { account_id: 'account_id' });
console.log(crawl.job_id);
```
#### Response
```json
{
"result": {
"job_id": "job_id",
"message": "message"
},
"success": true,
"errors": [
{
"code": 0,
"message": "message"
}
]
}
```
## Domain Types
### Crawl Create Response
- `CrawlCreateResponse = string`
Crawl job ID.
### Crawl Get Response
- `CrawlGetResponse`
- `id: string`
Crawl job ID.
- `browserSecondsUsed: number`
Total seconds spent in browser so far.
- `finished: number`
Total number of URLs that have been crawled so far.
- `records: Array`
List of crawl job records.
- `metadata: Metadata`
- `status: number`
HTTP status code of the crawled page.
- `url: string`
Final URL of the crawled page.
- `title?: string`
Title of the crawled page.
- `status: "queued" | "errored" | "completed" | 3 more`
Current status of the crawled URL.
- `"queued"`
- `"errored"`
- `"completed"`
- `"disallowed"`
- `"skipped"`
- `"cancelled"`
- `url: string`
Crawled URL.
- `html?: string`
HTML content of the crawled URL.
- `json?: Record`
JSON of the content of the crawled URL.
- `markdown?: string`
Markdown of the content of the crawled URL.
- `skipped: number`
Total number of URLs that were skipped due to include/exclude/subdomain filters. Skipped URLs are included in records but are not counted toward total/finished.
- `status: string`
Current crawl job status.
- `total: number`
Total current number of URLs in the crawl job.
- `cursor?: string`
Cursor for pagination.
### Crawl Delete Response
- `CrawlDeleteResponse`
- `job_id: string`
The ID of the cancelled job.
- `message: string`
Cancellation confirmation message.