Skip to content

fix(browser): resolve Playwright Chromium launch failure (#4060) - #4066

Merged
mrveiss merged 2 commits into
Dev_new_guifrom
fix/browser-playwright-launch-4060
Apr 10, 2026
Merged

mrveiss merged 2 commits into
Dev_new_guifrom
fix/browser-playwright-launch-4060

Conversation

@mrveiss

@mrveiss mrveiss commented Apr 10, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #4060 - Playwright Chromium browser fails to launch after service starts.

Three root causes identified and fixed:

  • Env var name mismatch (primary cause): The systemd service unit set HEADLESS_MODE={{ headless_mode }} but playwright-server.js reads process.env.HEADLESS !== 'false'. Since HEADLESS was never set, it evaluated to undefined !== 'false' = true, forcing headless mode regardless of the headless_mode Ansible variable. When the service was deployed with headless_mode: false (the default), the browser was expected to run headed against the VNC DISPLAY but actually ran headless — and on WSL2 without a proper X11 display configured for headless Chromium, the launch failed. Fixed playwright.service.j2 to set HEADLESS={{ headless_mode | lower }}, consistent with the .env template that has always used the correct variable name.

  • Duplicate route/function registrations: ensureNavPage, captureNavScreenshot, and five routes (/status, /navigate, /screenshot, /back, /forward, /reload) were all registered twice. The second block (labeled "Persistent navigation page for BrowserTool Issue fix(browser): SLM browser tool broken - missing backend routes and worker endpoints #1120") was an accidental duplicate left over from a prior refactor. In Node.js, the second function declaration silently overwrites the first; in Express, both route handler callbacks are registered and the first one runs. This caused the first (correct) set of handlers to run while the dead second set stayed in memory. Removed the entire duplicate block.

  • Opaque error logging: logger.error('Failed to launch browser:', error) serialized the Playwright error object via JSON.stringify, producing {"name":"Error"} with no diagnostic detail. Changed to log error.message and error.stack so the real Chromium failure reason appears in the journal.

Files changed

  • autobot-browser-worker/playwright-server.js — fix error logging, remove 101-line duplicate route block
  • autobot-slm-backend/ansible/roles/browser/templates/playwright.service.j2 — set HEADLESS (not HEADLESS_MODE) with lowercase value

Test plan

  • Deploy browser worker to target host via Ansible browser role
  • Confirm journalctl -u autobot-playwright shows "Browser launched successfully" on startup
  • Confirm curl http://<browser-host>:3000/health returns browser_connected: true
  • With headless_mode: false, confirm HEADLESS=false appears in systemctl show autobot-playwright --property=Environment
  • With headless_mode: true, confirm browser launches headless with no DISPLAY dependency

🤖 Generated with Claude Code

mrveiss and others added 2 commits April 10, 2026 07:48
… to Node.js/Express (#4062)

Replace outdated uvicorn (Python) configuration with current Node.js/Express
implementation. Update environment variables, ExecStart command, restart policy,
and file paths to match actual deployment. Uses EnvironmentFile for
configuration instead of hardcoded values.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…e starts (#4060)

Three root causes fixed:
1. Env var name mismatch: systemd service used HEADLESS_MODE but playwright-server.js
   reads process.env.HEADLESS, causing it to always evaluate as undefined (truthy for
   headless) regardless of the headless_mode config value. Fixed playwright.service.j2
   to set HEADLESS={{ headless_mode | lower }}, consistent with the .env template.
2. Duplicate route/function registrations: ensureNavPage, captureNavScreenshot, /status,
   /navigate, /screenshot, /back, /forward, and /reload were all registered twice.
   The second block (Issue #1120 section) was an accidental duplicate of the first block
   (lines 81-188) that survived a refactor. Removed the duplicate block entirely.
3. Opaque error logging: initBrowser catch logged the error object as JSON which
   serializes to {"name":"Error"} with no message. Fixed to log error.message and stack.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No hardcoded values detected that have SSOT config equivalents!

@mrveiss
mrveiss merged commit 6f3fdaa into Dev_new_gui Apr 10, 2026
4 of 5 checks passed
@mrveiss
mrveiss deleted the fix/browser-playwright-launch-4060 branch April 10, 2026 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant