← Commit history

Fix wiki #468 (Drew: pup 100% unusable, 'never bound its port'). ROOT CAUSE: the heavy native requires (puppeteer, keytar via credential_vault, sharp, and chrome.js which itself requires puppeteer) ran synchronously at module load, blocking the event loop ~8s before the HTTP port could bind — long after AD's recover_not_listening reaps a not-yet-bound bridge (~2-3.6s). FIX: defer all four out of the sync module-load path into ensureHeavyInit(), which runs in the listen callback AFTER the port binds (recover_not_listening is a TCP listen check, so the post-bind load is safe) plus lazily on the first non-/health request. /health needs no heavy module (chrome.readiness guarded). Port now binds in <1s.

John Lauer ·f07bd87b6f ·3mo ago ·parent 3581702
4 files changed +36−15
adom-bridge-puppeteer-manifest.json+4−4
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "1.9.333",-  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.333/adom-bridge-puppeteer-v1.9.333.zip",-  "sha256": "4fd2876b09e03a059339ddf191fcf664a3fd6af63f4016304d45fa9dfc4ecf3c",-  "size": 625701,+  "version": "1.9.334",+  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.334/adom-bridge-puppeteer-v1.9.334.zip",+  "sha256": "2a9340102ab08c90f83d296dc4ddb0b01a15024ffaaaf7ce4d64a548fada6bf7",+  "size": 626470,   "verbPrefixes": [     "browser_",     "desktop_recorder_",
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-1.9.333+1.9.334
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "1.9.333",+  "version": "1.9.334",   "description": "Drives a browser ALREADY on the machine \u2014 installed Chrome, else Microsoft Edge (every Windows PC ships with Edge) \u2014 launched with a FRESH isolated profile, so the common case has NO ~150 MB Chrome-for-Testing download and it never touches the user's real tabs/logins. Binds its local server to LOOPBACK (127.0.0.1) only, so no Windows Firewall 'allow Node through the firewall' prompt ever pops. Chrome for Testing is fetched only as a LAST RESORT if the machine has no Chromium browser at all. SPAWN-VERIFIED fallback: pup tries each detected browser (Chrome \u2192 Edge \u2192 CfT) and actually launches it, falling through to the next if one won't start (and handling browsers like Edge that relaunch onto another PID), so a corrupt/partial install never hard-fails an open. The browser that launches is cached as the default (persisted across restarts) so it isn't re-probed each time. On spawn the bridge SELF-WARMS: detects browsers + disk, and only if the box has no Chrome/Edge and no cached CfT does it background-fetch CfT so the first open is instant. browser_use pins a specific browser (chrome | edge | cft | auto); {browser:'chrome',install:true} downloads & installs REAL Google Chrome (user-scoped, no admin) on an Edge-only box. browser_readiness (READ-ONLY) reports which browser will be used + the full candidate list + the default + free disk. Every failure returns a specific errorCode + _hint (chrome_install_no_disk, chrome_download_network, chrome_install_permission, chrome_stable_not_detected, \u2026). Launches with FULL browser permissions by default for full debug (strictPermissions:true opts out). Headful automation: open/close windows+tabs, navigate, screenshot, eval JS, record. pup is a GENERIC, non-profile browser only \u2014 every session is a fresh isolated Chrome/Edge process, never the user's real signed-in browser; profile defaults to sessionId. To drive the user's REAL Chrome/Edge (their profile, cookies, SSO), use the Adom browser EXTENSION's nbrowser_* verbs \u2014 a separate bridge, not pup's job. macOS (v1.9.74+): full parity with mac-native mechanics \u2014 background-by-default is the app-level hide (windows stay drivable/screenshottable while hidden), raise/lower map to unhide+activate/hide, browser_alert_window posts a native toast whose click focuses the window, browser_use {browser:'chrome',install:true} installs Chrome from the official dmg, and taskbar identity/badging remains Windows-only.",   "homepage": "https://wiki.adom.inc/adom/adom-desktop",   "author": "Adom Inc.",
src/server.js+30−9
@@ -141,11 +141,26 @@ function ensureDepsInstalled() {     }   } }-const _depState = ensureDepsInstalled();--const puppeteer = require('puppeteer');-const credentialVault = require('./credential_vault');-const chrome = require('./chrome'); // Chrome-for-Testing self-heal: detect / auto-install / readiness (cold-start fix)+// v1.9.334 (wiki issue #468 — Drew: pup "never bound its port", 100% unusable). The heavy NATIVE+// requires below (puppeteer, keytar via credential_vault, sharp, and chrome.js — which itself requires+// puppeteer) block the event loop for ~8s at module load, so the HTTP port only bound at ~8s, long+// after AD's recover_not_listening reaps a not-yet-bound bridge (~2-3.6s). FIX: DEFER them out of the+// SYNCHRONOUS module-load path. Only light modules load synchronously now → the port binds in <1s, AD+// sees it listening and never reaps, and the ~8s of native loading happens in ensureHeavyInit() AFTER+// the bind (first line of the listen callback, plus lazily on the first non-/health request). /health+// needs no heavy module (its chrome.readiness() is guarded for the pre-init window).+let _depState = null, puppeteer = null, credentialVault = null, chrome = null;+let _heavyInitDone = false;+function ensureHeavyInit() {+  if (_heavyInitDone) return;+  _heavyInitDone = true;+  try { _depState = ensureDepsInstalled(); } catch (e) { _depState = { ok: false, error: e.message }; }+  puppeteer = require('puppeteer');+  credentialVault = require('./credential_vault');+  chrome = require('./chrome'); // Chrome-for-Testing self-heal (also pulls puppeteer internally)+  try { sharp = require('sharp'); }+  catch (e) { console.warn('[pup] sharp unavailable — screenshots served at capture size, not downscaled:', e.message); sharp = null; }+}  // sharp is REQUIRED for resizing screenshots — never send full-res to container. // v1.8.40+: previously this was wrapped in try/catch with a `let sharp = null`@@ -156,9 +171,7 @@ const chrome = require('./chrome'); // Chrome-for-Testing self-heal: detect / au // work without it: we fall back to serving the screenshot at capture size and reading // dimensions from the PNG header. When sharp IS present, we downscale to keep images // under Claude's Read limit (the ideal path). Never let a missing sharp crash the bridge.-let sharp = null;-try { sharp = require('sharp'); }-catch (e) { console.warn('[pup] sharp unavailable — screenshots served at capture size, not downscaled:', e.message); }+let sharp = null;   // v1.9.334: loaded lazily in ensureHeavyInit() (see the #468 deferral above) — never in the sync module-load path const MAX_SCREENSHOT_DIM = 1568; // Claude's optimal max dimension  // PNG width/height straight from the IHDR header (bytes 16-23, big-endian). Pure JS,@@ -9598,6 +9611,10 @@ const server = http.createServer(async (req, res) => {     res.end();     return;   }+  // v1.9.334 (#468): everything except the lightweight /health probe needs the deferred native modules+  // (puppeteer/sharp/keytar/chrome). Load them on first use; /health stays answerable during the ~8s+  // one-time load so AD never mistakes a warming bridge for a wedged one.+  if (pathname !== '/health') ensureHeavyInit();    try {     // GET /health@@ -10022,7 +10039,7 @@ const server = http.createServer(async (req, res) => {         sessionCount: sessions.size,         activeSession: activeSessionId,         sessions: sessionList,-        chrome: chrome.readiness(),+        chrome: (chrome && chrome.readiness) ? chrome.readiness() : { ready: false, initializing: true },       });       return;     }@@ -13742,6 +13759,10 @@ server.keepAliveTimeout = 30_000; const BIND_HOST = process.env.ADOM_BIND_HOST || '127.0.0.1'; server.listen(PORT, BIND_HOST, async () => {   console.log(`Puppeteer Bridge running on http://${BIND_HOST}:${PORT} (bind=${BIND_HOST}; no firewall prompt)`);+  // v1.9.334 (#468): the PORT IS NOW BOUND (this callback fires after the OS bind), so AD already sees+  // the bridge listening and will not reap it. NOW do the heavy native loading that was deferred out of+  // the synchronous module-load path. It blocks briefly, but the port is up, so a reap can't happen.+  ensureHeavyInit();   console.log('Multi-session support: sessions are tabs sharing Chrome profiles via userDataDir');   console.log('Endpoints: /health, /command, /launch, /navigate, /reload, /screenshot, /screenshot.png, /errors, /eval, /wait, /status, /close');   // Self-warm: detect browsers + disk the moment the bridge spawns (right after AD