Skip to content

capture-screenshot

Pure helpers for screenshot capture: building the CDP device-metrics override payload, decoding a base64-encoded PNG, and reading a PNG’s pixel dimensions out of its IHDR header.

Kept separate from the transports (which are integration-only and excluded from unit tests) so the payload shape and the PNG parsing stay unit-testable — the transports themselves only talk to CDP / Appium.

Interface Description
CaptureScreenshotParams Parameters for capturing a screenshot of a running Obsidian instance.
PngDimensions The pixel dimensions read out of a PNG’s IHDR header.
Function Description
buildDeviceMetricsOverride Builds the Emulation.setDeviceMetricsOverride payload that pins a desktop capture to an exact pixel size. Takes only the size half of CaptureScreenshotParams — routing the capture to a window is the transport’s job, not the payload’s.
decodeBase64Png Decodes the base64 payload both CDP (Page.captureScreenshot) and Appium (takeScreenshot) return into raw PNG bytes.
isPng Decides whether the given bytes are a PNG carrying an IHDR chunk. Used to fail a capture loudly when a transport hands back something that is not an image, rather than writing a corrupt file to disk.
readPngDimensions Reads a PNG’s pixel dimensions from its IHDR header. The whole point is verification: a capture that silently comes back at the wrong size is the failure mode that produces an off-spec screenshot set, so the size is read back from the bytes rather than assumed from the request.