Take a Screenshot
Capture any webpage as a PNG or JPEG using the Browserless screenshot API.
- A Browserless API token from your account dashboard
Steps
- REST API
- Frameworks
- BQL
Use the /screenshot REST endpoint to capture a page as a PNG or JPEG. No WebSocket connection needed.
- cURL
- JavaScript
- Python
- Java
- C#
1. Build the request
Append your token to the screenshot endpoint:
https://production-sfo.browserless.io/screenshot?token=YOUR_API_TOKEN_HERE
2. Send the request
curl -X POST \
"https://production-sfo.browserless.io/screenshot?token=YOUR_API_TOKEN_HERE" \
-H 'Cache-Control: no-cache' \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"options": { "fullPage": true, "type": "png" }
}' \
--output screenshot.png
3. Check the output
The response is a raw PNG binary written to screenshot.png in the current directory.
1. Send the request
import fs from 'fs';
const response = await fetch(
'https://production-sfo.browserless.io/screenshot?token=YOUR_API_TOKEN_HERE',
{
method: 'POST',
headers: {
'Cache-Control': 'no-cache',
'Content-Type': 'application/json',
},
body: JSON.stringify({
url: 'https://example.com',
options: { fullPage: true, type: 'png' },
}),
}
);
const buffer = await response.arrayBuffer();
fs.writeFileSync('screenshot.png', Buffer.from(buffer));
2. Check the output
Run the script with node screenshot.mjs. The file screenshot.png will appear in the current directory.
1. Install dependencies
pip install requests
2. Send the request
import requests
response = requests.post(
'https://production-sfo.browserless.io/screenshot?token=YOUR_API_TOKEN_HERE',
headers={'Cache-Control': 'no-cache', 'Content-Type': 'application/json'},
json={'url': 'https://example.com', 'options': {'fullPage': True, 'type': 'png'}},
)
with open('screenshot.png', 'wb') as f:
f.write(response.content)
3. Check the output
Run the script with python screenshot.py. The file screenshot.png will appear in the current directory.
1. Send the request
import java.io.*;
import java.net.URI;
import java.net.http.*;
String token = "YOUR_API_TOKEN_HERE";
String endpoint = "https://production-sfo.browserless.io/screenshot?token=" + token;
String jsonData = """
{
"url": "https://example.com",
"options": { "fullPage": true, "type": "png" }
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(endpoint))
.header("Cache-Control", "no-cache")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonData))
.build();
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
try (FileOutputStream fos = new FileOutputStream("screenshot.png")) {
response.body().transferTo(fos);
}
System.out.println("Screenshot saved as screenshot.png");
2. Check the output
Run the class. The file screenshot.png will appear in the current directory.
1. Send the request
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
string token = "YOUR_API_TOKEN_HERE";
string endpoint = $"https://production-sfo.browserless.io/screenshot?token={token}";
var payload = new
{
url = "https://example.com",
options = new { fullPage = true, type = "png" },
};
using (HttpClient httpClient = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, endpoint);
request.Headers.Add("Cache-Control", "no-cache");
request.Content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");
var response = await httpClient.SendAsync(request);
var contentStream = await response.Content.ReadAsStreamAsync();
using (var fileStream = new FileStream("screenshot.png", FileMode.Create, FileAccess.Write))
{
await contentStream.CopyToAsync(fileStream);
}
Console.WriteLine("Screenshot saved as screenshot.png");
}
2. Check the output
Run the program. The file screenshot.png will appear in the current directory.
Use a browser connection when you need to interact with the page or wait for dynamic content before capturing.
- Puppeteer
- Playwright
1. Install dependencies
npm install puppeteer-core
2. Connect and capture
import puppeteer from 'puppeteer-core';
const browser = await puppeteer.connect({
browserWSEndpoint: 'wss://production-sfo.browserless.io?token=YOUR_API_TOKEN_HERE',
});
try {
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle2' });
await page.screenshot({ path: 'screenshot.png', fullPage: true });
} finally {
// Always close to release the session even on error.
await browser.close();
}
3. Check the output
Run the script with node screenshot.mjs. The file screenshot.png will appear in the current directory.
1. Install dependencies
npm install playwright-core
2. Connect and capture
import { chromium } from 'playwright-core';
const browser = await chromium.connect(
'wss://production-sfo.browserless.io/chromium/playwright?token=YOUR_API_TOKEN_HERE'
);
try {
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle' });
await page.screenshot({ path: 'screenshot.png', fullPage: true });
} finally {
// Always close to release the session even on error.
await browser.close();
}
3. Check the output
Run the script with node screenshot.mjs. The file screenshot.png will appear in the current directory.
1. Write the mutation
Navigate to the URL and capture a screenshot in one operation:
mutation Screenshot {
goto(url: "https://example.com") {
status
}
screenshot(omitBackground: true) {
base64
}
}
2. Run it
Paste into the BQL IDE and click Run.
3. Check the output
The response includes a base64-encoded PNG. Each example above decodes it and saves it as screenshot.png.
{
"data": {
"goto": { "status": 200 },
"screenshot": { "base64": "iVBORw0KGgoAAAANSUhEUgAA..." }
}
}
Next steps
- Generate a PDF — export the same page as a document
- Scrape Structured Data — extract data instead of capturing images