The best way to control Claude Code, Codex and more from any computer or phone
fix(server): html previews say how their browser exited (#16872)
Nikita Koynov committed
Oct 18, 2026 at 22:11 UTC
bd395e9e6530002a4b66b23844abd416aaebb88d
2 files changed
+81
-1
apps/server/src/htmlRender/HtmlRender.test.ts
+58
@@ -54,6 +54,33 @@ const layerTest = layerHtmlRender();
54
55
const PNG_BYTES = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
56
57
+/**
58
+ * A stand-in browser that reads T3's first command off its debugging pipe,
59
+ * then runs `exit`. Reading it first keeps the pipe from resetting.
60
+ */
61
+const exitingBrowser = (exit: string) =>
62
+ Effect.gen(function* () {
63
+ const fileSystem = yield* FileSystem.FileSystem;
64
+ const path = yield* Path.Path;
65
+ const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-exiting-browser-" });
66
+ const executable = path.join(directory, "chrome-headless-shell");
67
+ yield* fileSystem.writeFileString(
68
+ executable,
69
+ [
70
+ `#!${process.execPath}`,
71
+ `new (process.getBuiltinModule("node:net").Socket)({ fd: 3 }).on("data", (chunk) => { if (chunk.includes(0)) { ${exit} } });`,
72
+ ].join("\n"),
73
+ );
74
+ yield* fileSystem.chmod(executable, 0o755);
75
+ return executable;
76
+ });
77
+
78
+const previewError = (executable: string) =>
79
+ Effect.gen(function* () {
80
+ const htmlRender = yield* HtmlRender.HtmlRender;
81
+ return yield* htmlRender.preview({ html: "<p>x</p>" }).pipe(Effect.flip);
82
+ }).pipe(Effect.provide(layerHtmlRender(executable)));
83
+
84
describe("HtmlRender", () => {
85
it.effect("inlines local images by absolute path and leaves URLs and relative paths alone", () =>
86
Effect.gen(function* () {
@@ -227,6 +254,37 @@ describe("HtmlRender", () => {
254
}),
255
);
256
257
+ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")(
258
+ "when the browser exits before rendering",
259
+ () => {
260
+ it.live("reports its exit code and keeps what it printed out of the message", () =>
261
+ Effect.gen(function* () {
262
+ const executable = yield* exitingBrowser(
263
+ `process.stderr.write("[WARNING:bus.cc] Failed to connect to the bus\\n[FATAL:shared_memory.cc] Check failed: /dev/shm is not writable\\n"); process.exit(3);`,
264
+ );
265
+
266
+ const error = yield* previewError(executable);
267
+
268
+ expect(error.message).toBe(
269
+ "Headless Chrome could not render the page: the browser exited unexpectedly (exit code 3).",
270
+ );
271
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
272
+ );
273
+
274
+ it.live("reports the signal that ended it", () =>
275
+ Effect.gen(function* () {
276
+ const executable = yield* exitingBrowser(`process.kill(process.pid, "SIGKILL");`);
277
+
278
+ const error = yield* previewError(executable);
279
+
280
+ expect(error.message).toBe(
281
+ "Headless Chrome could not render the page: the browser exited unexpectedly (signal SIGKILL).",
282
+ );
283
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
284
+ );
285
+ },
286
+ );
287
+
288
it.live(
289
"screenshots the page in headless Chrome with the requested theme and every console level",
290
(ctx) =>
apps/server/src/htmlRender/headlessChrome.ts
+23
-1
@@ -23,10 +23,18 @@ export class HtmlRenderBrowserError extends Schema.TaggedError<HtmlRenderBrowser
23
reason: Schema.String,
24
cause: Schema.optional(Schema.Defect()),
25
output: Schema.optional(Schema.String),
26
+ exitCode: Schema.optional(Schema.Number),
27
+ signal: Schema.optional(Schema.String),
28
},
29
) {
30
override get message(): string {
29
- return `Headless Chrome could not render the page: ${this.reason}.`;
31
+ const exit =
32
+ this.exitCode !== undefined
33
+ ? ` (exit code ${this.exitCode})`
34
+ : this.signal !== undefined
35
+ ? ` (signal ${this.signal})`
36
+ : "";
37
+ return `Headless Chrome could not render the page: ${this.reason}${exit}.`;
38
}
39
}
40
@@ -238,6 +246,9 @@ const Ignored = Schema.Unknown;
246
const Navigation = Schema.Struct({ errorText: Schema.optional(Schema.String) });
247
const Measured = Schema.Struct({ result: Schema.Struct({ value: Schema.Finite }) });
248
249
+// Effect's spawner names the signal that ended a child only in its error message.
250
+const EXIT_SIGNAL = /signal: '(SIG[A-Z0-9]+)'/;
251
+
252
interface PageEvents {
253
readonly mainFrameId: string;
254
body: Uint8Array | undefined;
@@ -406,9 +417,20 @@ const launchBrowser = Effect.fnUntraced(function* (input: {
417
// sandbox, says why on stderr, which may still be draining, so give it a moment.
418
const disconnect = Effect.gen(function* () {
419
yield* Fiber.await(stderrReader).pipe(Effect.timeout("1 second"), Effect.ignore);
420
+ const exit = yield* child.exitCode.pipe(
421
+ Effect.map((code): { exitCode?: number; signal?: string; cause?: unknown } => ({
422
+ exitCode: code,
423
+ })),
424
+ Effect.catch((error) => {
425
+ const signal = EXIT_SIGNAL.exec(String(error.cause))?.[1];
426
+ return Effect.succeed(signal === undefined ? { cause: error } : { signal, cause: error });
427
+ }),
428
+ Effect.timeoutOption("1 second"),
429
+ );
430
const error = new HtmlRenderBrowserError({
431
reason: "the browser exited unexpectedly",
432
output: stderrTail,
433
+ ...Option.getOrElse(exit, () => ({})),
434
});
435
disconnected = error;
436
const waiters = [...pending.values()];