API reference
Screenshot
Capture the viewport, the full page or one element of a session's current page.
The image comes back inside the JSON response as base64. To capture a URL without creating a session first, use Stateless screenshot.
Take a screenshot
POST/v1/sessions/{id}/screenshotEvery field is optional: an empty object captures the viewport of the active tab as a JPEG.
Path
- idstringrequired
The session to drive.
Body
- full_pagebooldefaultfalse
Capture the whole page instead of the viewport. The capture stops at 16384 CSS px per side.
- selectorstring
Capture one element, found by CSS selector. At most 16384 CSS px per side, from its top left.
- xpathstring
Capture one element, found by XPath, with the same bound. Use
selectororxpath, not both. - formatjpeg or pngdefaultjpeg
The image format.
- qualityint, 1–100default70
JPEG quality.
jpegonly. - tab_idstringdefaultthe active tab
The tab to capture.
A page or element longer than 16384 CSS px on a side is captured from its top left, up to that size.
Response
- formatstring
jpegorpng. - image_base64string
The image, base64-encoded.
curl -s -X POST \
"$SPHYNX_URL/v1/sessions/$SESSION/screenshot" \
-H "Authorization: Bearer $SPHYNX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"full_page": true, "format": "png"}' \
| jq -r .image_base64 | base64 -d > page.pngimport { writeFile } from "node:fs/promises";
const res = await fetch(`${process.env.SPHYNX_URL}/v1/sessions/${sessionId}/screenshot`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SPHYNX_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ full_page: true, format: "png" }),
});
const { image_base64 } = await res.json();
await writeFile("page.png", Buffer.from(image_base64, "base64"));import base64
import os
import requests
res = requests.post(
f"{os.environ['SPHYNX_URL']}/v1/sessions/{session_id}/screenshot",
headers={"Authorization": f"Bearer {os.environ['SPHYNX_API_KEY']}"},
json={"full_page": True, "format": "png"},
timeout=60,
)
with open("page.png", "wb") as image:
image.write(base64.b64decode(res.json()["image_base64"])){
"format": "png",
"image_base64": "iVBORw0KGgo..."
}{
"selector": "#prices",
"format": "jpeg",
"quality": 85
}Errors
The shape is the same as everywhere else: see Errors.
| HTTP | Code | When |
|---|---|---|
| 400 | invalid_request | Both selector and xpath, bad selector or XPath, unknown field, bad value |
| 401 | unauthorized | Missing or invalid API key |
| 404 | session_not_found | No such session for this key |
| 404 | element_not_found | No element matched selector or xpath |
| 404 | tab_not_found | No such tab |
| 409 | no_page_loaded | The tab is blank |
| 409 | session_in_use | Another drive call has been running on this session for more than 3 s |
| 410 | session_closed | The session has ended |
| 500 | internal | Our fault. Send us the request_id |