← Commit history

Stop fighting the user for the window: the post-open re-assert timers called the z-bottom primitive with force (needed for Chrome PDF self-activation pops) which also demoted a window the USER had just raised from the taskbar, because the session-flag guards lag the click by seconds. The primitive now checks GetLastInputInfo in the same PowerShell pass: OS-foreground plus user input within 5s means a human raised it, so it returns user-foreground instead of bottoming even under force; a PDF self-pop with idle hands still gets demoted. All re-assert and park callers stop retrying on that signal and mark the session userActive so every later demotion timer skips it for 10 minutes

John Lauer ·b2701b133c ·2mo ago ·parent de16b23
4 files changed +49−9
adom-bridge-puppeteer-manifest.json+4−4
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "2.0.25",-  "url": "https://wiki.adom.inc/download/adom/pup-bridge/2.0.25/adom-bridge-puppeteer-v2.0.25.zip",-  "sha256": "2882a0d80d5498cbaff3ad89c09dde6d27ca22df2a6776696c0e1de44e8d42c0",-  "size": 647596,+  "version": "2.0.26",+  "url": "https://wiki.adom.inc/download/adom/pup-bridge/2.0.26/adom-bridge-puppeteer-v2.0.26.zip",+  "sha256": "acad3b410632ca82dbfb7d5cf5c0ced7b44583067595f64d4105154e55691e8a",+  "size": 648278,   "verbPrefixes": [     "browser_",     "desktop_recorder_",
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-2.0.25+2.0.26
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "2.0.25",+  "version": "2.0.26",   "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. pup_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. pup_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, pup_alert_window posts a native toast whose click focuses the window, pup_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-bridge",   "author": "Adom Inc.",
src/server.js+43−3
@@ -6688,6 +6688,8 @@ async function osBottomUnlessForeground(hwnd, force) {       'public class ZBot {',       '  [DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr h, IntPtr a, int x, int y, int cx, int cy, uint f);',       '  [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();',+      '  [StructLayout(LayoutKind.Sequential)] public struct LASTINPUTINFO { public uint cbSize; public uint dwTime; }',+      '  [DllImport("user32.dll")] public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);',       '}',       '"@',       // THE OS truth: GetForegroundWindow. (document.hasFocus() via CDP LIES for CDP-created@@ -6697,6 +6699,20 @@ async function osBottomUnlessForeground(hwnd, force) {       `$h = [IntPtr]${Number(hwnd)}`,       `$force = ${force ? 1 : 0}`,       'if ($force -eq 0 -and [ZBot]::GetForegroundWindow() -eq $h) { Write-Output "foreground"; exit }',+      // v2.0.26 (John clicked the taskbar button and pup yanked the window back down): force exists+      // for Chrome SELF-activations (the PDF-viewer pop), but it cannot tell a PDF pop from a USER+      // click — and the session-flag guards lag the click by seconds, so the +2.5s/+3s re-asserts+      // kept demoting a window the user had just raised. Discriminator: RECENT USER INPUT. A window+      // that is OS-foreground while the user's hands were active in the last 5s was raised by a+      // HUMAN — respect it even under force. A PDF self-pop happens with idle hands and still gets+      // demoted. Same script, zero extra process spawns.+      'if ($force -eq 1 -and [ZBot]::GetForegroundWindow() -eq $h) {',+      '  $lii = New-Object ZBot+LASTINPUTINFO; $lii.cbSize = [uint32][System.Runtime.InteropServices.Marshal]::SizeOf($lii)',+      '  if ([ZBot]::GetLastInputInfo([ref]$lii)) {',+      '    $idleMs = [uint32]([Environment]::TickCount - $lii.dwTime)',+      '    if ($idleMs -lt 5000) { Write-Output "user-foreground"; exit }',+      '  }',+      '}',       '[ZBot]::SetWindowPos($h, [IntPtr]1, 0, 0, 0, 0, 0x13) | Out-Null', // HWND_BOTTOM; SWP_NOSIZE|NOMOVE|NOACTIVATE       'Write-Output "bottomed"',     ].join('\r\n');@@ -6983,7 +6999,16 @@ async function parkSessionWindowDirect(page, sessionId) {           const o = r && (typeof r.output === 'string' ? JSON.parse(r.output) : r.output || r);           hwnd = (o && ((o.best && o.best.hwnd) || o.hwnd)) || null;         } catch (e) {}-        if (hwnd && (await osBottomUnlessForeground(hwnd, true)) === 'bottomed') { bottomed = true; parkHwnd = hwnd; break; }+        {+          const zr = hwnd ? await osBottomUnlessForeground(hwnd, true) : 'error';+          if (zr === 'bottomed') { bottomed = true; parkHwnd = hwnd; break; }+          // v2.0.26: the user raised it while we were parking — respect it, remember it, stop parking.+          if (zr === 'user-foreground') {+            const _us = sessions.get(sessionId); if (_us) _us._userActiveAt = Date.now();+            console.log(`[park] "${sessionId}": user has this window FOREGROUND (recent input) — leaving it exactly where they put it`);+            return 'user-foreground';+          }+        }       }       await new Promise(r2 => setTimeout(r2, 300));     }@@ -7062,7 +7087,16 @@ async function reassertBottomAfterNav(sessionId) {   let bottomed = false;   try {     const hwnd = await cachedSessionHwnd(sessionId);-    if (hwnd && (await osBottomUnlessForeground(hwnd, true)) === 'bottomed') bottomed = true;+    const zr = hwnd ? await osBottomUnlessForeground(hwnd, true) : 'error';+    if (zr === 'bottomed') bottomed = true;+    // v2.0.26 (John: "you took it back to the bg... that fights with the user"): a re-assert that+    // finds the window user-foregrounded (recent input) STOPS — no retry, no ab fallback — and+    // marks the session so every later demotion timer skips it too (userIsUsingWindow, 10 min).+    if (zr === 'user-foreground') {+      if (sess) sess._userActiveAt = Date.now();+      console.log(`[park] "${sessionId}" (post-nav re-assert): user-foreground — hands off`);+      return;+    }   } catch (e) {}   if (bottomed) { console.log(`[park] "${sessionId}" (post-nav re-assert): bottomed`); return; }   // v1.9.202 (John's log audit found `park-failed` on two windows and pup just moved on): a@@ -7071,10 +7105,16 @@ async function reassertBottomAfterNav(sessionId) {   try {     await new Promise(r => setTimeout(r, 1200));     const hwnd2 = await cachedSessionHwnd(sessionId);-    if (hwnd2 && (await osBottomUnlessForeground(hwnd2, true)) === 'bottomed') {+    const zr2 = hwnd2 ? await osBottomUnlessForeground(hwnd2, true) : 'error';+    if (zr2 === 'bottomed') {       console.log(`[park] "${sessionId}" (post-nav re-assert, retry): bottomed`);       return;     }+    if (zr2 === 'user-foreground') {+      const _us2 = sessions.get(sessionId); if (_us2) _us2._userActiveAt = Date.now();+      console.log(`[park] "${sessionId}" (post-nav re-assert, retry): user-foreground — hands off`);+      return;+    }   } catch (e) {}   try {     await chrome.adCommand('desktop_set_window_state', { ...(await windowTarget(sessions.get(sessionId), sessionId)), state: 'bottom', force: false }, { timeoutMs: 5000 , caller: sessionCaller(sessions.get(sessionId))});