fix(vnc-watcher): detect Xvfb display when launched with -displayfd - #5243
Closed
paranoidi wants to merge 1 commit into
Closed
fix(vnc-watcher): detect Xvfb display when launched with -displayfd#5243paranoidi wants to merge 1 commit into
paranoidi wants to merge 1 commit into
Conversation
The VNC watcher's awk regex /:Xvfb :[0-9]+/ only matched Xvfb launched with a hardcoded display number (e.g. 'Xvfb :0'). The camoufox-js VirtualDisplay class uses -displayfd 3 (dynamic display assignment), so the watcher never found the display and x11vnc never started, causing noVNC to fail with 'Connection refused'. Replace the inline awk with a detect_display() function that tries three fallbacks: 1. Xvfb with hardcoded :N display in argv 2. /tmp/.X*-lock files (traditional lock file) 3. /tmp/.X11-unix/X* sockets With the fix, the watcher successfully detects ':0' in -displayfd mode and attaches x11vnc, making noVNC work. Guard x11vnc command with || true so set -e doesn't kill watcher. Remove set -e so watcher survives x11vnc failures.
|
This was also an issue for me with noVNC.html and was resolved in a similar way. My agent performed similar fixes plus a few additions so I ran it against your PR to combine. From PR #5243 (paranoidi):
My additions:
|
gearwave00001
added a commit
to gearwave00001/camofox-browser
that referenced
this pull request
Jul 9, 2026
…info polling Three bugs caused noVNC to show 'failed to connect to server' after the browser goes idle and restarts: 1. Display detection — Xvfb launched with -displayfd 3 has no display number in argv, so the original awk regex never matched. Replace with detect_display() that falls back to /tmp/.X*-lock and /tmp/.X11-unix/X* sockets. 2. XIO error crash — x11vnc connects before Xvfb is fully ready and crashes silently (masked by -bg). Poll xdpyinfo for up to 5 seconds before starting x11vnc. Also remove -noxdamage which can cause issues with some Xvfb configs. 3. Stale PID tracking — After x11vnc dies, CURRENT_DISPLAY stays set so the attach block is skipped on every subsequent loop. Add a heartbeat check at the top of each loop that detects dead x11vnc and clears CURRENT_DISPLAY for re-attach. Also clear on pgrep failure after start. Remove set -e so the watcher survives x11vnc failures. Replace with || true guards and explicit retry logic. Based on upstream PR jo-inc#5243 (covers bugs 1-2) plus bug 3 which is not covered by any open PR.
gearwave00001
pushed a commit
to gearwave00001/camofox-browser
that referenced
this pull request
Jul 12, 2026
… and launch stability Combines fixes from two open upstream PRs and adds coverage improvements neither addresses: From jo-inc#6788 (mavolty) — server.js: - await VirtualDisplay.get() — missing await passed a Promise object as the display string, so the browser launched headed with no display ("cannot open display") even though Xvfb was running. One-word fix. - viewport: null in newContext() — Playwright >=1.58 sends isMobile in Browser.setDefaultViewport, which Camoufox v135's Juggler protocol rejects. Passing null skips setDefaultViewport entirely; per-page setViewportSize() handles sizing. - DefaultVirtualDisplay subclass patches Xvfb resolution to 1280x720x24 so pages still render at the expected size without a context-level viewport (which is now null). From jo-inc#5243 (paranoidi) — vnc-watcher.sh: - detect_display() with 3 fallbacks (argv scan, /tmp/.X*-lock files, /tmp/.X11-unix/X* sockets) replaces the broken awk regex that only matched Xvfb launched with a hardcoded :N display. Camoufox uses -displayfd 3 (dynamic assignment), so the old regex never matched and x11vnc never started. Improvements beyond both PRs: - Heartbeat check: each loop iteration verifies x11vnc is still alive and clears stale PID/display state when it dies. Neither jo-inc#5243 nor jo-inc#6788 addresses this — without it, the watcher loses track of a crashed x11vnc and never re-attaches, leaving noVNC permanently disconnected. This is the bug that made multi-tab sessions unreliable (x11vnc dies on browser restart, watcher never recovers). - xdpyinfo polling (5s) before starting x11vnc prevents XIO error crashes when Xvfb hasn't finished accepting connections. - Removed set -e so the watcher survives x11vnc failures instead of exiting. Replaced -bg with foreground background (&) plus PID verification via $! so failures are visible and stale PIDs aren't recorded. - killall x11vnc before starting a new instance to avoid port conflicts on re-attach. Also: - Add docker-compose.yaml with NODE_OPTIONS=--max-old-space-size=4096 (fixes JS heap OOM that killed the server on memory-heavy pages), ENABLE_VNC=1, and VNC_BIND=0.0.0.0 for remote access. - Add launchCompat.test.js to prevent regression on the await and viewport: null fixes. - Drop executable bit on non-script files (bin/camofox-browser.js, release.sh, etc.) that were incorrectly mode 755. Closes issues from jo-inc#5243, jo-inc#6788, and jo-inc#5916. Builds on mvanhorn's fixes (jo-inc#5042, jo-inc#5040) for postinstall env whitelist, ENABLE_VNC=1 honor, and BROWSER_IDLE_TIMEOUT_MS=0 support.
skyfallsin
added a commit
that referenced
this pull request
Jul 19, 2026
Incorporates the VNC attachment and recovery work proposed in #4781, #5243, #6549, and #8070 while preserving per-server process ownership. Co-authored-by: Doud-FR <59610009+Doud-FR@users.noreply.github.com> Co-authored-by: paranoidi <504877+paranoidi@users.noreply.github.com> Co-authored-by: Omar Usman <19397228+modanq@users.noreply.github.com> Co-authored-by: luxles <291718194+luxles@users.noreply.github.com>
Contributor
|
Thank you — support for Xvfb launched with Included via commit 50b5031 with co-author credit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disclaimer: PR made with AI but I verified locally that it fixes the issue for me.
Bug Description
When Camofox runs with VNC enabled (ENABLE_VNC=1), noVNC fails with "Failed to connect to 127.0.0.1:5900: Connection refused" because x11vnc never starts. The VNC watcher script loops forever unable to detect the Xvfb display.
Root Cause
The VNC watcher script uses the awk regex /\Xvfb :[0-9]+/ to find Xvfb, which only matches when Xvfb is launched with a hardcoded display number (e.g. Xvfb :0 -screen ...). The camoufox-js VirtualDisplay class launches Xvfb with -displayfd 3 (dynamic display assignment), so the command line looks like Xvfb -displayfd 3 -screen ... — no :0 in argv. The watcher never finds it, x11vnc never attaches, and noVNC stays permanently disconnected.
Fix
Replace the inline awk detection with a detect_display() function that tries three fallbacks in order:
How to Verify