Skip to content

Commit 7def1ca

Browse files
feat(preview): use a host-provided headless shell from T3CODE_PREVIEW_BROWSER_PATH
Co-authored-by: Kalle Ahlström <[email protected]>
1 parent 1eb4071 commit 7def1ca

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎apps/server/src/preview/PreviewBrowser.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (
7878
readonly body?: Stream.Stream<Uint8Array>;
7979
readonly wait?: Duration.Input;
8080
readonly unsupported?: boolean;
81+
readonly executablePath?: string;
8182
} = {},
8283
) {
8384
const fs = yield* FileSystem.FileSystem;
@@ -100,6 +101,7 @@ const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (
100101
sha256,
101102
},
102103
...(options.wait === undefined ? {} : { wait: options.wait }),
104+
...(options.executablePath === undefined ? {} : { executablePath: options.executablePath }),
103105
}).pipe(
104106
Effect.provideService(HostProcess.Platform, hostPlatform),
105107
Effect.provideService(HostProcess.Architecture, "x64"),
@@ -198,4 +200,15 @@ it.layer(NodeServices.layer)("PreviewBrowser", (it) => {
198200
);
199201
}),
200202
);
203+
204+
it.effect("uses a host-provided browser without downloading one", () =>
205+
Effect.gen(function* () {
206+
const executablePath = "/opt/browser/chrome-headless-shell";
207+
const { browser, requests } = yield* makeHarness({ unsupported: true, executablePath });
208+
209+
expect(yield* browser.executable).toBe(executablePath);
210+
expect(yield* browser.installed).toEqual(Option.some(executablePath));
211+
expect(requests).toEqual([]);
212+
}),
213+
);
201214
});

‎apps/server/src/preview/PreviewBrowser.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export interface PreviewBrowserOptions {
140140
readonly release?: PreviewBrowserRelease | null;
141141
/** How long a caller waits on an install in progress. Provider tool calls time out near 60s. */
142142
readonly wait?: Duration.Input;
143+
/** A headless shell the host provides, such as a distribution package; nothing is downloaded. */
144+
readonly executablePath?: string;
143145
}
144146

145147
const DOWNLOAD_TIMEOUT = "15 minutes";
@@ -160,6 +162,12 @@ type InstallState =
160162
export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
161163
options: PreviewBrowserOptions,
162164
) {
165+
if (options.executablePath !== undefined) {
166+
return PreviewBrowser.of({
167+
executable: Effect.succeed(options.executablePath),
168+
installed: Effect.succeedSome(options.executablePath),
169+
});
170+
}
163171
const fs = yield* FileSystem.FileSystem;
164172
const path = yield* Path.Path;
165173
const http = yield* HttpClient.HttpClient;
@@ -439,6 +447,10 @@ export const layer = Layer.effect(
439447
PreviewBrowser,
440448
Effect.gen(function* () {
441449
const config = yield* ServerConfig.ServerConfig;
442-
return yield* makePreviewBrowser({ baseDir: config.baseDir });
450+
const executablePath = (yield* HostProcess.Environment).T3CODE_PREVIEW_BROWSER_PATH;
451+
return yield* makePreviewBrowser({
452+
baseDir: config.baseDir,
453+
...(executablePath ? { executablePath } : {}),
454+
});
443455
}),
444456
);

‎docs/user/remote-access.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ reports what it would change.
241241
The browser always runs in Chrome's sandbox. Where you cannot change the host,
242242
set `T3CODE_SERVER_BROWSER_SANDBOX=0` for the environment to run without it.
243243

244+
Where `t3 browser setup` cannot install libraries, such as on NixOS, point
245+
`T3CODE_PREVIEW_BROWSER_PATH` at a `chrome-headless-shell` the host provides.
246+
T3 then uses it instead of downloading its own.
247+
244248
## Connect an outside agent
245249

246250
Claude Code, Codex, ChatGPT and other agents T3 Code did not start can drive

0 commit comments

Comments
 (0)