The best way to control Claude Code, Codex and more from any computer or phone
fix(server): preview tab list shows desktop tabs that loaded before the server attached (#27456)
Co-authored-by: maria-rcks <maria@kuuro.net>
Cameron Chisholm committed
Nov 1, 2026 at 02:38 UTC
fbe137d99e774389d75c63c64bdbed5e582d3975
2 files changed
+34
-3
apps/server/src/preview/ServerBrowser.test.ts
+32
-3
@@ -58,7 +58,7 @@ vi.mock("./ServerBrowserContexts.ts", () => ({
58
return makeEncoderPage() as unknown as Page;
59
}
60
async connectDesktopPage(endpoint: string) {
61
- const context = makeContext();
61
+ const context = makeContext(undefined, desktopPageUrl);
62
context.page.viewportSize.mockReturnValue(null);
63
desktopConnections.push({ endpoint, context });
64
return { browser: { close: async () => {} }, page: context.page as unknown as Page };
@@ -151,12 +151,12 @@ function fileChooserElement(accept: string) {
151
};
152
}
153
154
-function makeContext(onClose?: (context: BrowserContext) => void) {
154
+function makeContext(onClose?: (context: BrowserContext) => void, initialUrl = "about:blank") {
155
const events = new NodeEvents.EventEmitter();
156
const nativeFileChooser = vi.fn();
157
const setChooserFiles = vi.fn(async (_files: unknown) => {});
158
const sessions: ReturnType<typeof makeSession>[] = [];
159
- let url = "about:blank";
159
+ let url = initialUrl;
160
let viewport: ReturnType<Page["viewportSize"]> = { width: 1280, height: 800 };
161
const cssViewport = { width: 1920, height: 1080 };
162
let closed = false;
@@ -299,6 +299,7 @@ let focusedFrame: ReturnType<typeof makeFrame> | null = null;
299
let contextFailure: Error | null = null;
300
let initialNavigation: (() => Promise<void>) | null = null;
301
let desktopRendersNext = false;
302
+let desktopPageUrl = "about:blank";
303
/** Replaces the answer to the desktop page's size reads. */
304
let desktopSizeAnswer: (() => Promise<Record<string, unknown>>) | null = null;
305
const desktopDetaches = new NodeEvents.EventEmitter();
@@ -446,6 +447,7 @@ beforeEach(() => {
447
focusedFrame = null;
448
desktopTabs.clear();
449
desktopRendersNext = false;
450
+ desktopPageUrl = "about:blank";
451
desktopSizeAnswer = null;
452
desktopDetachReady = Promise.withResolvers<void>();
453
desktopReleased = Promise.withResolvers<void>();
@@ -563,6 +565,33 @@ it.effect("a tab the desktop does not draw is marked headless, so the desktop st
565
).pipe(Effect.provide(layer)),
566
);
567
568
+it.effect("a desktop page that loaded before the server attached reports its loaded title", () =>
569
+ Effect.scoped(
570
+ Effect.gen(function* () {
571
+ const { broker } = yield* ready;
572
+ const manager = yield* Manager.PreviewManager;
573
+ const events = yield* manager.subscribeEvents;
574
+ desktopRendersNext = true;
575
+ desktopPageUrl = "https://example.com/loaded";
576
+ const opened = yield* broker.invoke<PreviewAutomationStatus>({
577
+ scope,
578
+ operation: "open",
579
+ input: { url: desktopPageUrl, reuseExistingTab: false, show: false },
580
+ });
581
+ let event = yield* PubSub.take(events);
582
+ while (event.type !== "navigated" || event.tabId !== opened.tabId) {
583
+ event = yield* PubSub.take(events);
584
+ }
585
+
586
+ expect(event.snapshot.navStatus).toEqual({
587
+ _tag: "Success",
588
+ url: "https://example.com/loaded",
589
+ title: "test page",
590
+ });
591
+ }),
592
+ ).pipe(Effect.provide(layer)),
593
+);
594
+
595
it.live.each([
596
{ method: "goto" as const, message: { type: "navigate", url: "http://10.255.255.1/" } },
597
{ method: "goBack" as const, message: { type: "history", delta: -1 } },
apps/server/src/preview/ServerBrowser.ts
+2
@@ -989,6 +989,8 @@ const make = Effect.gen(function* () {
989
page.on("crash", () => dropTab(tab, true));
990
tabs.set(key, tab);
991
reportLiveTabs();
992
+ // A desktop page navigates on its own and can finish loading before these listeners attach.
993
+ if (desktop) void page.waitForLoadState("load").then(() => reportLoaded(tab), constVoid);
994
// Existing desktop and popup PDFs can start loading before interception attaches.
995
if (
996
snapshot.navStatus._tag === "Loading" &&