← Commit history

Robust observer-proof window resolution via UNIQUE-WIDTH WIGGLE (finally kills the dup-hwnd bug for all windows, clean titles kept). With titleTag off, the transient-title approach was fought by each page's own title observer (un-disconnectable on pre-1.9.288 pages), so same-profile windows parked at the identical rect collapsed onto one hwnd. New approach: when the tag is off, pup gives the window being resolved a UNIQUE width via CDP Browser.setWindowBounds (pup controls this directly, no page script can fight it), matches the one OS window at that exact width, then restores - deterministic and unambiguous even for many same-profile windows. Guarded to never resize a foreground window the user is looking at (falls back to plain bounds there); the window is off-screen during most resolves so the width change is invisible. Title-tag-ON path still uses the exact persistent-tag find. Together with the reconciler's duplicate-hwnd self-heal (clears any shared cache to force re-resolve), every window binds to its own unique handle.

John Lauer ·118b092958 ·3mo ago ·parent dad513c
5 files changed +46−36
adom-bridge-puppeteer-manifest.json+4−4
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "1.9.289",-  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.289/adom-bridge-puppeteer-v1.9.289.zip",-  "sha256": "dd051ef5632d23486e05608eb904f7e1525c3b6d612894747c3282cdb055501c",-  "size": 718323,+  "version": "1.9.290",+  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.290/adom-bridge-puppeteer-v1.9.290.zip",+  "sha256": "778ee857d33aecb4a2dfc8318d371e9b99fedbbd717223dda565cf521d6c2358",+  "size": 718536,   "verbPrefixes": [     "browser_",     "desktop_recorder_",
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-1.9.289+1.9.290
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "1.9.289",+  "version": "1.9.290",   "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/package.json+2−2
@@ -1,7 +1,7 @@ {   "name": "adom-puppeteer-bridge",-  "version": "1.0.0",-  "description": "Puppeteer Bridge — persistent browser instance for visual debugging via Adom Desktop",+  "version": "1.9.289",+  "description": "Puppeteer Bridge \u2014 persistent browser instance for visual debugging via Adom Desktop",   "main": "server.js",   "scripts": {     "start": "node server.js"
src/server.js+38−28
@@ -4810,37 +4810,39 @@ async function resolveSessionHwndByBounds(session, sessionId) {     // matching cannot distinguish windows after a restart and misassigns hwnds. The title tag is     // exact where it exists - resolve by title FIRST; geometry stays as the fallback for windows     // that cannot carry the tag (PDF viewer).-    try {-      // v1.9.286: with titleTag OFF the visible title has no tag, so TRANSIENTLY add it, resolve,-      // then strip it. The window is parked off-screen during most resolves, so the tag flash is-      // usually invisible; either way it lasts only the ~1s of the find. window.name stays the-      // durable identity. When titleTag is ON, the tag is already persistent — no transient dance.-      const _transient = pupSettings().titleTag !== 'on';-      const _atab = (session.tabs || []).find(t => t.tabId === session.activeTabId) || (session.tabs || [])[0];-      if (_transient) session._resolvingHwnd = true;   // v1.9.288: keep the reconciler from stripping the transient tag mid-find-      if (_transient && _atab && _atab.page) {-        try { await _atab.page.evaluate((sfx) => { try { if (String(document.title).indexOf(sfx) === -1) document.title = String(document.title || '') + sfx + ')'; } catch (e) {} }, ` (${TITLE_LABEL}: ${sessionId}`); } catch (e) {}-      }+    // titleTag ON: the persistent "(ai-thread: X)" suffix is the exact, reliable resolver. When OFF+    // we skip straight to the unique-width geometry wiggle below (observer-proof; the transient TITLE+    // approach was fought by the page's own title observer, collapsing same-profile windows onto one+    // hwnd — John's dup-handle bug).+    if (pupSettings().titleTag === 'on') try {       const fw = adPayload(await chrome.adCommand('desktop_find_window', { titleContains: `(${TITLE_LABEL}: ${sessionId}` }, { timeoutMs: 5000, caller: sessionCaller(session) }));       const b = fw && (fw.best || (fw.data && fw.data.best));-      if (_transient && _atab && _atab.page) {-        try { const esc = sessionId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); await _atab.page.evaluate((re) => { try { document.title = String(document.title || '').replace(new RegExp(re, 'g'), ''); } catch (e) {} }, `\\s*\\((?:session|ai-thread): ${esc}(?:[^)]*)\\)`); } catch (e) {}-      }-      session._resolvingHwnd = false;-      if (b && b.hwnd) { session._hwnd = Number(b.hwnd); console.log(`[hwnd] "${sessionId}" resolved by ${_transient ? 'TRANSIENT tag' : 'TITLE tag'} -> ${b.hwnd}`); return Number(b.hwnd); }+      if (b && b.hwnd) { session._hwnd = Number(b.hwnd); console.log(`[hwnd] "${sessionId}" resolved by TITLE tag -> ${b.hwnd}`); return Number(b.hwnd); }     } catch (e) {}     const page = (session.tabs || [])[0] && (session.tabs || [])[0].page;     if (!page) return null;-    let bounds = null, cdp = null;+    // v1.9.290 UNIQUE-WIDTH WIGGLE: parked windows share the identical rect, so plain geometry can't+    // tell two same-profile windows apart (dup-hwnd bug). Give THIS window a UNIQUE width via CDP+    // (pup controls it directly — no page observer can fight it), match on that exact width, restore.+    let bounds = null, cdp = null, windowId = null, markerW = null;     try {       cdp = await page.target().createCDPSession();-      const { windowId } = await cdp.send('Browser.getWindowForTarget');+      ({ windowId } = await cdp.send('Browser.getWindowForTarget'));       ({ bounds } = await cdp.send('Browser.getWindowBounds', { windowId }));-    } catch (e) { return null; } finally { try { if (cdp) await cdp.detach(); } catch (e) {} }-    if (!bounds || !Number.isFinite(bounds.width)) return null;+    } catch (e) { try { if (cdp) await cdp.detach(); } catch (x) {} return null; }+    if (!bounds || !Number.isFinite(bounds.width)) { try { if (cdp) await cdp.detach(); } catch (x) {} return null; }     const be = browsers.get(session.profileName);     const pid = be && be.browser && (be.browser._detachedPid || (() => { try { return be.browser.process()?.pid; } catch (e) { return null; } })());-    if (!pid) return null;+    if (!pid) { try { if (cdp) await cdp.detach(); } catch (x) {} return null; }+    const _origW = bounds.width;+    // Never resize a window the USER is looking at (foreground) — fall back to plain bounds match there.+    if (!session._foreground) {+      try {+        markerW = Math.max(400, Math.round(_origW) - 3 - (_hwndWiggle++ % 90));   // unique among concurrent resolves+        await cdp.send('Browser.setWindowBounds', { windowId, bounds: { width: markerW } });+        await new Promise(r => setTimeout(r, 140));+      } catch (e) { markerW = null; }+    }     const scriptPath = path.join(require('os').tmpdir(), `_adom_hwnd_${process.pid}.ps1`);     // CSS bounds -> physical px via the DPI scale, then match a top-level window of ANY chrome.exe     // in this profile's process tree by position (a small tolerance absorbs frame/DPI rounding).@@ -4880,18 +4882,25 @@ async function resolveSessionHwndByBounds(session, sessionId) {     for (const line of out.split(/\r?\n/)) {       const [h, , L, T, W, H] = line.split(',').map(Number);       if (!h || !Number.isFinite(W)) continue;-      // Compare in physical px: CSS * dpiScale. Try common scales so we do not need a DPI probe.       for (const sc of [1, 1.25, 1.5, 1.75, 2]) {-        const dx = Math.abs(L - Math.round(bounds.left * sc));-        const dy = Math.abs(T - Math.round(bounds.top * sc));-        const dw = Math.abs(W - Math.round(bounds.width * sc));-        const score = dx + dy + dw;-        if (dx <= 40 && dy <= 40 && dw <= 60 && (!best || score < best.score)) best = { h, score };+        if (markerW != null) {+          // WIGGLE match: the unique marker width identifies exactly this window (tight tolerance).+          if (Math.abs(W - Math.round(markerW * sc)) <= 4) { best = { h, score: 0 }; break; }+        } else {+          const dx = Math.abs(L - Math.round(bounds.left * sc));+          const dy = Math.abs(T - Math.round(bounds.top * sc));+          const dw = Math.abs(W - Math.round(bounds.width * sc));+          const score = dx + dy + dw;+          if (dx <= 40 && dy <= 40 && dw <= 60 && (!best || score < best.score)) best = { h, score };+        }       }+      if (best && best.score === 0) break;     }+    try { if (markerW != null) await cdp.send('Browser.setWindowBounds', { windowId, bounds: { width: _origW } }); } catch (e) {}+    try { if (cdp) await cdp.detach(); } catch (e) {}     if (best) {       session._hwnd = best.h;-      console.log(`[hwnd] "${sessionId}" resolved OS handle ${best.h} by window BOUNDS (no title tag needed) — taskbar paint + park can now target it`);+      console.log(`[hwnd] "${sessionId}" resolved OS handle ${best.h} by ${markerW != null ? 'UNIQUE-WIDTH wiggle' : 'window BOUNDS'} — taskbar paint + park can target it`);       return best.h;     }     return null;@@ -6390,6 +6399,7 @@ async function flashViaAD(sessionId, opts) {   catch (e) { return null; } } const _flashedHwnds = new Set(); // every hwnd pup ever flashed this boot — the clear-all sweep list+let _hwndWiggle = 0;   // v1.9.290: monotonic-ish counter for unique resolution widths // v1.9.243 (John: "i just hit clear flashes again and it still didn't clear"). Per-boot bookkeeping // was the hole: a bridge restart (every ship) empties the set while the taskbar keeps its orange, so // clear-all had nothing to sweep. Bookkeeping across restarts is inherently fragile — so DON'T rely