Skip to content

Commit 600ffd0

Browse files
committed
fix(engine): a missing or unreadable full Chrome cache never stops a WSL render
1 parent be48e9d commit 600ffd0

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

‎packages/engine/src/services/browserManager.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
resolveHeadlessShellPath,
2929
resolveBrowserGpuMode,
3030
resolveCaptureBrowserPath,
31+
resolveFullChromePath,
3132
} from "./browserManager.js";
3233

3334
describe("BeginFrame capability probe", () => {
@@ -699,6 +700,20 @@ describe("resolveBrowserGpuMode", () => {
699700
});
700701
});
701702

703+
it("finds no full Chrome, without throwing, when its cache cannot be read", () => {
704+
const home = mkdtempSync(join(tmpdir(), "hf-full-chrome-cache-"));
705+
const saved = { HOME: process.env.HOME, USERPROFILE: process.env.USERPROFILE };
706+
try {
707+
mkdirSync(join(home, ".cache", "puppeteer"), { recursive: true });
708+
writeFileSync(join(home, ".cache", "puppeteer", "chrome"), "not a folder");
709+
Object.assign(process.env, { HOME: home, USERPROFILE: home });
710+
expect(resolveFullChromePath()).toBeUndefined();
711+
} finally {
712+
Object.assign(process.env, saved);
713+
rmSync(home, { recursive: true, force: true });
714+
}
715+
});
716+
702717
it("never swaps the browser outside WSL", async () => {
703718
setMockWebGlProbe({ hasWebGL: false, vendor: "", renderer: "" });
704719
vi.spyOn(console, "error").mockImplementation(() => {});

‎packages/engine/src/services/browserManager.ts‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,12 @@ export function resolveHeadlessShellPath(
277277
/** Full Chrome for Testing in Puppeteer's cache (`@puppeteer/browsers install chrome@...`), newest first. */
278278
export function resolveFullChromePath(): string | undefined {
279279
const baseDir = join(homedir(), ".cache", "puppeteer", "chrome");
280-
if (!existsSync(baseDir)) return undefined;
281-
const versions = readdirSync(baseDir).sort(compareBrowserVersionsDescending);
280+
let versions: string[];
281+
try {
282+
versions = readdirSync(baseDir).sort(compareBrowserVersionsDescending);
283+
} catch {
284+
return undefined;
285+
}
282286
for (const version of versions) {
283287
const candidates = [
284288
join(
@@ -624,11 +628,12 @@ async function probeWslFullChrome(
624628
const fullChrome = (options.findFullChrome ?? resolveFullChromePath)();
625629
let route: FullChromeRoute = { state: "missing" };
626630
if (fullChrome) {
627-
if (fullChrome !== shellPath) {
628-
const viaFullChrome = await probeWebGlMode(ppt, fullChrome, options, "full Chrome: ");
629-
if (viaFullChrome.mode === "hardware") return { mode: "hardware", browserPath: fullChrome };
630-
}
631-
route = { state: "no-gpu", path: fullChrome };
631+
const viaFullChrome =
632+
fullChrome === shellPath
633+
? shellOutcome
634+
: await probeWebGlMode(ppt, fullChrome, options, "full Chrome: ");
635+
if (viaFullChrome.mode === "hardware") return { mode: "hardware", browserPath: fullChrome };
636+
route = { state: viaFullChrome.cause ?? "no-gpu", path: fullChrome };
632637
}
633638
return { ...shellOutcome, wslAccess: describeWslGpuAccess(options.wslHost, route) ?? undefined };
634639
}

‎packages/engine/src/services/wslHost.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ describe("describeWslGpuAccess", () => {
102102
expect(tried).toContain("Full Chrome (/c/chrome) found no hardware GPU either.");
103103
expect(tried).not.toContain("@puppeteer/browsers install");
104104
expect(tried).toContain("native Windows");
105+
const timedOut = describeWslGpuAccess(host, { state: "probe-error", path: "/c/chrome" });
106+
expect(timedOut?.join("\n")).toContain("could not finish its GPU check either");
105107
});
106108

107109
it("returns null outside WSL", () => {

‎packages/engine/src/services/wslHost.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export function detectWsl(host: WslHostFacts = realHost): boolean {
6767

6868
const RENDER_NODE = "/dev/dri/renderD128";
6969

70-
export type FullChromeRoute = { state: "missing" } | { state: "no-gpu"; path: string };
70+
export type FullChromeRoute =
71+
| { state: "missing" }
72+
| { state: "no-gpu" | "probe-error"; path: string };
7173

7274
const NATIVE_WINDOWS =
7375
"render from native Windows (project copied to a Windows drive, run from PowerShell), " +
@@ -82,7 +84,9 @@ function routeToGpu(fullChrome: FullChromeRoute): string[] {
8284
"~/.cache/puppeteer` and HyperFrames will try it when the headless shell finds no GPU " +
8385
"(or point HYPERFRAMES_BROWSER_PATH at a full Chrome).",
8486
]
85-
: [` Full Chrome (${fullChrome.path}) found no hardware GPU either.`];
87+
: fullChrome.state === "no-gpu"
88+
? [` Full Chrome (${fullChrome.path}) found no hardware GPU either.`]
89+
: [` Full Chrome (${fullChrome.path}) could not finish its GPU check either.`];
8690
return [...viaFullChrome, ` Or ${NATIVE_WINDOWS}`];
8791
}
8892

0 commit comments

Comments
 (0)