A screenshot is a PNG, base64-encoded in value. Paths follow
http://127.0.0.1:4445/{token}; see the
overview for the reply format and the errors.
Platforms#
The window’s WKWebView takes the snapshot itself
(takeSnapshotWithConfiguration), at the screen’s scale (so 2x on a Retina
display), and the plugin returns it as PNG. WebKit draws the page out of
process, so the snapshot comes from the web view, on the main thread; it has
30 seconds (500 timeout, the web view did not draw a snapshot in time).
Windows (WebView2) and Linux (WebKitGTK) answer 500 unsupported operation
for now. An element screenshot still scrolls the element into view first.
Take screenshot#
GET /session/{sessionId}/screenshot
The whole web view. On a Retina display a 900 x 700 window gave a 1800 x 1400 PNG.
The current session’s id.
The PNG, base64-encoded.
Take element screenshot#
GET /session/{sessionId}/element/{elementId}/screenshot
The part of the view the element covers, after it is scrolled into view: the
page scrolls it to the middle of the view at once, even when the page sets
scroll-behavior: smooth, and cuts its box to the viewports it is in (its
frames’ and the window’s). This also holds when the page is zoomed, as Tauri’s
set_zoom and the zoom hotkeys do: the area is scaled by the web view’s
pageZoom, which only a unit test of that conversion checks. On macOS a real
app took the screenshot of a paragraph far below the view on a page with
scroll-behavior: smooth.
The current session’s id.
The element’s id.
The PNG, base64-encoded.
Errors#
| Status | error | When |
|---|---|---|
| 404 | no such element, stale element reference | The element is unknown or gone. |
| 500 | unsupported operation | Windows and Linux. |
| 500 | unable to capture screen | The element has no area in view; the window holds no WKWebView; WebKit gave no snapshot or the snapshot cannot be encoded. |
| 500 | timeout | WebKit did not draw the snapshot within 30 seconds. |