Skip to main content

Function: screenshot()

screenshot(widget, options?): Promise<ScreenshotResult>

Defined in: screenshot.ts:85

Captures a screenshot of a GTK widget as a PNG image.

This function will retry multiple times if the widget hasn't finished rendering, waiting for GTK to complete its paint cycle.

Parameters

ParameterTypeDescription
widgetWidgetThe widget to capture (typically a Window)
options?ScreenshotOptionsOptional timeout and interval configuration

Returns

Promise<ScreenshotResult>

Screenshot result containing base64-encoded PNG data and dimensions

Throws

Error if widget has no size, is not realized, or rendering fails after timeout

Example

import { render, screenshot } from "@gtkx/testing";
import * as Gtk from "@gtkx/ffi/gtk";

const { container } = await render(<MyApp />);
const window = container.getWindows()[0];
const result = await screenshot(window);
console.log(result.mimeType); // "image/png"