The best way to control Claude Code, Codex and more from any computer or phone
fix(browser): Stop cancels loading pages (#29475)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Lakshmi Tanmay committed
Nov 13, 2026 at 22:53 UTC
0f13d638aff77091a0f400727b0ccf56c8319a0a
14 files changed
+266
-14
apps/desktop/src/ipc/channels.ts
+1
@@ -88,6 +88,7 @@ export const PREVIEW_REGISTER_WEBVIEW_CHANNEL = "desktop:preview-register-webvie
88
export const PREVIEW_NAVIGATE_CHANNEL = "desktop:preview-navigate";
89
export const PREVIEW_GO_BACK_CHANNEL = "desktop:preview-go-back";
90
export const PREVIEW_GO_FORWARD_CHANNEL = "desktop:preview-go-forward";
91
+export const PREVIEW_STOP_LOADING_CHANNEL = "desktop:preview-stop-loading";
92
export const PREVIEW_REFRESH_CHANNEL = "desktop:preview-refresh";
93
export const PREVIEW_ZOOM_IN_CHANNEL = "desktop:preview-zoom-in";
94
export const PREVIEW_ZOOM_OUT_CHANNEL = "desktop:preview-zoom-out";
apps/desktop/src/ipc/methods/preview.ts
+6
@@ -168,6 +168,11 @@ const refresh = tabMethod(
168
"desktop.ipc.preview.refresh",
169
(manager, tabId) => manager.refresh(tabId),
170
);
171
+const stopLoading = tabMethod(
172
+ IpcChannels.PREVIEW_STOP_LOADING_CHANNEL,
173
+ "desktop.ipc.preview.stopLoading",
174
+ (manager, tabId) => manager.stopLoading(tabId),
175
+);
176
const zoomIn = tabMethod(
177
IpcChannels.PREVIEW_ZOOM_IN_CHANNEL,
178
"desktop.ipc.preview.zoomIn",
@@ -472,6 +477,7 @@ export const methods = [
477
goBack,
478
goForward,
479
refresh,
480
+ stopLoading,
481
zoomIn,
482
zoomOut,
483
resetZoom,
apps/desktop/src/preload.ts
+1
@@ -389,6 +389,7 @@ contextBridge.exposeInMainWorld("desktopBridge", {
389
goBack: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_GO_BACK_CHANNEL, { tabId }),
390
goForward: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_GO_FORWARD_CHANNEL, { tabId }),
391
refresh: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_REFRESH_CHANNEL, { tabId }),
392
+ stopLoading: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_STOP_LOADING_CHANNEL, { tabId }),
393
zoomIn: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_ZOOM_IN_CHANNEL, { tabId }),
394
zoomOut: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_ZOOM_OUT_CHANNEL, { tabId }),
395
resetZoom: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_RESET_ZOOM_CHANNEL, { tabId }),
apps/desktop/src/preview/GuestInput.test.ts
+24
@@ -44,6 +44,30 @@ describe("preview guest input", () => {
44
expect(guest.sendCommand).not.toHaveBeenCalledWith("Input.insertText", expect.anything());
45
});
46
47
+ it("stops the guest navigation without stopping its embedder", async () => {
48
+ let guestLoading = true;
49
+ let hostLoading = true;
50
+ const guest = {
51
+ stop: () => {
52
+ guestLoading = false;
53
+ },
54
+ };
55
+ const debuggee = {
56
+ sendCommand: async () => {
57
+ hostLoading = false;
58
+ return {};
59
+ },
60
+ };
61
+ await sendPageCommand(
62
+ guest as unknown as Electron.WebContents,
63
+ debuggee as unknown as Electron.Debugger,
64
+ "Page.stopLoading",
65
+ {},
66
+ );
67
+ expect(guestLoading).toBe(false);
68
+ expect(hostLoading).toBe(true);
69
+ });
70
+
71
it.each([
72
{
73
sessionId: undefined,
apps/desktop/src/preview/GuestInput.ts
+4
@@ -185,6 +185,10 @@ export const sendPageCommand = async (
185
else webContents.reload();
186
return {};
187
}
188
+ if (method === "Page.stopLoading") {
189
+ webContents.stop();
190
+ return {};
191
+ }
192
if (!FOCUS_ROUTED_INPUT.has(method) || webContents.focusedFrame) {
193
return debuggee.sendCommand(method, params);
194
}
apps/desktop/src/preview/Manager.ts
+4
@@ -2148,6 +2148,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
2148
if (wc.navigationHistory.canGoForward()) wc.navigationHistory.goForward();
2149
});
2150
const refresh = (tabId: string) => withWebContents("refresh", tabId, (wc) => wc.reload());
2151
+ const stopLoading = (tabId: string) => withWebContents("stopLoading", tabId, (wc) => wc.stop());
2152
const hardReload = (tabId: string) =>
2153
withWebContents("hardReload", tabId, (wc) => wc.reloadIgnoringCache());
2154
const findInPage = (
@@ -3531,6 +3532,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
3532
prepareWebview,
3533
reapplyZoom,
3534
refresh,
3535
+ stopLoading,
3536
registerWebview,
3537
resetZoom: (tabId: string) => applyZoom(tabId, () => DEFAULT_ZOOM_FACTOR),
3538
setZoomFactor: (tabId: string, zoomFactor: number) =>
@@ -3732,6 +3734,7 @@ export class PreviewManager extends Context.Service<
3734
readonly goBack: (tabId: string) => Effect.Effect<void, PreviewManagerError>;
3735
readonly goForward: (tabId: string) => Effect.Effect<void, PreviewManagerError>;
3736
readonly refresh: (tabId: string) => Effect.Effect<void, PreviewManagerError>;
3737
+ readonly stopLoading: (tabId: string) => Effect.Effect<void, PreviewManagerError>;
3738
readonly zoomIn: (tabId: string) => Effect.Effect<void, PreviewManagerError>;
3739
readonly zoomOut: (tabId: string) => Effect.Effect<void, PreviewManagerError>;
3740
readonly resetZoom: (tabId: string) => Effect.Effect<void, PreviewManagerError>;
@@ -3906,6 +3909,7 @@ export const make = Effect.gen(function* PreviewManagerMake() {
3909
goBack: operations.goBack,
3910
goForward: operations.goForward,
3911
refresh: operations.refresh,
3912
+ stopLoading: operations.stopLoading,
3913
zoomIn: operations.zoomIn,
3914
zoomOut: operations.zoomOut,
3915
resetZoom: operations.resetZoom,
apps/server/src/preview/ServerBrowser.test.ts
+164
-11
@@ -213,11 +213,11 @@ function makeContext(onClose?: (context: BrowserContext) => void, initialUrl = "
213
viewport = size;
214
}),
215
goto: vi.fn(async (next: string, _options?: { timeout?: number; waitUntil?: string }) => {
216
- url = next;
217
- events.emit("load");
216
const pending = initialNavigation;
217
initialNavigation = null;
218
await pending?.();
219
+ url = next;
220
+ events.emit("load");
221
}),
222
goBack: vi.fn(async () => {}),
223
goForward: vi.fn(async () => {}),
@@ -998,15 +998,117 @@ it.effect("a desktop page that loaded before the server attached reports its loa
998
).pipe(Effect.provide(layer)),
999
);
1000
1001
+it.effect.each(["none", "during", "after-fragment", "same-url"])(
1002
+ "Stop settles an initial navigation with its request event $0",
1003
+ (requestTiming) =>
1004
+ Effect.scoped(
1005
+ Effect.gen(function* () {
1006
+ const { browser, broker } = yield* ready;
1007
+ const manager = yield* Manager.PreviewManager;
1008
+ const events = yield* manager.subscribeEvents;
1009
+ const started = Promise.withResolvers<void>();
1010
+ const committed = Promise.withResolvers<void>();
1011
+ initialNavigation = () => {
1012
+ started.resolve();
1013
+ return committed.promise;
1014
+ };
1015
+ yield* Effect.addFinalizer(() => Effect.sync(() => committed.resolve()));
1016
+ const { tabId } = yield* manager.open({
1017
+ threadId: scope.thread.threadId,
1018
+ runtime: "server",
1019
+ url:
1020
+ requestTiming === "after-fragment"
1021
+ ? "https://example.com/pending#section"
1022
+ : "https://example.com/pending",
1023
+ });
1024
+ const viewer = yield* browser.attachViewer(viewerInput(tabId, true));
1025
+ yield* Effect.promise(() => started.promise);
1026
+ const page = contexts.at(-1)!.page;
1027
+ const request = {
1028
+ url: () => "https://example.com/pending",
1029
+ method: () => "GET",
1030
+ isNavigationRequest: () => true,
1031
+ frame: () => page,
1032
+ failure: () => ({ errorText: "net::ERR_ABORTED" }),
1033
+ };
1034
+ const cdp = contexts.at(-1)!.sessions.at(-1)!;
1035
+ const send = cdp.send.getMockImplementation()!;
1036
+ cdp.send.mockImplementation(async (operation, input) => {
1037
+ if (operation === "Page.stopLoading") {
1038
+ committed.reject(new Error("net::ERR_ABORTED"));
1039
+ if (requestTiming === "during") page.emit("request", request);
1040
+ }
1041
+ return send(operation, input);
1042
+ });
1043
+ yield* viewer.input({ type: "stopLoading" });
1044
+ const stopped = yield* broker.invoke<PreviewAutomationStatus>({
1045
+ scope,
1046
+ tabId,
1047
+ operation: "status",
1048
+ input: {},
1049
+ });
1050
+ expect(stopped.loading).toBe(false);
1051
+ let settled = yield* PubSub.take(events);
1052
+ while (
1053
+ settled.type !== "navigated" ||
1054
+ settled.tabId !== tabId ||
1055
+ settled.snapshot.navStatus._tag !== "Idle"
1056
+ ) {
1057
+ settled = yield* PubSub.take(events);
1058
+ }
1059
+ const corrected = requestTiming === "same-url";
1060
+ using timeout = vi.spyOn(globalThis, "setTimeout");
1061
+ if (corrected) {
1062
+ page.goto.mockImplementationOnce(async () => {
1063
+ page.emit("request", request);
1064
+ });
1065
+ yield* viewer.input({ type: "navigate", url: request.url() });
1066
+ } else if (requestTiming !== "none") {
1067
+ if (requestTiming === "after-fragment") page.emit("request", request);
1068
+ page.emit("requestfailed", request);
1069
+ }
1070
+ const status = yield* broker.invoke<PreviewAutomationStatus>({
1071
+ scope,
1072
+ tabId,
1073
+ operation: "status",
1074
+ input: {},
1075
+ });
1076
+ expect(status.loading).toBe(corrected);
1077
+ expect(timeout).not.toHaveBeenCalledWith(expect.any(Function), 5_000);
1078
+ if (!corrected) {
1079
+ const { sessions } = yield* manager.list({ threadId: scope.thread.threadId });
1080
+ expect(sessions.find((session) => session.tabId === tabId)?.navStatus).toEqual({
1081
+ _tag: "Idle",
1082
+ });
1083
+ }
1084
+ }),
1085
+ ).pipe(Effect.provide(layer)),
1086
+);
1087
+
1088
it.effect.each([
1002
- { method: "goto" as const, message: { type: "navigate", url: "http://10.255.255.1/" } },
1003
- { method: "goBack" as const, message: { type: "history", delta: -1 } },
1004
- { method: "goForward" as const, message: { type: "history", delta: 1 } },
1005
- { method: "reload" as const, message: { type: "reload" } },
1006
-])("a pending viewer $method allows a corrected URL and text input", ({ method, message }) =>
1089
+ {
1090
+ method: "goto" as const,
1091
+ message: { type: "navigate", url: "http://10.255.255.1/" },
1092
+ abortEvent: "before",
1093
+ },
1094
+ { method: "goBack" as const, message: { type: "history", delta: -1 }, abortEvent: "before" },
1095
+ { method: "goForward" as const, message: { type: "history", delta: 1 }, abortEvent: "before" },
1096
+ { method: "reload" as const, message: { type: "reload" }, abortEvent: "after" },
1097
+ { method: "reload" as const, message: { type: "reload" }, abortEvent: "none" },
1098
+ ...["before", "after", "none"].map((abortEvent) => ({
1099
+ method: "goto" as const,
1100
+ message: { type: "navigate", url: "http://10.255.255.1/" },
1101
+ abortEvent,
1102
+ blank: true,
1103
+ })),
1104
+])("viewer $method Stop settles ($abortEvent, blank=$blank)", (testCase) =>
1105
Effect.scoped(
1106
Effect.gen(function* () {
1009
- const { browser, tabId } = yield* ready;
1107
+ const { method, message, abortEvent } = testCase;
1108
+ const blank = "blank" in testCase;
1109
+ const { browser, broker, tabId } = yield* ready;
1110
+ const manager = yield* Manager.PreviewManager;
1111
+ const events = yield* manager.subscribeEvents;
1112
const viewer = yield* browser.attachViewer(viewerInput(tabId, true));
1113
yield* viewer.input({ type: "takeControl" });
1114
const started = Promise.withResolvers<void>();
@@ -1020,26 +1122,77 @@ it.effect.each([
1122
yield* Effect.promise(() => started.promise);
1123
const cdp = contexts[0]!.sessions.at(-1)!;
1124
const send = cdp.send.getMockImplementation()!;
1125
+ const request = {
1126
+ url: () => "https://example.com/pending",
1127
+ method: () => "GET",
1128
+ isNavigationRequest: () => true,
1129
+ frame: () => page,
1130
+ failure: () => ({ errorText: "net::ERR_ABORTED" }),
1131
+ };
1132
const typed = Promise.withResolvers<void>();
1133
+ let cancelled = false;
1134
cdp.send.mockImplementation(async (operation, input) => {
1135
if (operation === "Input.insertText") typed.resolve();
1136
+ if (operation === "Page.stopLoading") {
1137
+ cancelled = true;
1138
+ committed.reject(new Error("net::ERR_ABORTED"));
1139
+ if (abortEvent === "before") page.emit("requestfailed", request);
1140
+ }
1141
return send(operation, input);
1142
});
1143
const correction = yield* Effect.gen(function* () {
1029
- yield* viewer.input({ type: "navigate", url: "http://localhost:5173/fixed" });
1144
+ if (!blank) yield* viewer.input({ type: "navigate", url: "http://localhost:5173/fixed" });
1145
yield* viewer.input({ type: "text", text: "hello" });
1146
}).pipe(Effect.forkScoped);
1147
yield* Effect.addFinalizer(() => Effect.sync(() => committed.resolve()));
1148
// The text reaches the page while the first navigation is still uncommitted.
1149
yield* Effect.promise(() => typed.promise);
1150
expect(page.goto).toHaveBeenLastCalledWith(
1036
- "http://localhost:5173/fixed",
1151
+ blank ? "http://10.255.255.1/" : "http://localhost:5173/fixed",
1152
expect.objectContaining({ waitUntil: "commit" }),
1153
);
1154
expect(contexts[0]!.sessions.at(-1)!.send).toHaveBeenCalledWith("Input.insertText", {
1155
text: "hello",
1156
});
1042
- committed.resolve();
1157
+ page.emit("request", request);
1158
+ let loadingEvent = yield* PubSub.take(events);
1159
+ while (
1160
+ loadingEvent.type !== "navigated" ||
1161
+ loadingEvent.snapshot.navStatus._tag !== "Loading"
1162
+ ) {
1163
+ loadingEvent = yield* PubSub.take(events);
1164
+ }
1165
+ const reader = yield* browser.attachViewer(viewerInput(tabId, false));
1166
+ yield* reader.input({ type: "stopLoading" });
1167
+ expect(cancelled).toBe(false);
1168
+ if (abortEvent === "none" && !blank) committed.resolve();
1169
+ yield* viewer.input({ type: "stopLoading" });
1170
+ expect(cancelled).toBe(true);
1171
+ using timeout = vi.spyOn(globalThis, "setTimeout");
1172
+ if (abortEvent === "after") page.emit("requestfailed", request);
1173
+ expect(timeout).not.toHaveBeenCalledWith(expect.any(Function), 5_000);
1174
+ const status = yield* broker.invoke<PreviewAutomationStatus>({
1175
+ scope,
1176
+ tabId,
1177
+ operation: "status",
1178
+ input: {},
1179
+ });
1180
+ expect(status.loading).toBe(false);
1181
+ const expectedStatus = blank ? "Idle" : "Success";
1182
+ let settled = yield* PubSub.take(events);
1183
+ while (settled.type !== "navigated" || settled.snapshot.navStatus._tag !== expectedStatus) {
1184
+ settled = yield* PubSub.take(events);
1185
+ }
1186
+ if (blank) {
1187
+ const { sessions } = yield* manager.list({ threadId: scope.thread.threadId });
1188
+ expect(sessions.find((session) => session.tabId === tabId)?.navStatus).toEqual({
1189
+ _tag: "Idle",
1190
+ });
1191
+ }
1192
+ if (settled.snapshot.navStatus._tag === "Success")
1193
+ expect(settled.snapshot.navStatus.url).toBe("http://localhost:5173/fixed");
1194
+ expect(page[method]).toHaveBeenCalledTimes(method === "goto" && !blank ? 2 : 1);
1195
+ yield* viewer.input({ type: "releaseControl" });
1196
yield* Fiber.join(navigation);
1197
yield* Fiber.join(correction);
1198
}),
apps/server/src/preview/ServerBrowser.ts
+47
-1
@@ -380,7 +380,9 @@ interface ServerTab {
380
closing: boolean;
381
recording: Recording | null;
382
initialNavigation: Promise<void> | null;
383
+ pendingInitialRequestUrl: string | null;
384
navigationGeneration: number;
385
+ stoppedGeneration: number | null;
386
387
abortedNavigation: {
388
readonly url: string;
@@ -1011,7 +1013,9 @@ const make = Effect.gen(function* () {
1013
recording: null,
1014
recordingStart: null,
1015
initialNavigation: null,
1016
+ pendingInitialRequestUrl: null,
1017
navigationGeneration: 0,
1018
+ stoppedGeneration: null,
1019
abortedNavigation: null,
1020
captureLock: Promise.resolve(),
1021
capturing: 0,
@@ -1047,10 +1051,20 @@ const make = Effect.gen(function* () {
1051
const navigationGenerations = new WeakMap<object, number>();
1052
page.on("request", (request) => {
1053
if (!isMainNavigation(request)) return;
1054
+ // Playwright can deliver the first request after Stop has already settled its navigation.
1055
+ const stoppedInitialRequest =
1056
+ request.url() === tab.pendingInitialRequestUrl &&
1057
+ tab.stoppedGeneration === tab.navigationGeneration;
1058
+ tab.pendingInitialRequestUrl = null;
1059
navigationGenerations.set(request, ++tab.navigationGeneration);
1060
clearAbortedNavigation(tab);
1061
tab.loading = true;
1062
tab.loadError = undefined;
1063
+ if (stoppedInitialRequest) {
1064
+ tab.stoppedGeneration = tab.navigationGeneration;
1065
+ settleStoppedNavigation(tab, tab.navigationGeneration);
1066
+ return;
1067
+ }
1068
report(tab, {
1069
_tag: "Loading",
1070
url: ServerBrowserPage.withoutDataPayload(request.url()).slice(0, 2048),
@@ -1058,6 +1072,7 @@ const make = Effect.gen(function* () {
1072
});
1073
});
1074
page.on("load", () => {
1075
+ tab.pendingInitialRequestUrl = null;
1076
tab.loading = false;
1077
void reportLoaded(tab);
1078
});
@@ -1090,6 +1105,10 @@ const make = Effect.gen(function* () {
1105
if (generation !== tab.navigationGeneration) return;
1106
// An aborted navigation is usually a download; its `download` event settles the status.
1107
if (errorText.includes("ERR_ABORTED")) {
1108
+ if (tab.stoppedGeneration === generation) {
1109
+ settleStoppedNavigation(tab, generation);
1110
+ return;
1111
+ }
1112
const url = request.url();
1113
const navigationGeneration = tab.navigationGeneration;
1114
clearAbortedNavigation(tab);
@@ -1156,6 +1175,10 @@ const make = Effect.gen(function* () {
1175
snapshot.navStatus._tag === "Loading" &&
1176
((!adopted && !desktop) || isPdfAssetUrl(snapshot.navStatus.url))
1177
) {
1178
+ tab.loading = true;
1179
+ const initialUrl = URL.parse(snapshot.navStatus.url);
1180
+ if (initialUrl) initialUrl.hash = "";
1181
+ tab.pendingInitialRequestUrl = initialUrl?.href ?? null;
1182
const options = { waitUntil: "commit", timeout: NAVIGATION_TIMEOUT_MS } as const;
1183
tab.initialNavigation = (
1184
(desktop || adopted) && page.url() === snapshot.navStatus.url
@@ -1193,6 +1216,14 @@ const make = Effect.gen(function* () {
1216
tab.abortedNavigation = null;
1217
};
1218
1219
+ const settleStoppedNavigation = (tab: ServerTab, generation: number) => {
1220
+ if (tab.navigationGeneration !== generation || !tab.loading) return;
1221
+ clearAbortedNavigation(tab);
1222
+ tab.loading = false;
1223
+ if (tab.page.url() === "about:blank") report(tab, { _tag: "Idle" });
1224
+ else void reportLoaded(tab);
1225
+ };
1226
+
1227
const settleAbortedNavigation = (
1228
tab: ServerTab,
1229
generation: number,
@@ -1923,6 +1954,7 @@ const make = Effect.gen(function* () {
1954
readiness: "load" | "domContentLoaded" | "none",
1955
timeout: number,
1956
) => {
1957
+ tab.pendingInitialRequestUrl = null;
1958
const startedAt = performance.now();
1959
const navigation = tab.page.goto(url, { timeout, waitUntil: "commit" });
1960
if (readiness === "none") {
@@ -2705,7 +2737,10 @@ const make = Effect.gen(function* () {
2737
const request = event.request;
2738
if (request?.clear === "cookies") await tab.cdp.send("Network.clearBrowserCookies");
2739
if (request?.clear === "cache") await tab.cdp.send("Network.clearBrowserCache");
2708
- if (request?.hardReload) await tab.cdp.send("Page.reload", { ignoreCache: true });
2740
+ if (request?.hardReload) {
2741
+ tab.pendingInitialRequestUrl = null;
2742
+ await tab.cdp.send("Page.reload", { ignoreCache: true });
2743
+ }
2744
})
2745
.catch((cause: unknown) =>
2746
runFork(Effect.logWarning("server preview could not apply a tab setting", { cause })),
@@ -2847,17 +2882,28 @@ const make = Effect.gen(function* () {
2882
case "navigate":
2883
if (typeof message.url === "string") {
2884
const url = normalizePreviewUrl(message.url);
2885
+ tab.pendingInitialRequestUrl = null;
2886
tab.control.trackUntilHandoff(tab.page.goto(url, VIEWER_NAVIGATION_OPTIONS));
2887
}
2888
return;
2889
case "history":
2890
+ tab.pendingInitialRequestUrl = null;
2891
tab.control.trackUntilHandoff(
2892
num(message.delta) < 0
2893
? tab.page.goBack(VIEWER_NAVIGATION_OPTIONS)
2894
: tab.page.goForward(VIEWER_NAVIGATION_OPTIONS),
2895
);
2896
return;
2897
+ case "stopLoading": {
2898
+ const generation = tab.navigationGeneration;
2899
+ tab.stoppedGeneration = generation;
2900
+ await session.send("Page.stopLoading");
2901
+ // Stopping a committed document need not emit Playwright's load or requestfailed events.
2902
+ settleStoppedNavigation(tab, generation);
2903
+ return;
2904
+ }
2905
case "reload":
2906
+ tab.pendingInitialRequestUrl = null;
2907
if (message.ignoreCache === true) {
2908
await session.send("Page.reload", { ignoreCache: true });
2909
return;
apps/server/src/preview/ServerBrowserStream.test.ts
+1
@@ -57,6 +57,7 @@ const mutations = [
57
{ type: "navigate", url: "https://example.com" },
58
{ type: "history", delta: -1 },
59
{ type: "reload" },
60
+ { type: "stopLoading" },
61
{ type: "probe", x: 10, y: 10 },
62
{ type: "takeControl" },
63
{ type: "releaseControl" },
apps/web/src/browser/ServerBrowserSurface.tsx
+2
@@ -46,6 +46,7 @@ export interface ServerBrowserHandle {
46
readonly navigate: (url: string) => void;
47
readonly history: (delta: -1 | 1) => void;
48
readonly reload: (options?: { readonly ignoreCache?: boolean }) => void;
49
+ readonly stopLoading: () => void;
50
readonly viewport: (setting: PreviewViewportSetting) => void;
51
readonly canvas: () => HTMLCanvasElement | null;
52
}
@@ -311,6 +312,7 @@ export function ServerBrowserSurface(props: {
312
history: (delta) => send({ type: "history", delta }),
313
reload: (options) =>
314
send({ type: "reload", ...(options?.ignoreCache ? { ignoreCache: true } : {}) }),
315
+ stopLoading: () => send({ type: "stopLoading" }),
316
viewport: (setting) => send({ type: "viewport", setting }),
317
canvas: () => (!pdfUrl && hasFrameRef.current ? canvasRef.current : null),
318
}),
apps/web/src/components/preview/PreviewChromeRow.tsx
+4
-2
@@ -32,6 +32,7 @@ interface Props {
32
onBack: () => void;
33
onForward: () => void;
34
onRefresh: () => void;
35
+ onStopLoading: () => void;
36
onSubmit: (url: string) => void;
37
onOpenInBrowser?: (() => void) | undefined;
38
onCapture?: ((record: boolean) => void) | undefined;
@@ -61,6 +62,7 @@ export function PreviewChromeRow({
62
onBack,
63
onForward,
64
onRefresh,
65
+ onStopLoading,
66
onSubmit,
67
onOpenInBrowser,
68
onCapture,
@@ -135,7 +137,7 @@ export function PreviewChromeRow({
137
<Button
138
variant="ghost"
139
size="icon-xs"
138
- onClick={refreshDisabled ? NOOP : onRefresh}
140
+ onClick={refreshDisabled ? NOOP : loading ? onStopLoading : onRefresh}
141
disabled={refreshDisabled}
142
aria-label={loading ? "Stop" : "Refresh"}
143
type="button"
@@ -144,7 +146,7 @@ export function PreviewChromeRow({
146
>
147
<RefreshIcon refreshing={loading} />
148
</TooltipTrigger>
147
- <TooltipPopup>{loading ? "Loading…" : "Refresh"}</TooltipPopup>
149
+ <TooltipPopup>{loading ? "Stop" : "Refresh"}</TooltipPopup>
150
</Tooltip>
151
</div>
152
apps/web/src/components/preview/PreviewView.tsx
+6
@@ -334,6 +334,11 @@ export function PreviewView({
334
else if (previewBridge && runtimeTabId) void previewBridge.refresh(runtimeTabId);
335
};
336
337
+ const handleStopLoading = () => {
338
+ if (isServerTab) serverSurfaceRef.current?.stopLoading();
339
+ else if (previewBridge && runtimeTabId) void previewBridge.stopLoading(runtimeTabId);
340
+ };
341
+
342
const adjustServerTab = async (change: Omit<PreviewAdjustInput, "threadId" | "tabId">) => {
343
if (!tabId) return;
344
const result = await adjust({
@@ -984,6 +989,7 @@ export function PreviewView({
989
onBack={handleBack}
990
onForward={handleForward}
991
onRefresh={handleRefresh}
992
+ onStopLoading={handleStopLoading}
993
onSubmit={(next) => void handleSubmitUrl(next)}
994
onOpenInBrowser={tabId ? handleOpenInBrowser : undefined}
995
onCapture={previewBridge && tabId && !isServerTab ? handleCapture : undefined}
packages/client-runtime/src/preview/serverBrowserStream.ts
+1
@@ -90,6 +90,7 @@ export type PreviewStreamInput =
90
| { readonly type: "navigate"; readonly url: string }
91
| { readonly type: "history"; readonly delta: -1 | 1 }
92
| { readonly type: "reload"; readonly ignoreCache?: boolean }
93
+ | { readonly type: "stopLoading" }
94
| { readonly type: "probe"; readonly x: number; readonly y: number };
95
96
export interface PreviewStreamDownload {
packages/contracts/src/ipc.ts
+1
@@ -1263,6 +1263,7 @@ export interface DesktopPreviewBridge {
1263
goBack: (tabId: string) => Promise<void>;
1264
goForward: (tabId: string) => Promise<void>;
1265
refresh: (tabId: string) => Promise<void>;
1266
+ stopLoading: (tabId: string) => Promise<void>;
1267
zoomIn: (tabId: string) => Promise<void>;
1268
zoomOut: (tabId: string) => Promise<void>;
1269
resetZoom: (tabId: string) => Promise<void>;