← Commit history

Fix cross-session hwnd collision (John caught two windows on DIFFERENT profiles sharing one taskbar handle - wildlife-compare on adom-you was wrongly holding hero-studio's hwnd). Root cause: the 1.9.278 ownership guard only proved an hwnd was SOME pup window, not THIS session's window, so a stale/mis-resolved cached hwnd that happened to be another pup window passed validation forever and was never corrected - overlays then painted on the wrong button. Fix: hwndBelongsToPup now takes the session and validates the hwnd's owning pid (or parent) is in THAT session's OWN profile Chrome process; a cross-profile hwnd fails and forces an immediate re-resolve to the correct window. Applied at all three OS-op guards (overlay paint, flash, cached-hwnd reuse). This also surfaced under 1.9.286's clean-title transient resolution, which made mis-resolution more visible. Ralph gained a unique-hwnd guard (no two live windows may resolve to the same handle).

John Lauer ·85a08eef26 ·3mo ago ·parent 18f8d63
4 files changed +22−15
adom-bridge-puppeteer-manifest.json+4−4
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "1.9.286",-  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.286/adom-bridge-puppeteer-v1.9.286.zip",-  "sha256": "18a2667eebcde94dbe1fb1316cacf2b7d69c8f42d0c6fa52070e0f80a637c528",-  "size": 717362,+  "version": "1.9.287",+  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.287/adom-bridge-puppeteer-v1.9.287.zip",+  "sha256": "68099c2e61d0be95ddfb76e21ad85251a657b42a18938d17ff44c6c34edf0397",+  "size": 717595,   "verbPrefixes": [     "browser_",     "desktop_recorder_",
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-1.9.286+1.9.287
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "1.9.286",+  "version": "1.9.287",   "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+16−9
@@ -4489,7 +4489,7 @@ async function applyAppOverlay(session, sessionId) {     // v1.9.278 THE EDGE GUARD: paint ONLY to an hwnd proven to be a pup browser window. If we cannot     // prove ownership (recycled/dead handle), REFUSE - never fall back to a bare title match that     // could hit another app. A missed overlay this cycle self-heals next sweep; painting on Edge does not.-    if (!session._hwnd || !(await hwndBelongsToPup(session._hwnd))) {+    if (!session._hwnd || !(await hwndBelongsToPup(session._hwnd, session))) {       session._hwnd = null; session._appOverlay = false;       console.log(`[overlay] "${sessionId}" REFUSED to paint — no pup-owned hwnd confirmed (protecting non-pup taskbar buttons like Edge)`);       return false;@@ -4740,9 +4740,10 @@ async function ensureWindowOpenedWatch() { // and pup's overlay paint (which trusted the stale cache) landed on Edge. THE GUARANTEE, enforced // below: pup only ever paints/flashes an hwnd it can PROVE belongs to one of its own browser // processes. Any other hwnd is refused. pup can never touch Edge (or any app it did not launch).-function pupBrowserPidSet() {+function pupBrowserPidSet(profileName) {   const pids = new Set();-  for (const [, be] of browsers) {+  for (const [prof, be] of browsers) {+    if (profileName && prof !== profileName) continue;   // v1.9.287: scope to ONE profile when asked     try {       const b = be && be.browser; if (!b) continue;       if (b._detachedPid) pids.add(Number(b._detachedPid));@@ -4771,16 +4772,22 @@ async function hwndOwnerPid(hwnd) { } // Confirm an hwnd is a LIVE window owned by a pup browser process. Used as the hard gate before any // taskbar paint/flash, and to invalidate a stale cached hwnd (recycled numbers).-async function hwndBelongsToPup(hwnd) {+async function hwndBelongsToPup(hwnd, session) {+  // v1.9.287 (John caught two sessions on DIFFERENT profiles sharing one hwnd): validate that the+  // hwnd belongs to THIS session's OWN profile process, not merely "some pup window". The old check+  // let a wrong-but-pup cached hwnd (another session's window) pass forever, so a stale/mis-resolved+  // hwnd was never corrected and overlays painted on the wrong button. When a session is given, the+  // pid set is scoped to its profile; a cross-profile hwnd now fails and forces a re-resolve.   const pid = await hwndOwnerPid(hwnd);   if (!pid) return false;-  // pupBrowserPidSet is the parent detached pids; the real window often belongs to a CHILD chrome.-  if (pupBrowserPidSet().has(pid)) return true;+  const prof = session && session.profileName;+  const own = pupBrowserPidSet(prof || undefined);+  if (own.has(pid)) return true;   try {     const sp = path.join(require('os').tmpdir(), `_adom_ppid_${process.pid}.ps1`);     fs.writeFileSync(sp, `try { (Get-CimInstance Win32_Process -Filter "ProcessId=${pid}" -EA Stop).ParentProcessId } catch { 0 }`);     const par = Number((runPsHidden(sp, { timeout: 4000 }) || '0').trim());-    if (par && pupBrowserPidSet().has(par)) return true;+    if (par && own.has(par)) return true;   } catch (e) {}   return false; }@@ -4790,7 +4797,7 @@ async function resolveSessionHwndByBounds(session, sessionId) {     // v1.9.278: NEVER trust a cached hwnd blind - validate it still belongs to pup before reuse     // (a dead/recycled handle now owned by Edge is exactly how the Edge overlay happened).     if (session._hwnd) {-      if (await hwndBelongsToPup(session._hwnd)) return Number(session._hwnd);+      if (await hwndBelongsToPup(session._hwnd, session)) return Number(session._hwnd);       console.log(`[hwnd] "${sessionId}" cached hwnd ${session._hwnd} is stale/foreign — discarding and re-resolving`);       session._hwnd = null;     }@@ -6349,7 +6356,7 @@ async function flashViaAD(sessionId, opts) {   // v1.9.278: flash only a proven pup hwnd; else title match (a title tag can only exist on a pup   // window). Never flash a bare recycled hwnd - same Edge-protection guarantee as the overlay paint.   let _flashHwndOk = false;-  if (session && session._hwnd) { try { _flashHwndOk = await hwndBelongsToPup(session._hwnd); } catch (e) {} if (!_flashHwndOk) session._hwnd = null; }+  if (session && session._hwnd) { try { _flashHwndOk = await hwndBelongsToPup(session._hwnd, session); } catch (e) {} if (!_flashHwndOk) session._hwnd = null; }   const tgt = _flashHwndOk ? { hwnd: session._hwnd } : { titleContains: `(${TITLE_LABEL}: ${sessionId}` };   if (!opts.stop && session && session._hwnd) _flashedHwnds.add(session._hwnd);   const args = opts.stop ? { ...tgt, stop: true } : { ...tgt, mode: 'count', count: 4 };