Skip to content

Video as code: canvas scenes rendered with WebCodecs in headless Chrome, a review viewer, and agent skills that build the video from your references.

Chrome: use Playwright's Chromium when there is no system Chrome (#11)

Stanyslaus Haryc439744043b1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a57feba..c42be2b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@ Changes are listed by release, newest first. The sections dated before 0.1.0 rec
## Unreleased
+### Added
+
+- With no system Chrome, motlab uses the newest Chromium that Playwright downloaded, from Playwright's folder (`~/.cache/ms-playwright` on Linux, `~/Library/Caches/ms-playwright` on macOS, `%LOCALAPPDATA%\ms-playwright` on Windows, or `PLAYWRIGHT_BROWSERS_PATH`), so `motlab doctor` passes without `CHROME` on a machine set up for Playwright (issue #8). The folder names come from Playwright's own code, and a test checks the lookup on folders made for it. Not tried: a real Playwright download found this way. The render in issue #8 used that Chromium with `CHROME` set.
+
### Changed
- The install docs now say a Chromium you already have works: set `CHROME` to it, for example the Chromium Playwright downloads, instead of installing Google Chrome. The README, the install docs and the roadmap also record that a real video has now been rendered on Linux: a 42 s, 1080x1920 project on Ubuntu 24.04 with no GPU in about 82 s (issue #8). An install from the npm registry on Linux and anything on macOS are still untested.
diff --git a/ROADMAP.md b/ROADMAP.md
index 3afce74..f9a7baf 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -31,7 +31,7 @@ What is not built, what has not been tested, and ideas that came up while using
- Notes on a real touch screen. Touch was emulated in Chrome over the DevTools protocol. Moving and resizing a box was tried with the mouse only.
- The viewer on a real phone. The phone layout, its menus and notes drawn with touch were checked in Chrome with a phone emulated over the DevTools protocol, at 390 and 360 px upright and 844 and 740 px sideways. On an iPhone, Safari allows full screen for video elements only, so the viewer has no full screen there.
- The viewer's full screen outside Chrome on Windows.
-- The skills in agents other than Claude Code. The installer was run with `--dry-run` for every target, and the folders come from each agent's docs. Muse has loaded the skills and made a real video with them (a 42 s project on Ubuntu 24.04 with no GPU, issue #8); no other agent has yet. That includes Muse Code and Hermes Agent, added from their docs in November 2026.
+- The skills in agents other than Claude Code. The installer was run with `--dry-run` for every target, and the folders come from each agent's docs. A Muse agent followed `skills/motlab/SKILL.md` from a clone and made a real video (a 42 s project on Ubuntu 24.04 with no GPU, issue #8). The skills installed with `--skill muse`, Hermes Agent (both added from their docs in November 2026) and the other agents have not been tried yet.
## Questions about speed
diff --git a/docs/install.md b/docs/install.md
index 4e5859c..5fab0c7 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -7,7 +7,7 @@ motlab has two parts: the engine (the `motlab` command, the viewer and the rende
| Tool | Why | Check |
|---|---|---|
| Node.js 24 or newer | runs the engine | `node --version` |
-| Google Chrome or Chromium | draws and encodes the frames | found on its default path, or set `CHROME` to a binary you already have, for example the Chromium Playwright downloads |
+| Google Chrome or Chromium | draws and encodes the frames | found on its default path or in Playwright's browser folder, or set `CHROME` to it |
| ffmpeg and ffprobe | join the parts, add audio, check the output | `ffmpeg -version` |
| Python 3, optional | the skills' helper scripts | `python --version` |
| Blender 4.2 or newer, optional | the main 3D path of `motlab-assets` (FBX, baked textures, Cycles stills) | `blender --version` |
@@ -27,7 +27,7 @@ Google Chrome on Debian or Ubuntu (x64), the command `motlab doctor` prints when
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && sudo apt install -y ./google-chrome-stable_current_amd64.deb
```
-If Chrome is already on the machine another way, for example the Chromium Playwright downloads to `~/.cache/ms-playwright/`, set `CHROME` to that binary instead of installing Google's.
+A machine set up for Playwright needs no other Chrome. When no system Chrome is found, motlab uses the newest Chromium that `npx playwright install chromium` put in Playwright's folder: `~/.cache/ms-playwright` on Linux, `~/Library/Caches/ms-playwright` on macOS, `%LOCALAPPDATA%\ms-playwright` on Windows, or `PLAYWRIGHT_BROWSERS_PATH` when it is set. For a Chrome anywhere else, set `CHROME` to it.
The skill's scripts need numpy, scipy and Pillow. From the engine folder (`motlab --help` prints it; `motlab doctor` prints this command with the full path when they are missing):
@@ -172,7 +172,7 @@ It checks Node, Chrome, ffmpeg, ffprobe, the npm packages, and (as warnings) Pyt
Windows
-- Chrome is found in `Program Files` and `Program Files (x86)`. Set `CHROME` for any other path.
+- Chrome is found in `Program Files` and `Program Files (x86)`, then in Playwright's folder. Set `CHROME` for any other path.
- On a laptop with two GPUs, headless Chrome draws on the integrated one unless told otherwise. motlab always passes `--force_high_performance_gpu`, and each render prints the GPU it got.
- Python is usually `python`, not `python3`.
diff --git a/src/chrome.js b/src/chrome.js
index 347e055..99bf05d 100644
--- a/src/chrome.js
+++ b/src/chrome.js
@@ -1,7 +1,7 @@
// Launches headless Chrome on the real GPU and talks to it over the DevTools protocol (no dependency: Node's WebSocket).
import { spawn } from 'node:child_process';
-import { existsSync, mkdtempSync, rmSync } from 'node:fs';
-import { tmpdir } from 'node:os';
+import { existsSync, mkdtempSync, readdirSync, rmSync } from 'node:fs';
+import { homedir, tmpdir } from 'node:os';
import { join } from 'node:path';
const CANDIDATES = [
@@ -12,9 +12,40 @@ const CANDIDATES = [
'/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser',
];
+// Playwright downloads Chrome for Testing into chromium-<revision> folders in its own cache (or PLAYWRIGHT_BROWSERS_PATH),
+// so a machine set up for Playwright has a Chrome without a system install. Folder and file names are the ones in
+// Playwright's registry (packages/playwright-core/src/server/registry/index.ts). Its chromium_headless_shell folders are
+// left out: that is the old headless mode, and motlab runs --headless=new.
+const PLAYWRIGHT_EXE = {
+ 'linux-x64': ['chrome-linux64', 'chrome'],
+ 'linux-arm64': ['chrome-linux-arm64', 'chrome'],
+ 'darwin-x64': ['chrome-mac-x64', 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing'],
+ 'darwin-arm64': ['chrome-mac-arm64', 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing'],
+ 'win32-x64': ['chrome-win64', 'chrome.exe'],
+};
+
+function playwrightDir() {
+ const env = process.env.PLAYWRIGHT_BROWSERS_PATH;
+ if (env === '0') return null; // the browsers sit inside one project's node_modules
+ if (env) return env;
+ const home = homedir();
+ if (process.platform === 'win32') return join(process.env.LOCALAPPDATA || join(home, 'AppData', 'Local'), 'ms-playwright');
+ if (process.platform === 'darwin') return join(home, 'Library', 'Caches', 'ms-playwright');
+ return join(process.env.XDG_CACHE_HOME || join(home, '.cache'), 'ms-playwright');
+}
+
+// The newest Playwright Chromium in dir that has its executable, or null.
+export function playwrightChrome(dir = playwrightDir(), platform = `${process.platform}-${process.arch}`) {
+ const exe = PLAYWRIGHT_EXE[platform];
+ if (!dir || !exe) return null;
+ let names; try { names = readdirSync(dir); } catch { return null; }
+ return names.map(n => /^chromium-(\d+)$/.exec(n)).filter(Boolean).sort((a, b) => b[1] - a[1])
+ .map(m => join(dir, m[0], ...exe)).find(p => existsSync(p)) ?? null;
+}
+
export function findChrome(explicit) {
- const path = explicit || process.env.CHROME || CANDIDATES.find(p => existsSync(p));
- if (!path || !existsSync(path)) throw new Error('Chrome not found. Pass --chrome <path> or set CHROME=/path/to/chrome');
+ const path = explicit || process.env.CHROME || CANDIDATES.find(p => existsSync(p)) || playwrightChrome();
+ if (!path || !existsSync(path)) throw new Error("Chrome not found (also looked for Playwright's Chromium). Pass --chrome <path> or set CHROME=/path/to/chrome");
return path;
}
diff --git a/test/chrome.test.js b/test/chrome.test.js
index ede01e8..df9eb03 100644
--- a/test/chrome.test.js
+++ b/test/chrome.test.js
@@ -1,10 +1,31 @@
// Chrome's launch flags: --no-sandbox is added when, and only when, motlab
-// runs as root, because Chrome refuses to start as root without it.
+// runs as root, because Chrome refuses to start as root without it. And the
+// Chromium that Playwright downloads is found when there is no system Chrome.
import assert from 'node:assert/strict';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
import { test } from 'node:test';
-import { SANDBOX_FLAGS } from '../src/chrome.js';
+import { SANDBOX_FLAGS, playwrightChrome } from '../src/chrome.js';
test('--no-sandbox is passed exactly when running as root', () => {
const root = typeof process.getuid === 'function' && process.getuid() === 0;
assert.deepEqual(SANDBOX_FLAGS, root ? ['--no-sandbox'] : []);
});
+
+test("Playwright's newest Chromium is found, by revision number, and only where its executable is", () => {
+ const dir = mkdtempSync(join(tmpdir(), 'motlab-pw-'));
+ try {
+ const exe = (folder, ...rest) => { const p = join(dir, folder, ...rest); mkdirSync(dirname(p), { recursive: true }); writeFileSync(p, ''); return p; };
+ exe('chromium-999', 'chrome-linux64', 'chrome');
+ const newest = exe('chromium-1248', 'chrome-linux64', 'chrome');
+ mkdirSync(join(dir, 'chromium-1300')); // an unfinished download: no executable
+ exe('chromium_headless_shell-1400', 'chrome-headless-shell-linux64', 'chrome-headless-shell');
+ assert.equal(playwrightChrome(dir, 'linux-x64'), newest); // 1248 beats 999 as a number, not as text
+ assert.equal(playwrightChrome(dir, 'win32-x64'), null); // the Linux build is not used on Windows
+ const win = exe('chromium-1248', 'chrome-win64', 'chrome.exe');
+ assert.equal(playwrightChrome(dir, 'win32-x64'), win);
+ assert.equal(playwrightChrome(join(dir, 'missing'), 'linux-x64'), null);
+ assert.equal(playwrightChrome(dir, 'freebsd-x64'), null);
+ } finally { rmSync(dir, { recursive: true, force: true }); }
+});