Skip to main content

/export API

The /export API fetches a URL and streams the result in its native content type (HTML, PDF, image, etc.).

You can check the full Open API schema here.

Quick Start

curl -X POST \
"https://production-sfo.browserless.io/export?token=YOUR_API_TOKEN_HERE" \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/"
}'

Response

The API returns the content in its native format. For HTML pages, you'll receive the HTML content with Content-Type: text/html:

<!DOCTYPE html>
<html>
<head>
<title>Example Domain</title>
...
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples...</p>
</div>
</body>
</html>

For PDFs, images, or other binary content, the API returns the appropriate content type (e.g., application/pdf, image/jpeg) with a Content-Disposition: attachment header.

Additional Examples and Configuration

Parameters

The /export API accepts the following parameters:

Required Parameters

  • url (string) - The URL of the resource to export

Optional Parameters

  • headers (object) - Custom HTTP headers to send with the request
  • gotoOptions (object) - Navigation options (see Request Configuration)
  • waitForEvent (object) - Wait for a specific event before proceeding
  • waitForFunction (object) - Wait for a specific function to return true
  • waitForSelector (object) - Wait for a specific selector to be present
  • waitForTimeout (number) - Time in milliseconds to wait after page load
  • bestAttempt (boolean) - Whether to continue on errors. Default: false
  • includeResources (boolean) - Whether to include all linked resources (images, CSS, JavaScript) in a zip file. Default: false
Configuration Options

For detailed documentation on gotoOptions, waitForEvent, waitForFunction, waitForSelector, waitForTimeout, and bestAttempt parameters, see the Request Configuration page.

Handling Different Content Types

The /export API automatically detects and returns content in its native format. Here's how to handle different response types in your code:

HTML Content

const response = await fetch(url, options);
if (response.headers.get('content-type')?.includes('text/html')) {
const htmlContent = await response.text();
// Process HTML content
}

PDF Content

const response = await fetch(url, options);
if (response.headers.get('content-type')?.includes('application/pdf')) {
const arrayBuffer = await response.arrayBuffer();
const pdfBuffer = Buffer.from(arrayBuffer);
// Save or process PDF buffer
}

Binary Content (Images, etc.)

const response = await fetch(url, options);
const contentType = response.headers.get('content-type');
if (contentType?.includes('image/') || !contentType?.includes('text/')) {
const arrayBuffer = await response.arrayBuffer();
const binaryBuffer = Buffer.from(arrayBuffer);
// Save or process binary buffer
}

Export with Custom Navigation Options

curl -X POST \
"https://production-sfo.browserless.io/export?token=YOUR_API_TOKEN_HERE" \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/",
"gotoOptions": {
"waitUntil": "networkidle0",
"timeout": 60000
},
"waitForSelector": {
"selector": "h1",
"timeout": 5000
}
}'

Export with All Resources (Zip File)

When includeResources is set to true, the API returns a zip file containing the HTML and all linked resources (images, CSS, JavaScript):

curl -X POST \
"https://production-sfo.browserless.io/export?token=YOUR_API_TOKEN_HERE" \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/",
"includeResources": true
}' \
--output "webpage.zip"

Response

The API returns a zip file with Content-Type: application/zip and Content-Disposition: attachment header:

HTTP/1.1 200 OK
Content-Type: application/zip
Content-Disposition: attachment; filename="webpage.zip"

[Binary zip file content containing HTML and all resources]