Open History to see the last commit
1// Isolate native screenshot crashes and stalls in a Node-mode child.
2import type { RegionSnapShotRequest, RegionSnapShotResult } from "./RegionSnapShot.ts";
3
4process.once("disconnect", () => process.exit(0));
5
6async function capture() {
7 const imported = await import("@crowecawcaw/xa11y");
8 const xa11y = (imported as unknown as { readonly default?: typeof imported }).default ?? imported;
9 process.send?.("ready");
10 const request = await new Promise<RegionSnapShotRequest>((resolve) => {
11 process.once("message", resolve);
12 });
13 const shot = await xa11y.screenshot({ region: request.region });
14 const result: RegionSnapShotResult = {
15 type: "result",
16 width: shot.width,
17 height: shot.height,
18 png: shot.toPng().toString("base64"),
19 };
20 process.send?.(result);
21}
22
23void capture().catch((error: unknown) =>
24 process.send?.({
25 type: "error",
26 message: error instanceof Error ? error.message : "Windows window capture failed.",
27 } satisfies RegionSnapShotResult),
28);