Frequently Asked Question
Headless - Capture a web page as an image
Last Updated 10 months ago
Headless API
Overview
The Headless API provides functionality to capture screenshots, generate PDFs, and retrieve the DOM of web pages using a headless browser. It allows for remote rendering and content extraction from web pages.
Version
1.002
Endpoint
/v2/headless
Authentication
This API requires authentication using an API key. The key should be passed in the X_API_Key header.
Request Parameters
| Parameter | Type | Description |
|---|---|---|
| f | string | Function to perform: 'screenshot', 'pdf', or 'dom' (required) |
| p | string | URL of the web page to process (required) |
| w | string | Window size in format "width,height" (optional, default: "1920,1080") |
Response
The API returns different content types based on the requested function:
| Function | Content-Type | Description |
|---|---|---|
| screenshot | image/png | PNG image of the web page |
| application/pdf | PDF document of the web page | |
| dom | text/html | HTML content of the web page's DOM |
Example Usage
curl "https://api_url/v2/headless.php?f=pdf&p=https://www.gen.uk" -H "X-API-KEY: your_api_key_here" --output downloads/test.pdf
curl "https://api_url/v2/headless.php?f=screenshot&p=https://www.gen.uk" -H "X-API-KEY: your_api_key_here" --output downloads/test.png
Note: Replace 'your_api_key_here' with your actual API key.
Apply
Error Handling
- If an invalid function is specified:
Error; invalid function passed - If there's an authentication error: JSON response with
{"status": "[validation status]"}
Notes
- For PDF generation, you can add custom CSS to the target page to control the layout, e.g., setting page size to A4 landscape.
- Temporary files are created and then deleted after processing.
Security
- Ensure that the API key is kept secure and not exposed in client-side code.
Limitations
- Processing time may vary depending on the complexity and size of the target web page.
- The API may not handle JavaScript-heavy pages or single-page applications perfectly in all cases.
