Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(preview): bound stalled screenshot captures #25862

Mergedcabamarcos(GitHub profile, opens in a new tab)merged 6 commits intomain fromrefs/pull/25862/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 65 additions and 1 deletion.

x
0 of 2 viewed, 2 left
45 additions and 0 deletionsapps/server/src/preview/ServerBrowserPage.test.tsModified
View file
@@ -19,9 +19,54 @@
} from "vite-plus/test";
​
import * as ServerBrowserPage from "./ServerBrowserPage.ts";
+import { SessionControl } from "./SessionControl.ts";
​
const decodeEvaluateInput = Schema.decodeUnknownSync(PreviewAutomationEvaluateInput);
​
+describe("server browser capture deadlines", () => {
+ it("releases control after an unanswered capture and ignores its late reply", async () => {
+ vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
+ try {
+ const captured = Promise.withResolvers<{ data: string }>();
+ const send = vi.fn(async (method: string) =>
+ method === "Page.captureScreenshot"
+ ? captured.promise
+ : { result: { value: "still responsive" } },
+ );
+ const cdp = { send } as unknown as CDPSession;
+ const control = new SessionControl("agent");
+ let outcome: unknown;
+ const capture = control
+ .agent("agent", () => ServerBrowserPage.captureViewport(cdp, { format: "png" }))
+ .catch((cause: unknown) => {
+ outcome = cause;
+ });
+ const evaluation = control.agent("agent", () =>
+ ServerBrowserPage.evaluate(cdp, { expression: "document.title" }, 1_000),
+ );
+​