fix: auto-install Playwright Chromium in setup (PR #22)

Setup now verifies Playwright can launch Chromium, and auto-installs
it via `bunx playwright install chromium` if missing. Exits non-zero
if build or Chromium launch fails.

Credit: AkbarDevop (PR #22)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-03-12 20:29:09 -07:00
parent 5645839186
commit da7ec213e2
+29 -2
View File
@@ -4,14 +4,41 @@ set -e
GSTACK_DIR="$(cd "$(dirname "$0")" && pwd)"
SKILLS_DIR="$(dirname "$GSTACK_DIR")"
BROWSE_BIN="$GSTACK_DIR/browse/dist/browse"
ensure_playwright_browser() {
(
cd "$GSTACK_DIR"
bun --eval 'import { chromium } from "playwright"; const browser = await chromium.launch(); await browser.close();'
) >/dev/null 2>&1
}
# 1. Build browse binary if needed
if [ ! -x "$GSTACK_DIR/browse/dist/browse" ]; then
if [ ! -x "$BROWSE_BIN" ]; then
echo "Building browse binary..."
cd "$GSTACK_DIR" && bun install && bun run build
fi
# 2. Only create skill symlinks if we're inside a .claude/skills directory
if [ ! -x "$BROWSE_BIN" ]; then
echo "gstack setup failed: browse binary not found at $BROWSE_BIN" >&2
exit 1
fi
# 2. Ensure Playwright's Chromium is available
if ! ensure_playwright_browser; then
echo "Installing Playwright Chromium..."
(
cd "$GSTACK_DIR"
bunx playwright install chromium
)
fi
if ! ensure_playwright_browser; then
echo "gstack setup failed: Playwright Chromium could not be launched" >&2
exit 1
fi
# 3. Only create skill symlinks if we're inside a .claude/skills directory
SKILLS_BASENAME="$(basename "$SKILLS_DIR")"
if [ "$SKILLS_BASENAME" = "skills" ]; then
linked=()