Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/server/src/preview/ServerBrowser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3047,6 +3047,11 @@ it.effect("a desktop tab reports the size the desktop draws after a resize", ()
expect(
yield* resize({ mode: "freeform", width: 900, height: 600 }, 900, 600),
).toBeUndefined();
// A hidden guest takes the new size only while the desktop paints it, which a capture asks for.
expect(cdp.send).toHaveBeenCalledWith(
"Page.captureScreenshot",
expect.objectContaining({ clip: expect.anything() }),
);
desktopSizeAnswer = null;
expect(yield* resize({ mode: "freeform", width: 1280, height: 760 }, 1280, 760)).toEqual({
width: 1280,
Expand Down
21 changes: 20 additions & 1 deletion apps/server/src/preview/ServerBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ const AGENT_CURSOR_CLICK_LEAD_MS = 40;
const DESKTOP_VIEWPORT_READ_TIMEOUT = "1 second";
/** A desktop page that keeps its size draws nothing on a resize, so the wait gives up. */
const DESKTOP_RESIZE_WAIT_MS = 1000;
/** Answered only once the guest paints a frame; one pixel keeps it cheap. */
const DESKTOP_PAINT_CAPTURE = {
format: "jpeg",
quality: 1,
clip: { x: 0, y: 0, width: 1, height: 1, scale: 1 },
} as const;
// A revealed tab's client opens the panel and attaches its stream a few round trips later, remote ones included.
const REVEAL_VIEWER_WAIT_MS = 1000;
// A desktop panel's shown report waits on the renderer's layout, which a busy machine can push past a second.
Expand Down Expand Up @@ -2827,7 +2833,20 @@ const make = Effect.gen(function* () {
// The desktop draws the new size after the session update; its page resize says it has.
// Half the time left keeps room for the read, which runs even if nothing was drawn,
// because a page can keep another size than the one asked for.
if (changed) await within(drawn, Math.min(DESKTOP_RESIZE_WAIT_MS, remainingMs() / 2));
if (changed) {
// Electron resizes no hidden guest it does not paint; a pending capture makes the desktop paint it.
let waiting = true;
void (async () => {
while (waiting && !tab.closing) {
await tab.cdp.send("Page.captureScreenshot", DESKTOP_PAINT_CAPTURE);
}
})().catch(constVoid);
try {
await within(drawn, Math.min(DESKTOP_RESIZE_WAIT_MS, remainingMs() / 2));
} finally {
waiting = false;
}
}
const changes = tab.desktopViewportChanges;
const measured = await within(measureDesktopViewport(tab), remainingMs());
// Only a read after the draw, with no page resize or load during it, measures this resize.
Expand Down
Loading