fix(inspector): the inspector's Chrome starts as root or in a container (#8050)

* test(inspector): the inspector's Chrome follows the host sandbox rule, and probes retry without it

* fix(inspector): the inspector's Chrome starts as root or in a container

* test(producer): the page check and the inspector retry Chrome without the sandbox when it refuses

* fix(producer): the page check retries Chrome without the sandbox when it refuses, like the inspector

* chore(inspector): raise the packed size budget for the shared sandbox rule
This commit is contained in:
Miguel Ángel
2026-11-17 07:43:53 +00:00
committed by GitHub
parent fe93f9cd47
commit f91bbf0dac
15 changed files with 160 additions and 23 deletions
+6
View File
@@ -74,6 +74,12 @@
"types": "./dist/chromeEnv.d.ts",
"environments": ["bun", "node"]
},
"./chrome-sandbox": {
"source": "./src/chromeSandbox.ts",
"runtime": "./dist/chromeSandbox.js",
"types": "./dist/chromeSandbox.d.ts",
"environments": ["bun", "node"]
},
"./atomic-file": {
"source": "./src/atomicFile.ts",
"runtime": "./dist/atomicFile.js",
+10
View File
@@ -86,6 +86,12 @@
"import": "./src/chromeEnv.ts",
"types": "./src/chromeEnv.ts"
},
"./chrome-sandbox": {
"bun": "./src/chromeSandbox.ts",
"node": "./dist/chromeSandbox.js",
"import": "./src/chromeSandbox.ts",
"types": "./src/chromeSandbox.ts"
},
"./atomic-file": {
"bun": "./src/atomicFile.ts",
"node": "./dist/atomicFile.js",
@@ -714,6 +720,10 @@
"import": "./dist/chromeEnv.js",
"types": "./dist/chromeEnv.d.ts"
},
"./chrome-sandbox": {
"import": "./dist/chromeSandbox.js",
"types": "./dist/chromeSandbox.d.ts"
},
"./atomic-file": {
"import": "./dist/atomicFile.js",
"types": "./dist/atomicFile.d.ts"
+1 -1
View File
@@ -591,7 +591,7 @@ export {
chromeSandboxEnabled,
launchWithChromeSandboxFallback,
type ChromeSandboxHost,
} from "./services/chromeSandbox.js";
} from "@hyperframes/core/chrome-sandbox";
export {
VariablesInvalidError,
type VariablesIssue,
@@ -6,7 +6,7 @@ import {
acquireBrowser,
drainBrowserPool,
} from "./browserManager.js";
import { _resetChromeSandboxFallbackForTests } from "./chromeSandbox.js";
import { _resetChromeSandboxFallbackForTests } from "@hyperframes/core/chrome-sandbox";
const explained = vi.hoisted(() => [] as (readonly string[] | undefined)[]);
const explainedEnvs = vi.hoisted(() => [] as (NodeJS.ProcessEnv | undefined)[]);
@@ -1,4 +1,5 @@
// fallow-ignore-file code-duplication
import { _resetChromeSandboxFallbackForTests } from "@hyperframes/core/chrome-sandbox";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { execFileSync } from "node:child_process";
import { EventEmitter } from "node:events";
@@ -777,6 +778,27 @@ describe("resolveBrowserGpuMode", () => {
expect(args).not.toContain(flag);
});
it.skipIf(process.platform !== "linux")(
"retries the GPU probe without the sandbox when Chrome refuses it, as the render does",
async () => {
const { launch } = setMockWebGlProbe({
hasWebGL: true,
vendor: "NVIDIA",
renderer: "NVIDIA",
});
const browser = await launch();
launch.mockReset();
launch.mockRejectedValueOnce(new Error("No usable sandbox!")).mockResolvedValue(browser);
try {
await resolveBrowserGpuMode("auto", { sandbox: true });
const args = launch.mock.calls.map(([options]) => options.args.includes("--no-sandbox"));
expect(args).toEqual([false, true]);
} finally {
_resetChromeSandboxFallbackForTests();
}
},
);
it("lets a host own GPU probe launch and cleanup", async () => {
const { launch } = setMockWebGlProbe({ hasWebGL: true, vendor: "NVIDIA", renderer: "NVIDIA" });
const close = vi.fn(async (browser: Browser) => {
@@ -45,7 +45,7 @@ import {
chromeSandboxArgs,
chromeSandboxEnabled,
launchWithChromeSandboxFallback,
} from "./chromeSandbox.js";
} from "@hyperframes/core/chrome-sandbox";
import { describeWslGpuAccess, detectWsl, type WslHostFacts } from "./wslHost.js";
import {
BrowserLeasePool,
@@ -9,7 +9,7 @@ import {
chromeSandboxArgs,
chromeSandboxEnabled,
startsWithChromeSandboxFallback,
} from "./chromeSandbox.js";
} from "@hyperframes/core/chrome-sandbox";
/** Chrome 151 dropped macOS 12 and older (Darwin < 22); 150 is the last major that launches there. */
const MACOS_12_LAST_CHROME_MAJOR = 150;
@@ -9,7 +9,7 @@ import {
NO_SANDBOX_ARGS,
startsWithChromeSandboxFallback,
type ChromeSandboxHost,
} from "./chromeSandbox.js";
} from "@hyperframes/core/chrome-sandbox";
import { shellStarts } from "./chromeHostCeiling.js";
import { buildChromeArgs } from "./browserManager.js";
import { buildHdrChromeArgs } from "./hdrCapture.js";
+1 -1
View File
@@ -27,7 +27,7 @@ import {
chromeSandboxArgs,
chromeSandboxEnabled,
launchWithChromeSandboxFallback,
} from "./chromeSandbox.js";
} from "@hyperframes/core/chrome-sandbox";
// ── PQ (SMPTE 2084) OETF ─────────────────────────────────────────────────────
+41
View File
@@ -0,0 +1,41 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { _resetChromeSandboxFallbackForTests, NO_SANDBOX_ARGS } from "../../core/src/chromeSandbox";
import { inspectorChromeArgs, launchInspectorChrome } from "./service";
const launch = vi.hoisted(() => vi.fn());
vi.mock("puppeteer-core", () => ({ default: { launch } }));
afterEach(() => {
launch.mockReset();
_resetChromeSandboxFallbackForTests();
});
describe("the inspector's Chrome", () => {
it("drops the sandbox where the host can't give one, so it starts as root or in a container", () => {
expect(inspectorChromeArgs(["--proxy-server=x"], false)).toEqual(
expect.arrayContaining([...NO_SANDBOX_ARGS, "--proxy-server=x"]),
);
});
it("keeps the sandbox where the host allows it", () => {
const args = inspectorChromeArgs([], true);
for (const flag of NO_SANDBOX_ARGS) expect(args).not.toContain(flag);
});
it.skipIf(process.platform !== "linux")(
"starts without the sandbox when Chrome refuses it, as the render does",
async () => {
launch.mockRejectedValueOnce(new Error("No usable sandbox!")).mockResolvedValue({});
await launchInspectorChrome({
executablePath: "/chrome",
userDataDir: "/profile",
proxyArgs: [],
sandbox: true,
});
const sandboxOff = launch.mock.calls.map(([options]) =>
options.args.includes("--no-sandbox"),
);
expect(sandboxOff).toEqual([false, true]);
},
);
});
+40 -10
View File
@@ -1,6 +1,11 @@
import type { TimelineRequest } from "../../core/src/runtime/timelineInspection";
import { withHyperframesBrowserMarker } from "../../core/src/browserMarker";
import { buildChromeLaunchEnv } from "../../core/src/chromeEnv";
import {
chromeSandboxArgs,
chromeSandboxEnabled,
launchWithChromeSandboxFallback,
} from "../../core/src/chromeSandbox";
import {
inspectComponents,
inspectElementMap,
@@ -72,6 +77,39 @@ async function releaseEach(steps: ReadonlyArray<() => unknown>): Promise<void> {
}
}
export function inspectorChromeArgs(
proxyArgs: readonly string[],
sandbox = chromeSandboxEnabled(),
): string[] {
return [
...chromeSandboxArgs(sandbox),
"--disable-dev-shm-usage",
"--enable-webgl",
"--use-gl=angle",
"--use-angle=swiftshader",
...proxyArgs,
];
}
export function launchInspectorChrome(options: {
executablePath: string;
userDataDir: string;
proxyArgs: readonly string[];
sandbox?: boolean;
}): Promise<Browser> {
return launchWithChromeSandboxFallback(
inspectorChromeArgs(options.proxyArgs, options.sandbox),
(args) =>
puppeteer.launch({
executablePath: options.executablePath,
env: buildChromeLaunchEnv(),
headless: true,
userDataDir: options.userDataDir,
args: withHyperframesBrowserMarker(args),
}),
);
}
export interface InspectorOptions {
executablePath?: string;
idleMs?: number;
@@ -148,18 +186,10 @@ export class Inspector {
const started = await startCaptureProxy();
proxy = started;
profile = await createPublicOnlyProfile("hf-inspect-profile-");
const browser = await puppeteer.launch({
const browser = await launchInspectorChrome({
executablePath: this.options.executablePath ?? chromePath(),
env: buildChromeLaunchEnv(),
headless: true,
userDataDir: profile,
args: withHyperframesBrowserMarker([
"--disable-dev-shm-usage",
"--enable-webgl",
"--use-gl=angle",
"--use-angle=swiftshader",
...browserProxyArgs(started.url, `127.0.0.1:${address.port}`),
]),
proxyArgs: browserProxyArgs(started.url, `127.0.0.1:${address.port}`),
});
this.stats.browserStarts++;
this.host = { browser, server, port: address.port, proxy: started, profile };
@@ -0,0 +1,21 @@
import { afterEach, expect, it, vi } from "vitest";
import { _resetChromeSandboxFallbackForTests } from "@hyperframes/core/chrome-sandbox";
import { launchVerifyBrowser } from "./verifyStaticPage.js";
const launch = vi.hoisted(() => vi.fn());
vi.mock("puppeteer", () => ({ default: { launch } }));
afterEach(() => {
launch.mockReset();
_resetChromeSandboxFallbackForTests();
});
it.skipIf(process.platform !== "linux")(
"the page check starts without the sandbox when Chrome refuses it, as the render does",
async () => {
launch.mockRejectedValueOnce(new Error("No usable sandbox!")).mockResolvedValue({});
await launchVerifyBrowser(true);
const sandboxOff = launch.mock.calls.map(([options]) => options.args.includes("--no-sandbox"));
expect(sandboxOff).toEqual([false, true]);
},
);
+13 -6
View File
@@ -3,6 +3,11 @@
import puppeteer, { type Browser } from "puppeteer";
import { withHyperframesBrowserMarker } from "@hyperframes/core/browser-marker";
import {
chromeSandboxArgs,
chromeSandboxEnabled,
launchWithChromeSandboxFallback,
} from "@hyperframes/core/chrome-sandbox";
import { injectScriptsAtHeadStart } from "@hyperframes/core/compiler";
import { getVerifiedHyperframeRuntimeSource } from "./services/hyperframeRuntimeLoader.js";
@@ -10,12 +15,14 @@ export interface PageCheckResult {
failures: string[];
}
export async function launchVerifyBrowser(): Promise<Browser> {
return puppeteer.launch({
headless: true,
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || undefined,
args: withHyperframesBrowserMarker(["--no-sandbox", "--disable-setuid-sandbox"]),
});
export async function launchVerifyBrowser(sandbox = chromeSandboxEnabled()): Promise<Browser> {
return launchWithChromeSandboxFallback(chromeSandboxArgs(sandbox), (args) =>
puppeteer.launch({
headless: true,
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || undefined,
args: withHyperframesBrowserMarker(args),
}),
);
}
export async function checkPageLoads(
+1 -1
View File
@@ -20,7 +20,7 @@
"unpacked": 170124
},
"@hyperframes/inspector": {
"packed": 880000,
"packed": 933584,
"unpacked": 3830000
},
"@hyperframes/lint": {