okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221rc1 merge tui-update (3165c2e8a)a1cc285fa

main
2.1 KiB54 linesraw
1/**
2 * Where the Chromium binary the probes drive actually lives.
3 *
4 * The probes launched a fixed macOS cache path, so on Windows and Linux they
5 * printed "No cached Chromium found" and every runtime gate (contrast, measure,
6 * luminance, motion) was skipped rather than run. Resolution is now a single
7 * place with the same order everywhere:
8 *
9 *   1. STRATA_CHROME — an explicit override, for a CI image or a second Chrome
10 *   2. the cached Playwright build (macOS, the original platforms)
11 *   3. an installed browser: Chrome, Edge, Chromium
12 *
13 * `requireChromium` exits with the harness message the scripts already used, so
14 * a machine with no browser at all still fails loudly instead of silently
15 * passing a gate.
16 */
17import { existsSync } from 'node:fs';
18import { join } from 'node:path';
19import { homedir } from 'node:os';
20
21const PLAYWRIGHT_MAC = [
22  join(homedir(), 'Library/Caches/ms-playwright/chromium-1234/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing'),
23  join(homedir(), 'Library/Caches/ms-playwright/chromium_headless_shell-1234/chrome-headless-shell-mac-arm64/chrome-headless-shell'),
24];
25
26const INSTALLED = [
27  // Windows
28  'C:/Program Files/Google/Chrome/Application/chrome.exe',
29  'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe',
30  'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
31  'C:/Program Files/Microsoft/Edge/Application/msedge.exe',
32  // macOS
33  '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
34  '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
35  // Linux
36  '/usr/bin/google-chrome',
37  '/usr/bin/google-chrome-stable',
38  '/usr/bin/chromium',
39  '/usr/bin/chromium-browser',
40];
41
42export function findChromium() {
43  const candidates = [process.env.STRATA_CHROME, ...PLAYWRIGHT_MAC, ...INSTALLED].filter(Boolean);
44  return candidates.find((path) => existsSync(path)) ?? null;
45}
46
47export function requireChromium() {
48  const path = findChromium();
49  if (!path) {
50    console.error('No Chromium found. Set STRATA_CHROME, or install Chrome, Edge or Chromium.');
51    process.exit(2);
52  }
53  return path;
54}