





















@@ -8,16 +8,7 @@ import { chromium } from "playwright";
88import { resolvePnpmRunner } from "./pnpm-runner.mjs";
991010const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
11-const playwrightInstallArgs = ["--dir", "ui", "exec", "playwright", "install", "chromium"];
12-const playwrightInstallWithDepsArgs = [
13-"--dir",
14-"ui",
15-"exec",
16-"playwright",
17-"install",
18-"--with-deps",
19-"chromium",
20-];
11+const playwrightInstallBaseArgs = ["--dir", "ui", "exec", "playwright", "install"];
2112const executableOverrideEnvKey = "PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH";
2213/**
2314 * System Chromium executable paths used before downloading Playwright browsers.
@@ -59,12 +50,17 @@ export function resolveSystemChromiumExecutablePath(
5950 */
6051export function resolvePlaywrightInstallRunner(options = {}) {
6152const env = options.env ?? process.env;
53+const targets = options.targets ?? ["chromium"];
6254return resolvePnpmRunner({
6355comSpec: options.comSpec ?? env.ComSpec ?? env.COMSPEC,
6456 env,
6557npmExecPath: env === process.env ? env.npm_execpath : (env.npm_execpath ?? ""),
6658platform: options.platform,
67-pnpmArgs: options.withDeps ? playwrightInstallWithDepsArgs : playwrightInstallArgs,
59+pnpmArgs: [
60+ ...playwrightInstallBaseArgs,
61+ ...(options.withDeps ? ["--with-deps"] : []),
62+ ...targets,
63+],
6864});
6965}
7066@@ -122,10 +118,37 @@ export function ensurePlaywrightChromium(options = {}) {
122118const existsSync = options.existsSync ?? existsSyncImpl;
123119const log = options.log ?? console.error;
124120const spawnSync = options.spawnSync ?? spawnSyncImpl;
121+const runPlaywrightInstall = (targets = ["chromium"], withDeps = false) => {
122+const runner = resolvePlaywrightInstallRunner({
123+comSpec: options.comSpec,
124+ env,
125+platform: options.platform,
126+ targets,
127+ withDeps,
128+});
129+const result = spawnSync(runner.command, runner.args, {
130+cwd: options.cwd ?? repoRoot,
131+ env,
132+shell: runner.shell,
133+stdio: options.stdio ?? "inherit",
134+windowsVerbatimArguments: runner.windowsVerbatimArguments,
135+});
136+return result.status ?? 1;
137+};
138+const ensureFfmpeg = () => {
139+if (!options.ensureFfmpeg) {
140+return 0;
141+}
142+const status = runPlaywrightInstall(["ffmpeg"]);
143+if (status !== 0) {
144+log(`[ui-e2e] Playwright ffmpeg install failed with status ${status}.`);
145+}
146+return status;
147+};
125148126149if (executableOverride) {
127150if (existsSync(executableOverride) && canRunChromiumExecutable(executableOverride, spawnSync)) {
128-return 0;
151+return ensureFfmpeg();
129152}
130153log(
131154`[ui-e2e] ${executableOverrideEnvKey} points to ${executableOverride}, but that browser is not runnable.`,
@@ -134,14 +157,14 @@ export function ensurePlaywrightChromium(options = {}) {
134157}
135158136159if (existsSync(executablePath) && canRunChromiumExecutable(executablePath, spawnSync)) {
137-return 0;
160+return ensureFfmpeg();
138161}
139162140163const systemExecutablePath =
141164options.systemExecutablePath ?? resolveSystemChromiumExecutablePath(existsSync, spawnSync);
142165if (systemExecutablePath && canRunChromiumExecutable(systemExecutablePath, spawnSync)) {
143166log(`[ui-e2e] Using system Chromium at ${systemExecutablePath}.`);
144-return 0;
167+return ensureFfmpeg();
145168}
146169147170if (env.OPENCLAW_UI_E2E_ALLOW_MISSING_CHROMIUM === "1") {
@@ -157,35 +180,18 @@ export function ensurePlaywrightChromium(options = {}) {
157180getuid: options.getuid,
158181platform: options.platform,
159182});
160-const runPlaywrightInstall = (withDeps = false) => {
161-const runner = resolvePlaywrightInstallRunner({
162-comSpec: options.comSpec,
163- env,
164-platform: options.platform,
165- withDeps,
166-});
167-const result = spawnSync(runner.command, runner.args, {
168-cwd: options.cwd ?? repoRoot,
169- env,
170-shell: runner.shell,
171-stdio: options.stdio ?? "inherit",
172-windowsVerbatimArguments: runner.windowsVerbatimArguments,
173-});
174-return result.status ?? 1;
175-};
176-177183const status = runPlaywrightInstall();
178184if (status !== 0) {
179185if (canInstallSystemDependencies) {
180186log(
181187`[ui-e2e] Chromium install failed in a Linux CI/root lane; installing Linux system dependencies.`,
182188);
183-const depsStatus = runPlaywrightInstall(true);
189+const depsStatus = runPlaywrightInstall(["chromium"], true);
184190if (depsStatus !== 0) {
185191return depsStatus;
186192}
187193if (existsSync(executablePath) && canRunChromiumExecutable(executablePath, spawnSync)) {
188-return 0;
194+return ensureFfmpeg();
189195}
190196log(
191197`[ui-e2e] Playwright install completed but Chromium is still not runnable at ${executablePath}.`,
@@ -200,22 +206,22 @@ export function ensurePlaywrightChromium(options = {}) {
200206log(
201207`[ui-e2e] Chromium is installed but still cannot start; installing Linux system dependencies.`,
202208);
203-const depsStatus = runPlaywrightInstall(true);
209+const depsStatus = runPlaywrightInstall(["chromium"], true);
204210if (depsStatus !== 0) {
205211return depsStatus;
206212}
207213if (existsSync(executablePath) && canRunChromiumExecutable(executablePath, spawnSync)) {
208-return 0;
214+return ensureFfmpeg();
209215}
210216}
211217log(
212218`[ui-e2e] Playwright install completed but Chromium is still not runnable at ${executablePath}.`,
213219);
214220return 1;
215221}
216-return 0;
222+return ensureFfmpeg();
217223}
218224219225if (isDirectScriptExecution()) {
220-process.exitCode = ensurePlaywrightChromium();
226+process.exitCode = ensurePlaywrightChromium({ ensureFfmpeg: true });
221227}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。