@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 04:45 UTC

main
mjs 34 lines 1.34 KB
Raw
1 import * as NodeFS from "node:fs";
2 import * as NodeOS from "node:os";
3 import * as NodePath from "node:path";
4
5 // Playwright's pinned revision is often not downloaded; any cached Chromium renders the same CSS.
6 export const findChrome = (chromium) => {
7 if (process.env.CHROME) return process.env.CHROME;
8 const pinned = chromium.executablePath();
9 if (NodeFS.existsSync(pinned)) return pinned;
10 const caches = [".cache/ms-playwright", "Library/Caches/ms-playwright"]
11 .map((d) => NodePath.join(NodeOS.homedir(), d))
12 .filter(NodeFS.existsSync);
13 const builds = caches
14 .flatMap((cache) =>
15 NodeFS.readdirSync(cache)
16 .filter((d) => /^chromium-\d+$/.test(d))
17 .map((d) => ({ cache, d, rev: Number(d.split("-")[1]) })),
18 )
19 .sort((a, b) => b.rev - a.rev);
20 const candidates = builds.flatMap(({ cache, d }) => [
21 NodePath.join(cache, d, "chrome-linux64/chrome"),
22 NodePath.join(cache, d, "chrome-linux/chrome"),
23 NodePath.join(cache, d, "chrome-mac-arm64/Chromium.app/Contents/MacOS/Chromium"),
24 NodePath.join(cache, d, "chrome-mac/Chromium.app/Contents/MacOS/Chromium"),
25 ]);
26 const found = candidates.find(NodeFS.existsSync);
27 if (!found) {
28 console.error(
29 "No Chromium found. Set CHROME=/path/to/chrome or run `vp exec playwright install chromium` in apps/web.",
30 );
31 process.exit(1);
32 }
33 return found;
34 };