The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 22:15 UTC
fix(server): report failed preview navigation URLs (#34580)
Yash Singh committed
Nov 11, 2026 at 16:23 UTC
c58f472a356ed4148fb70a9e8b82e0c6f51d3660
2 files changed
+110
-21
apps/server/src/preview/ServerBrowser.test.ts
+67
-5
@@ -2649,8 +2649,14 @@ it.live("reports why a page failed to load while the tab shows the error page",
2649
page.emit("request", request);
2650
page.emit("requestfailed", request);
2651
page.url = () => "chrome-error://chromewebdata/";
2652
- expect((yield* status()).loadError).toEqual(certificateError);
2653
- expect((yield* snapshot()).loadError).toEqual(certificateError);
2652
+ expect(yield* status()).toMatchObject({
2653
+ url: certificateError.url,
2654
+ loadError: certificateError,
2655
+ });
2656
+ expect(yield* snapshot()).toMatchObject({
2657
+ url: certificateError.url,
2658
+ loadError: certificateError,
2659
+ });
2660
2661
const subframeRequest = {
2662
...request,
@@ -2659,7 +2665,10 @@ it.live("reports why a page failed to load while the tab shows the error page",
2665
};
2666
page.emit("request", subframeRequest);
2667
page.emit("requestfailed", subframeRequest);
2662
- expect((yield* status()).loadError).toEqual(certificateError);
2668
+ expect(yield* status()).toMatchObject({
2669
+ url: certificateError.url,
2670
+ loadError: certificateError,
2671
+ });
2672
2673
// Clearing must happen before the next navigation replaces the error page.
2674
page.emit("request", { ...request, url: () => "https://device.local/login" });
@@ -2670,6 +2679,53 @@ it.live("reports why a page failed to load while the tab shows the error page",
2679
page.emit("request", dataRequest);
2680
page.emit("requestfailed", dataRequest);
2681
expect((yield* status()).loadError?.url).toBe("data:text/html,…");
2682
+ initialNavigation = async () => {
2683
+ page.emit("request", request);
2684
+ page.emit("requestfailed", request);
2685
+ };
2686
+ const error = yield* broker
2687
+ .invoke<PreviewAutomationStatus>({
2688
+ scope,
2689
+ tabId,
2690
+ operation: "navigate",
2691
+ input: { url: certificateError.url },
2692
+ })
2693
+ .pipe(Effect.flip);
2694
+ expect(error).toMatchObject({
2695
+ _tag: "PreviewAutomationExecutionError",
2696
+ reason: `Navigation to ${certificateError.url} failed: ${certificateError.description}`,
2697
+ });
2698
+ }),
2699
+ ).pipe(Effect.provide(layer)),
2700
+);
2701
+
2702
+it.effect("preview_open rejects a desktop navigation that failed before automation attached", () =>
2703
+ Effect.scoped(
2704
+ Effect.gen(function* () {
2705
+ const { broker, tabId } = yield* ready;
2706
+ const manager = yield* Manager.PreviewManager;
2707
+ const channel = yield* DesktopChannel.DesktopBrowserChannel;
2708
+ desktopRendersNext = true;
2709
+ desktopPageUrl = "chrome-error://chromewebdata/";
2710
+ const failure = {
2711
+ ...certificateError,
2712
+ url: "https://user:secret@device.local/?token=private#fragment",
2713
+ };
2714
+ using _failure = vi.spyOn(channel, "loadFailure").mockReturnValue(failure);
2715
+ const error = yield* broker
2716
+ .invoke<PreviewAutomationStatus>({
2717
+ scope,
2718
+ operation: "open",
2719
+ input: { url: failure.url, reuseExistingTab: false, open: false },
2720
+ })
2721
+ .pipe(Effect.flip);
2722
+ expect(error).toMatchObject({
2723
+ _tag: "PreviewAutomationExecutionError",
2724
+ reason: `Navigation to ${certificateError.url} failed: ${certificateError.description}`,
2725
+ });
2726
+ expect(JSON.stringify(error)).not.toMatch(/secret|private|fragment/);
2727
+ const { sessions } = yield* manager.list({ threadId: scope.thread.threadId });
2728
+ expect(sessions.map((session) => session.tabId)).toEqual([tabId]);
2729
}),
2730
).pipe(Effect.provide(layer)),
2731
);
@@ -2701,8 +2757,14 @@ it.live("reports a desktop tab's load failure from before the server connected",
2757
input: {},
2758
tabId: PreviewTabId.make(opened.tabId),
2759
});
2704
- expect((yield* status()).loadError).toEqual(certificateError);
2705
- expect((yield* snapshot()).loadError).toEqual(certificateError);
2760
+ expect(yield* status()).toMatchObject({
2761
+ url: certificateError.url,
2762
+ loadError: certificateError,
2763
+ });
2764
+ expect(yield* snapshot()).toMatchObject({
2765
+ url: certificateError.url,
2766
+ loadError: certificateError,
2767
+ });
2768
desktopLoadFailures.set(opened.tabId, { ...certificateError, url: dataUrl });
2769
expect((yield* status()).loadError?.url).toBe("data:text/html,…");
2770
// A navigation the server sees supersedes it, even before the error page goes.
apps/server/src/preview/ServerBrowser.ts
+43
-16
@@ -1624,6 +1624,27 @@ const make = Effect.gen(function* () {
1624
return reported && { ...reported, url: ServerBrowserPage.withoutDataPayload(reported.url) };
1625
};
1626
1627
+ const assertNavigationSucceeded = (tab: ServerTab) => {
1628
+ const failure = loadErrorOf(tab);
1629
+ if (failure) {
1630
+ const diagnosticUrl = URL.parse(failure.url);
1631
+ if (diagnosticUrl) {
1632
+ diagnosticUrl.username = "";
1633
+ diagnosticUrl.password = "";
1634
+ diagnosticUrl.search = "";
1635
+ diagnosticUrl.hash = "";
1636
+ }
1637
+ const url = diagnosticUrl
1638
+ ? ServerBrowserPage.withoutDataPayload(diagnosticUrl.href)
1639
+ : "the requested page";
1640
+ throw new ServerBrowserPage.ServerBrowserOperationError({
1641
+ tag: "PreviewAutomationExecutionError",
1642
+ message: `Navigation to ${url} failed: ${failure.description}`,
1643
+ detail: { ...failure, url },
1644
+ });
1645
+ }
1646
+ };
1647
+
1648
const statusWithTitle = async (
1649
tab: ServerTab | undefined,
1650
agentSessionId?: string,
@@ -1646,7 +1667,7 @@ const make = Effect.gen(function* () {
1667
available: true,
1668
visible: isVisible(tab),
1669
tabId: tab.tabId,
1649
- url: url === "about:blank" ? null : url,
1670
+ url: loadError?.url ?? (url === "about:blank" ? null : url),
1671
title: null,
1672
loading: tab.loading,
1673
...(loadError ? { loadError } : {}),
@@ -1668,7 +1689,8 @@ const make = Effect.gen(function* () {
1689
url:
1690
candidate.page.url() === "about:blank"
1691
? null
1671
- : ServerBrowserPage.withoutDataPayload(candidate.page.url()),
1692
+ : (loadErrorOf(candidate)?.url ??
1693
+ ServerBrowserPage.withoutDataPayload(candidate.page.url())),
1694
...(candidate.openerTabId === undefined ? {} : { openerTabId: candidate.openerTabId }),
1695
owner: tabOwner(candidate),
1696
ownedByCaller: candidate.control.agentId === agentSessionId,
@@ -1732,6 +1754,7 @@ const make = Effect.gen(function* () {
1754
}
1755
throw ServerBrowserPage.toOperationError(cause, timeout);
1756
});
1757
+ assertNavigationSucceeded(tab);
1758
};
1759
1760
const withCaptureLock = <A>(tab: ServerTab, operation: () => Promise<A>): Promise<A> => {
@@ -2092,15 +2115,24 @@ const make = Effect.gen(function* () {
2115
if (url) await navigate(tab, url, "load", navigationTimeout);
2116
} else {
2117
// A failed open returns no tabId; a leftover hidden tab would block later reuse.
2095
- await tab.initialNavigation?.catch(async (cause: unknown) => {
2096
- // Playwright rejects downloads too; their tab must survive to save the file.
2097
- if (cause instanceof Error && cause.message.includes("Download is starting")) {
2118
+ await Promise.resolve(tab.initialNavigation)
2119
+ .then(async () => {
2120
+ if (url) {
2121
+ await tab.page
2122
+ .waitForLoadState("load", { timeout: navigationTimeout })
2123
+ .catch(constVoid);
2124
+ }
2125
+ assertNavigationSucceeded(tab);
2126
+ })
2127
+ .catch(async (cause: unknown) => {
2128
+ // Playwright rejects downloads too; their tab must survive to save the file.
2129
+ if (cause instanceof Error && cause.message.includes("Download is starting")) {
2130
+ throw cause;
2131
+ }
2132
+ await runPromise(manager.close({ threadId: tab.threadId, tabId: tab.tabId }));
2133
+ dropTab(tab, false);
2134
throw cause;
2099
- }
2100
- await runPromise(manager.close({ threadId: tab.threadId, tabId: tab.tabId }));
2101
- dropTab(tab, false);
2102
- throw cause;
2103
- });
2135
+ });
2136
}
2137
const reveal = open.open ?? open.show;
2138
if (reveal !== false) {
@@ -2112,11 +2144,6 @@ const make = Effect.gen(function* () {
2144
}),
2145
);
2146
}
2115
- if (!existing && url) {
2116
- await tab.page
2117
- .waitForLoadState("load", { timeout: navigationTimeout })
2118
- .catch(constVoid);
2119
- }
2147
return statusWithTitle(tab, request.agentSessionId);
2148
},
2149
deadlineMs,
@@ -2270,7 +2297,7 @@ const make = Effect.gen(function* () {
2297
}),
2298
);
2299
const loadError = loadErrorOf(tab);
2273
- return loadError ? { ...snapshot, loadError } : snapshot;
2300
+ return loadError ? { ...snapshot, url: loadError.url, loadError } : snapshot;
2301
}
2302
case "click": {
2303
const clickInput = input as PreviewAutomationClickInput;