bridges: prime the Playwright browser over IPv4 when the downloader hangs

`playwright install chromium` failed on this host even though the CDN is
reachable. Root cause is Node, not the network: Playwright's bundled downloader
forces `autoSelectFamily` with a custom dual-stack resolver that resolves
`[6, 4]` and interleaves IPv6 first, and this box has an IPv6 address (a ULA)
with no global IPv6 route, so the first IPv6 connection blackholes and Node never
falls back to IPv4 -- the download stalls to the socket timeout. Raising
`PLAYWRIGHT_DOWNLOAD_CONNECTION_TIMEOUT` only moved the hang from 30s to 600s;
`curl -4` fetches the same artifact at ~6 MB/s.

Playwright skips a browser whose directory holds an `INSTALLATION_COMPLETE`
marker, so prime the cache over IPv4 and the normal install becomes a no-op.

- `scripts/playwright-browsers.py`: reads the chromium/headless-shell/ffmpeg
  revisions and Chrome-for-Testing versions from Playwright's own
  `browsers.json`, downloads those exact artifacts with `curl -4`, extracts them
  into `PLAYWRIGHT_BROWSERS_PATH/<name>-<revision>/`, and writes the marker.
  Idempotent; prefers `unzip`, falls back to `zipfile` + chmod.
- `bootstrap.sh --browser`: if `playwright install` fails for chromium, fall
  back to the helper (firefox/webkit just warn).

Verified live: after priming, `playwright install chromium` exits 0 and the
browser bridge drives a real Chromium (goto/content/text/links/fill/select/
screenshot) over HTTP.
This commit is contained in:
gabby committed 2026-10-11 09:45:31 +00:00
1 parent 6240392632
commit e4961ef492
4 files changed
+199 -3

No files matched your search

+16 -2
View File
@@ -384,8 +384,22 @@ PY
)"
case "$BROWSER_ENGINE" in chromium|firefox|webkit) ;; *) BROWSER_ENGINE=chromium ;; esac
echo "== downloading Playwright browser '$BROWSER_ENGINE' into $BROWSERS"
PLAYWRIGHT_BROWSERS_PATH="$BROWSERS" "$PYTHON" -m playwright install "$BROWSER_ENGINE" \
|| echo "WARN: playwright browser download failed; re-run: PLAYWRIGHT_BROWSERS_PATH=$BROWSERS $PYTHON -m playwright install $BROWSER_ENGINE" >&2
if ! PLAYWRIGHT_BROWSERS_PATH="$BROWSERS" "$PYTHON" -m playwright install "$BROWSER_ENGINE"; then
echo "WARN: 'playwright install' failed" >&2
if [[ "$BROWSER_ENGINE" = chromium ]]; then
# Playwright's own downloader prefers IPv6 (autoSelectFamily + a custom
# dual-stack resolver) and can hang on a host that has an IPv6 address but
# no working global IPv6 route, even though the CDN serves over IPv4. The
# helper fetches the same pinned artifacts over IPv4 and lays them out
# where Playwright expects them, so the install becomes a no-op.
echo "== retrying over IPv4 (scripts/playwright-browsers.py)" >&2
PLAYWRIGHT_BROWSERS_PATH="$BROWSERS" "$PYTHON" "$REPO_ROOT/scripts/playwright-browsers.py" \
--browsers-path "$BROWSERS" --engine "$BROWSER_ENGINE" \
|| echo "WARN: browser priming failed; re-run: $PYTHON scripts/playwright-browsers.py --browsers-path $BROWSERS" >&2
else
echo "WARN: re-run: PLAYWRIGHT_BROWSERS_PATH=$BROWSERS $PYTHON -m playwright install $BROWSER_ENGINE" >&2
fi
fi
fi
# --- stage 4: GGUF --------------------------------------------------------------