API

Interface Screenshot

A captured frame, read back from the canvas swapchain.

data is tightly-packed RGBA8 (4 bytes/pixel), row-major, top row first — the same layout ImageData expects, so it can be handed straight to a 2D canvas:

const shot = await captureScreenshot(surface);
const cv = new OffscreenCanvas(shot.width, shot.height);
cv.getContext("2d")!.putImageData(new ImageData(shot.data, shot.width, shot.height), 0, 0);
const url = await cv.convertToBlob({ type: "image/jpeg", quality: 0.85 });

Alpha is forced to 255 (fully opaque): the swapchain is presented opaque, so its alpha channel is not meaningful for a saved image. Colours are the final, presented 8-bit values (BGRA swizzled to RGBA when the preferred canvas format is BGRA).

interface Screenshot {
    data: Uint8ClampedArray;
    height: number;
    width: number;
}
Index
data: Uint8ClampedArray
height: number
width: number