fix(docker): export Playwright browser runtime path

This commit is contained in:
Ayaan Zaidi
2026-05-10 11:06:39 +05:30
parent 3050b1568d
commit 082c932e94
4 changed files with 26 additions and 12 deletions

View File

@@ -207,15 +207,15 @@ RUN --mount=type=cache,id=openclaw-bookworm-apt-cache,target=/var/cache/apt,shar
# Adds ~300MB but eliminates the 60-90s Playwright install on every container start.
# Must run after node_modules COPY so playwright-core is available.
ARG OPENCLAW_INSTALL_BROWSER=""
ENV PLAYWRIGHT_BROWSERS_PATH=/home/node/.cache/ms-playwright
RUN --mount=type=cache,id=openclaw-bookworm-apt-cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,id=openclaw-bookworm-apt-lists,target=/var/lib/apt,sharing=locked \
if [ -n "$OPENCLAW_INSTALL_BROWSER" ]; then \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends xvfb && \
mkdir -p /home/node/.cache/ms-playwright && \
PLAYWRIGHT_BROWSERS_PATH=/home/node/.cache/ms-playwright \
mkdir -p "$PLAYWRIGHT_BROWSERS_PATH" && \
node /app/node_modules/playwright-core/cli.js install --with-deps chromium && \
chown -R node:node /home/node/.cache/ms-playwright; \
chown -R node:node "$PLAYWRIGHT_BROWSERS_PATH"; \
fi
# Optionally install Docker CLI for sandbox container management.

View File

@@ -414,10 +414,9 @@ See [ClawDock](/install/clawdock) for the full helper guide.
docker compose run --rm openclaw-cli \
node /app/node_modules/playwright-core/cli.js install chromium
```
4. **Persist browser downloads**: set
`PLAYWRIGHT_BROWSERS_PATH=/home/node/.cache/ms-playwright` and use
`OPENCLAW_HOME_VOLUME` or `OPENCLAW_EXTRA_MOUNTS`. OpenClaw auto-detects
the persisted Chromium on Linux.
4. **Persist browser downloads**: use `OPENCLAW_HOME_VOLUME` or
`OPENCLAW_EXTRA_MOUNTS`. OpenClaw auto-detects the Docker image's
Playwright-managed Chromium on Linux.
</Accordion>

View File

@@ -441,16 +441,21 @@ export async function launchOpenClawChrome(
userDataDir,
...launchOptions,
});
const env = {
...omitChromeProxyEnv(process.env),
// Reduce accidental sharing with the user's env.
HOME: os.homedir(),
};
if (process.platform === "linux") {
env.XDG_CONFIG_HOME ??= path.join(os.tmpdir(), ".chromium");
env.XDG_CACHE_HOME ??= path.join(os.tmpdir(), ".chromium");
}
// stdio tuple: discard stdout to prevent buffer saturation in constrained
// environments (e.g. Docker), while keeping stderr piped for diagnostics.
// Cast to ChildProcessWithoutNullStreams so callers can use .stderr safely;
// the tuple overload resolution varies across @types/node versions.
const preparedSpawn = prepareOomScoreAdjustedSpawn(exe.path, args, {
env: {
...omitChromeProxyEnv(process.env),
// Reduce accidental sharing with the user's env.
HOME: os.homedir(),
},
env,
});
return spawn(preparedSpawn.command, preparedSpawn.args, {
stdio: ["ignore", "ignore", "pipe"],

View File

@@ -74,6 +74,16 @@ describe("test-install-sh-docker", () => {
expect(dockerfile).toContain("NODE_OPTIONS=--max-old-space-size=8192 pnpm build:docker");
});
it("exports the Playwright browser cache installed by the root Dockerfile", () => {
const dockerfile = readFileSync("Dockerfile", "utf8");
expect(dockerfile).toContain("ENV PLAYWRIGHT_BROWSERS_PATH=/home/node/.cache/ms-playwright");
expect(dockerfile).toContain('mkdir -p "$PLAYWRIGHT_BROWSERS_PATH"');
expect(dockerfile).toContain(
"node /app/node_modules/playwright-core/cli.js install --with-deps chromium",
);
});
it("allows repository branch history and release tags for secret-backed Docker release checks", () => {
const workflow = readFileSync(LIVE_E2E_WORKFLOW_PATH, "utf8");