Skip to content

Commit 611afa8

Browse files
Vantrongsclaude
andcommitted
fix(preview): server recordings capture the tab instead of re-encoding the JPEG screencast
Server-browser recordings of tabs in a persistent profile now record the tab Chrome composites, through a small recorder extension's tabCapture, into the existing encoder page. The JPEG screencast stays for incognito and isolated tabs, where extensions do not run, and for desktop tabs. Tab capture needs full Chrome, so T3 now downloads Chrome for Testing's `chrome` instead of chrome-headless-shell (about 200 MB instead of 120 MB), unpacks the macOS bundle's links, sets up hosts for its four extra libraries, and renames the AppArmor profile so setup installs one for the new path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9826dbb commit 611afa8

12 files changed

Lines changed: 518 additions & 99 deletions

‎apps/server/src/cli/browser.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Command } from "effect/cli";
99
import * as ChildProcess from "effect/process/ChildProcess";
1010
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1111

12+
import * as PreviewBrowser from "../preview/PreviewBrowser.ts";
1213
import * as PreviewBrowserHost from "../preview/PreviewBrowserHost.ts";
1314
import { resolveBaseDir } from "../os-jank.ts";
1415
import { baseDirFlag } from "./config.ts";
@@ -67,12 +68,12 @@ const aptOffers = Effect.fn("browserSetup.aptOffers")(function* (name: string) {
6768
const installedBrowser = Effect.fn("browserSetup.installedBrowser")(function* (baseDir: string) {
6869
const fs = yield* FileSystem.FileSystem;
6970
const path = yield* Path.Path;
70-
const root = path.join(baseDir, "tools", "chrome-headless-shell");
71+
const root = path.join(baseDir, "tools", "chrome-for-testing");
7172
for (const platform of yield* fs.readDirectory(root).pipe(Effect.orElseSucceed(() => []))) {
7273
for (const version of yield* fs
7374
.readDirectory(path.join(root, platform))
7475
.pipe(Effect.orElseSucceed(() => []))) {
75-
const executable = path.join(root, platform, version, "chrome-headless-shell");
76+
const executable = path.join(root, platform, version, PreviewBrowser.executableName("linux"));
7677
if (yield* fs.exists(executable).pipe(Effect.orElseSucceed(() => false))) {
7778
return Option.some(executable);
7879
}

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

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ import * as PreviewBrowser from "./PreviewBrowser.ts";
1818
// NTFS cannot enforce POSIX modes; choose the host platform.
1919
const hostPlatform: NodeJS.Platform =
2020
HostProcess.Platform.defaultValue() === "win32" ? "win32" : "linux";
21-
const executableName =
22-
hostPlatform === "win32" ? "chrome-headless-shell.exe" : "chrome-headless-shell";
23-
const ROOT = "chrome-headless-shell-fixture/";
21+
const executableName = PreviewBrowser.executableName(hostPlatform);
22+
const ROOT = "chrome-fixture/";
2423

2524
const makeZip = (
2625
entries: ReadonlyArray<{ readonly name: string; readonly data?: string; readonly mode: number }>,
@@ -95,7 +94,7 @@ const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (
9594
: {
9695
version: "1.2.3",
9796
platform: "fixture",
98-
url: "https://storage.googleapis.com/chrome-headless-shell-fixture.zip",
97+
url: "https://storage.googleapis.com/chrome-fixture.zip",
9998
bytes: archive.byteLength,
10099
sha256,
101100
},
@@ -116,14 +115,16 @@ const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (
116115
),
117116
),
118117
);
119-
const installRoot = path.join(baseDir, "tools", "chrome-headless-shell", "fixture");
118+
const installRoot = path.join(baseDir, "tools", "chrome-for-testing", "fixture");
120119
return { browser, fs, path, baseDir, installRoot, requests };
121120
});
122121

123122
it.layer(NodeServices.layer)("PreviewBrowser", (it) => {
124123
it.effect("installs a verified download with its file modes and then reuses it", () =>
125124
Effect.gen(function* () {
126-
const { browser, fs, path, installRoot, requests } = yield* makeHarness();
125+
const { browser, fs, path, baseDir, installRoot, requests } = yield* makeHarness();
126+
const headlessShell = path.join(baseDir, "tools", "chrome-headless-shell");
127+
yield* fs.makeDirectory(path.join(headlessShell, "linux64", "156"), { recursive: true });
127128
yield* fs.makeDirectory(path.join(installRoot, "1.0.0"), { recursive: true });
128129
const active = path.join(installRoot, ".install-other");
129130
const abandoned = path.join(installRoot, ".install-abandoned");
@@ -152,6 +153,49 @@ it.layer(NodeServices.layer)("PreviewBrowser", (it) => {
152153
expect(yield* browser.executable).toBe(executable);
153154
expect(yield* browser.installed).toEqual(Option.some(executable));
154155
expect(requests).toHaveLength(1);
156+
expect(yield* fs.exists(headlessShell)).toBe(false);
157+
}),
158+
);
159+
160+
// macOS framework bundles link inside themselves; links are written as POSIX links.
161+
it.effect.skipIf(hostPlatform === "win32")(
162+
"installs links that stay inside the browser's directory",
163+
() =>
164+
Effect.gen(function* () {
165+
const { browser, fs, path, installRoot } = yield* makeHarness({
166+
archive: makeZip([
167+
{ name: `${ROOT}${executableName}`, data: "#!/bin/sh\n", mode: 0o100755 },
168+
{ name: `${ROOT}Versions/A/library`, data: "library", mode: 0o100644 },
169+
{ name: `${ROOT}Versions/Current`, data: "A", mode: 0o120755 },
170+
{ name: `${ROOT}library`, data: "Versions/Current/library", mode: 0o120755 },
171+
]),
172+
});
173+
174+
yield* browser.executable;
175+
176+
const version = path.join(installRoot, "1.2.3");
177+
expect(yield* fs.readLink(path.join(version, "library"))).toBe("Versions/Current/library");
178+
expect(yield* fs.readFileString(path.join(version, "library"))).toBe("library");
179+
}),
180+
);
181+
182+
it.effect.each([
183+
{ name: "a parent directory", link: "../../escape" },
184+
{ name: "an absolute path", link: "/etc" },
185+
{ name: "nothing", link: "" },
186+
])("rejects an archive with a link to $name", (testCase) =>
187+
Effect.gen(function* () {
188+
const { browser, fs, installRoot } = yield* makeHarness({
189+
archive: makeZip([
190+
{ name: `${ROOT}${executableName}`, data: "#!/bin/sh\n", mode: 0o100755 },
191+
{ name: `${ROOT}link`, data: testCase.link, mode: 0o120755 },
192+
]),
193+
});
194+
195+
const error = yield* browser.executable.pipe(Effect.flip);
196+
197+
expect(error._tag).toBe("PreviewBrowserInstallError");
198+
expect(yield* fs.readDirectory(installRoot)).toEqual([]);
155199
}),
156200
);
157201

@@ -193,7 +237,7 @@ it.layer(NodeServices.layer)("PreviewBrowser", (it) => {
193237

194238
expect(error._tag).toBe("PreviewBrowserInstallError");
195239
expect(yield* fs.readDirectory(installRoot)).toEqual([]);
196-
expect(yield* fs.exists(path.join(baseDir, "tools", "chrome-headless-shell", "escape"))).toBe(
240+
expect(yield* fs.exists(path.join(baseDir, "tools", "chrome-for-testing", "escape"))).toBe(
197241
false,
198242
);
199243
}),

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

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,46 @@ import * as NodeCrypto from "node:crypto";
2121
import * as ServerConfig from "../config.ts";
2222
import { openZipArchive } from "../zipArchive.ts";
2323

24-
// Update the version, sizes and hashes from each chrome-headless-shell zip listed at
24+
// Update from each `chrome` zip (full Chrome: only it can capture a tab for recordings) listed at
2525
// https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
26-
// Never pin below 156.0.8078.70: the shell has no CRLSet and older SPKI blocklists trust
27-
// compromised eMudhra intermediates (crrev.com/c/8627687).
26+
// Never pin below 156.0.8078.70: Chrome for Testing has no CRLSet and older SPKI blocklists
27+
// trust compromised eMudhra intermediates (crrev.com/c/8627687).
2828
const VERSION = "156.0.8078.70";
2929
const ARCHIVES = {
3030
linux64: {
31-
bytes: 126_646_931,
32-
sha256: "a313da592261ff1e342c1e507d315f25b1809006c0508f77ce86151d464d4ccb",
31+
bytes: 201_035_256,
32+
sha256: "baac330433bb105012b7429ad77d4ba3d4ec3768810008ce9257d5d930c1b0cd",
3333
},
3434
"linux-arm64": {
35-
bytes: 126_749_876,
36-
sha256: "dca11213d2e0b1db52141edd9f92ec423fd52ca25715846790d84fa1d5d16e8a",
35+
bytes: 200_845_435,
36+
sha256: "46dce94a0790d177927044e83ee7e0f571bc22e90e6fafe21fce5c1e248bc865",
3737
},
3838
"mac-arm64": {
39-
bytes: 103_901_293,
40-
sha256: "1f848385611f2e58122e68969489712661880fc9a92c9dd20428099f9998ba7b",
39+
bytes: 194_910_526,
40+
sha256: "1070e2acc6fec1b80aac9215c9b83a381334a8c556df941e5146efb816121adb",
4141
},
4242
"mac-x64": {
43-
bytes: 109_387_968,
44-
sha256: "ab4cc2949f88439e2241b2712c49268f24982f2d25af87960466cc22bdc2e6e1",
43+
bytes: 205_543_880,
44+
sha256: "3218f6e802588632f2f8055b90035b306cad48874daf6067330e0f012afdb7ab",
4545
},
4646
win32: {
47-
bytes: 119_029_359,
48-
sha256: "37dc9a03f37fd79637fec9f26042bf32f04cfe5b83749d980eb1e7d1a429d47c",
47+
bytes: 188_579_460,
48+
sha256: "853955e981b07b8c44dfc77e658f6bfc806868a74176a44900aecda65ea4c26e",
4949
},
5050
win64: {
51-
bytes: 126_214_071,
52-
sha256: "41c6aa97046d05d015b817a95f7b1512c3a1a41b18364f8da46478ae520400b1",
51+
bytes: 209_092_934,
52+
sha256: "8ab65752ca6106bb8a5bf3afaa710ab4f62a57c27ed39db4977422c929fce0b3",
5353
},
5454
} as const;
5555

56+
/** The browser's executable inside the archive's top directory. */
57+
export const executableName = (platform: NodeJS.Platform) =>
58+
platform === "win32"
59+
? "chrome.exe"
60+
: platform === "darwin"
61+
? "Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing"
62+
: "chrome";
63+
5664
const chromePlatform = (platform: NodeJS.Platform, arch: NodeJS.Architecture) => {
5765
switch (platform) {
5866
case "linux":
@@ -85,7 +93,7 @@ const previewBrowserRelease = (
8593
: {
8694
version: VERSION,
8795
platform: chrome,
88-
url: `https://storage.googleapis.com/chrome-for-testing-public/${VERSION}/${chrome}/chrome-headless-shell-${chrome}.zip`,
96+
url: `https://storage.googleapis.com/chrome-for-testing-public/${VERSION}/${chrome}/chrome-${chrome}.zip`,
8997
...ARCHIVES[chrome],
9098
};
9199
};
@@ -119,7 +127,7 @@ export class PreviewBrowserUnsupportedError extends Schema.TaggedError<PreviewBr
119127
{ platform: Schema.String, arch: Schema.String },
120128
) {
121129
override get message(): string {
122-
return `T3's headless browser is not available on ${this.platform}-${this.arch}: Chrome for Testing has no headless shell for it.`;
130+
return `T3's headless browser is not available on ${this.platform}-${this.arch}: Chrome for Testing has no build for it.`;
123131
}
124132
}
125133

@@ -170,24 +178,23 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
170178
const release =
171179
options.release === undefined ? previewBrowserRelease(platform, arch) : options.release;
172180
const wait = options.wait ?? "45 seconds";
181+
const toolsDir = path.join(options.baseDir, "tools");
173182
const installRoot = path.join(
174-
options.baseDir,
175-
"tools",
176-
"chrome-headless-shell",
183+
toolsDir,
184+
"chrome-for-testing",
177185
release?.platform ?? `${platform}-${arch}`,
178186
);
179-
const executableName =
180-
platform === "win32" ? "chrome-headless-shell.exe" : "chrome-headless-shell";
187+
const binary = executableName(platform);
181188
const gate = yield* Semaphore.make(1);
182189
let state: InstallState = { _tag: "idle" };
183190
const progress = { downloadedBytes: 0, unpacking: false };
184191

185192
const installedExecutable = (release: PreviewBrowserRelease) => {
186-
const executable = path.join(installRoot, release.version, executableName);
187-
return fs.stat(executable).pipe(
193+
const installed = path.join(installRoot, release.version, binary);
194+
return fs.stat(installed).pipe(
188195
Effect.map((info) =>
189196
info.type === "File" && (platform === "win32" || (info.mode & 0o111) !== 0)
190-
? Option.some(executable)
197+
? Option.some(installed)
191198
: Option.none<string>(),
192199
),
193200
Effect.orElseSucceed(() => Option.none<string>()),
@@ -251,7 +258,7 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
251258
const unsafe = new PreviewBrowserInstallError({
252259
detail: "The archive contains an unexpected or unsafe entry.",
253260
});
254-
const root = `chrome-headless-shell-${release.platform}/`;
261+
const root = `chrome-${release.platform}/`;
255262
yield* fs.makeDirectory(destination);
256263
let foundExecutable = false;
257264
for (;;) {
@@ -260,14 +267,15 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
260267
const unixMode = entry.externalFileAttributes >>> 16;
261268
const unixType = unixMode & 0o170000;
262269
const isDirectory = entry.fileName.endsWith("/");
270+
const isSymlink = unixType === 0o120000;
263271
const relative = entry.fileName.startsWith(root) ? entry.fileName.slice(root.length) : null;
264272
const target = relative === null ? null : path.resolve(destination, relative);
265273
if (
266274
relative === null ||
267275
target === null ||
268276
(relative !== "" && !target.startsWith(`${destination}${path.sep}`)) ||
269277
relative.split("/").includes("..") ||
270-
(unixType !== 0 && unixType !== (isDirectory ? 0o040000 : 0o100000)) ||
278+
(unixType !== 0 && !isSymlink && unixType !== (isDirectory ? 0o040000 : 0o100000)) ||
271279
(entry.generalPurposeBitFlag & 1) !== 0 ||
272280
![0, 8].includes(entry.compressionMethod)
273281
) {
@@ -278,6 +286,21 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
278286
continue;
279287
}
280288
yield* fs.makeDirectory(path.dirname(target), { recursive: true });
289+
if (isSymlink) {
290+
// macOS framework bundles link within themselves (Versions/Current); nothing may point out.
291+
const linked = yield* Effect.gen(function* () {
292+
const readable = yield* archive.streamEntry(entry);
293+
return yield* EffectNodeStream.fromReadable<Uint8Array, PreviewBrowserInstallError>({
294+
evaluate: () => readable,
295+
onError: wrapFailure("Could not unpack the browser."),
296+
}).pipe(Stream.decodeText(), Stream.mkString);
297+
}).pipe(Effect.scoped);
298+
if (linked === "" || linked.startsWith("/") || linked.split("/").includes("..")) {
299+
return yield* unsafe;
300+
}
301+
yield* fs.symlink(linked, target);
302+
continue;
303+
}
281304
yield* Effect.gen(function* () {
282305
const readable = yield* archive.streamEntry(entry);
283306
yield* EffectNodeStream.fromReadable<Uint8Array, PreviewBrowserInstallError>({
@@ -289,11 +312,11 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
289312
if (platform !== "win32" && (unixMode & 0o777) !== 0) {
290313
yield* fs.chmod(target, unixMode & 0o777);
291314
}
292-
if (relative === executableName) foundExecutable = true;
315+
if (relative === binary) foundExecutable = true;
293316
}
294317
if (!foundExecutable) {
295318
return yield* new PreviewBrowserInstallError({
296-
detail: "The archive does not contain chrome-headless-shell.",
319+
detail: "The archive does not contain Chrome.",
297320
});
298321
}
299322
},
@@ -345,7 +368,15 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
345368
),
346369
{ discard: true },
347370
);
348-
return path.join(installRoot, release.version, executableName);
371+
// Earlier versions installed chrome-headless-shell, which this browser replaces.
372+
yield* fs
373+
.remove(path.join(toolsDir, "chrome-headless-shell"), { recursive: true, force: true })
374+
.pipe(
375+
Effect.catch((cause) =>
376+
Effect.logWarning("Could not remove the old headless shell.", { cause }),
377+
),
378+
);
379+
return path.join(installRoot, release.version, binary);
349380
},
350381
Effect.mapError(wrapFailure("Could not save the browser in T3's home directory.")),
351382
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const LDD_IN_BARE_DEBIAN = `\tlinux-vdso.so.1 (0x00007ffd2d1f8000)
1919
// Chrome's own abort on Ubuntu 26.04 with unprivileged user namespaces restricted.
2020

2121
const LOADER_ERROR =
22-
"chrome-headless-shell: error while loading shared libraries: libglib-2.0.so.0: cannot open shared object file: No such file or directory";
22+
"chrome: error while loading shared libraries: libglib-2.0.so.0: cannot open shared object file: No such file or directory";
2323

2424
const hostReporting = (output: { readonly version: string; readonly ldd: string }) => {
2525
const commands: Array<string> = [];
@@ -60,7 +60,7 @@ const diagnose = (input: {
6060
version: input.version ?? LOADER_ERROR,
6161
});
6262
return PreviewBrowserHost.diagnoseLaunchFailure({
63-
executable: "/home/me/.t3/tools/chrome-headless-shell/linux64/154/chrome-headless-shell",
63+
executable: "/home/me/.t3/tools/chrome-for-testing/linux64/154/chrome",
6464
output: input.output,
6565
setupCommand: "sudo t3 browser setup",
6666
}).pipe(

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,27 @@ export const sandboxDisabled = (env: Readonly<Record<string, string | undefined>
1414

1515
/** Set on Ubuntu 23.10+: unprivileged user namespaces need an AppArmor profile. */
1616
const USERNS_RESTRICTION = "/proc/sys/kernel/apparmor_restrict_unprivileged_userns";
17-
export const APPARMOR_PROFILE_PATH = "/etc/apparmor.d/t3-chrome-headless-shell";
17+
// Named after the browser it allows: hosts set up for the former headless shell need a new profile.
18+
export const APPARMOR_PROFILE_PATH = "/etc/apparmor.d/t3-chrome-for-testing";
1819

1920
/** Match Ubuntu's Chrome profile; unconfined adds nothing beyond userns. */
2021
export const APPARMOR_PROFILE = `# Written by \`t3 browser setup\`: lets T3 Code's headless browser use Chrome's sandbox.
2122
abi <abi/4.0>,
2223
include <tunables/global>
2324
24-
profile t3-chrome-headless-shell /**/tools/chrome-headless-shell/*/*/chrome-headless-shell flags=(unconfined) {
25+
profile t3-chrome-for-testing /**/tools/chrome-for-testing/*/*/chrome flags=(unconfined) {
2526
userns,
2627
27-
include if exists <local/t3-chrome-headless-shell>
28+
include if exists <local/t3-chrome-for-testing>
2829
}
2930
`;
3031

3132
/** Ubuntu 24.04 and Debian 13 use some t64 library names; choose names available through apt. */
3233
export const DEBIAN_PACKAGES: ReadonlyArray<ReadonlyArray<string>> = [
3334
["libnss3"],
35+
["libcairo2"],
36+
["libcups2t64", "libcups2"],
37+
["libpango-1.0-0"],
3438
["libglib2.0-0t64", "libglib2.0-0"],
3539
["libatk1.0-0t64", "libatk1.0-0"],
3640
["libatk-bridge2.0-0t64", "libatk-bridge2.0-0"],

0 commit comments

Comments
 (0)