#!/bin/sh # tools/harness.sh: the playback regression run. Appends tools/harness.html's script to index.html, runs it in headless # Chrome with autoplay allowed, prints one state line per step. Needs Chrome/Chromium and python3. set -eu cd "$(dirname "$0")/.." CHROME=${CHROME:-} for c in "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" "$(command -v chromium || true)" "$(command -v google-chrome || true)"; do if [ -z "$CHROME" ] && [ -n "$c" ] && [ -x "$c" ]; then CHROME=$c; fi done [ -n "$CHROME" ] || { echo "no Chrome found; set CHROME" >&2; exit 1; } out=$(mktemp -d) python3 - "$out" <<'EOF' import sys, pathlib out = pathlib.Path(sys.argv[1]) page = pathlib.Path("index.html").read_text() h = pathlib.Path("tools/harness.html").read_text() script = h[h.index(""):] (out / "run.html").write_text(page.replace("", script + "")) EOF # shellcheck disable=SC2086 "$CHROME" --headless=new --disable-gpu --autoplay-policy=no-user-gesture-required --virtual-time-budget=25000 ${CHROME_FLAGS:-} --dump-dom "file://$out/run.html" 2>/dev/null > "$out/dom.html" || true python3 - "$out/dom.html" <<'EOF' import sys, re, html s = open(sys.argv[1]).read() m = re.search(r'
(.*?)
', s, re.S) print(html.unescape(m.group(1)) if m else "no diag: the harness did not run") EOF rm -rf "$out"