Screenshots
Captures a web page or an HTML document as an image or a PDF. The parameters follow ScreenshotOne.
GET https://api.sahifa.dev/take?access_key=...&url=https://example.com
POST https://api.sahifa.dev/take (JSON body with the same parameters)
Both methods take the same parameters. GET is convenient for simple captures; use POST with a JSON body for HTML sources and long parameter lists. The response body is the file; X-Response-Duration gives the render time in milliseconds.
Parameters
Source and output
| Name | Type | Default | Description |
|---|---|---|---|
url | string | one of | Public http(s):// address to capture. |
html | string | one of | HTML document to capture. Send exactly one of url and html. |
format | string | png | png, jpeg (or jpg), webp or pdf. |
image_quality | integer | browser default | 1 to 100, for jpeg and webp. |
omit_background | boolean | false | Transparent background where the page has none (png, webp). |
response_type | string | by_format | by_format returns the file; json returns { "success", "content_type", "data" (base64), "size" }. |
Viewport and area
| Name | Type | Default | Description |
|---|---|---|---|
viewport_width | integer | 1280 | Browser width in CSS pixels. |
viewport_height | integer | 720 | Browser height in CSS pixels. |
device_scale_factor | number | 1 | Pixel density, up to 4. 2 gives a sharp image for high-resolution screens, at four times the pixels. |
full_page | boolean | false | Capture the whole scrollable page, not only the viewport. |
selector | string | none | CSS selector of one element to capture. If nothing matches, the answer is 404. Cannot be combined with full_page. |
clip_x, clip_y, clip_width, clip_height | integer | none | Capture a rectangle of the page. Width and height are required. |
Page behaviour
| Name | Type | Default | Description |
|---|---|---|---|
wait_until | string | load | load, domcontentloaded, networkidle or commit. Use networkidle for pages built with JavaScript. |
wait_for_selector | string | none | Wait until an element matching this selector is visible. |
delay | number | 0 | Extra wait after loading, in seconds, up to 30. Note: the PDF endpoint's delay is in milliseconds, as in PDFShift. |
timeout | number | 30 | Maximum render time in seconds, capped at 30. |
dark_mode | boolean | false | Emulate a dark colour scheme (prefers-color-scheme: dark). |
reduced_motion | boolean | false | Emulate prefers-reduced-motion: reduce, which stops many animations. |
user_agent | string | Chromium | Custom user agent. |
authorization | string | none | Value of the Authorization header sent to the page. |
headers | string or list | none | Extra headers as Name=value; repeat the parameter for several. |
cookies | string or list | none | Cookies as name=value; repeat the parameter for several. |
cache | boolean | false | Accepted for compatibility and ignored: every request is rendered fresh and nothing is cached. |
Blocking and hiding
| Name | Type | Default | Description |
|---|---|---|---|
block_cookie_banners | boolean | false | Hide cookie consent pop-ups and restore scrolling. Covers the common consent platforms (OneTrust, Sourcepoint, Didomi, Quantcast, Usercentrics, Cookiebot, TrustArc, consentmanager and others). Adds about one second. |
block_ads | boolean | false | Block ad requests and hide ad slots (EasyList). |
block_trackers | boolean | false | Block tracking and analytics requests (EasyPrivacy). Often makes pages load faster. |
block_chats | boolean | false | Block and hide chat widgets (Intercom, Drift, Crisp, Tidio, Tawk, Zendesk, Freshchat, LiveChat, Olark, HubSpot). |
hide_selectors | string or list | none | CSS selectors to hide, comma-separated or repeated. |
block_requests | string or list | none | URL patterns to block, with * as wildcard, for example *.example.org/track*. |
block_resources | string or list | none | Resource types to block: image, font, media, script, stylesheet, xhr, fetch, websocket, other. |
The filter lists are built into the server, so blocking adds no outside requests.
Not supported
store, storage_*, async and webhook_url are refused with 400, because Sahifa does not store files. block_banners_by_heuristics is also refused; use block_cookie_banners and hide_selectors.
Examples
Whole page, without cookie banners
GET /take?access_key=KEY&url=https://example.com&full_page=true&block_cookie_banners=true
One element, sharp
GET /take?access_key=KEY&url=https://example.com&selector=%23pricing&device_scale_factor=2
HTML to JPEG
POST /take
X-API-Key: KEY
Content-Type: application/json
{ "html": "<h1 dir=\"rtl\">مرحبا</h1>", "format": "jpeg", "image_quality": 85, "viewport_width": 800, "viewport_height": 400 }
Complete programs are in the code examples.