← Commit history

v2.0.386 (insiders): Issue 80: pup_screenshot no longer dies silently on an occluded background window - on a CDP timeout it retries after a CDP lifecycle-active nudge (no OS focus change), then falls back to an OS-level window capture, and only then returns errorCode screenshot_timeout with a real hint; responses carry capturedVia. Issue 83 ask 3: a 5-minute identity audit reads each live window's ACTUAL stamped AUMID and re-stamps on mismatch; pup_rescan runs the same audit on demand. Not promoted.

John Lauer ·6f7b8cfc69 ·1mo ago ·parent 45328ea
4 files changed +101−11
package.json+1−1
@@ -1,6 +1,6 @@ {   "slug": "pup-bridge",-  "version": "2.0.385",+  "version": "2.0.386",   "type": "app",   "description": "The pup SKILL PACK \u2014 the AI skills that teach a cloud/container AI how to drive the Adom Desktop Puppeteer (pup) bridge (browser_* verbs): the everyday `pup` skill plus focused sub-skills for windows/sessions/tabs, screenshots+recording, browsers+Chrome install, and driving the Adom wiki. Installs into ~/.claude/skills + ~/.codex/skills. DOCS ONLY \u2014 this is NOT the bridge runtime. The bridge itself (the Node program that drives the browser) runs on the DESKTOP: Adom Desktop bundles it and auto-installs/updates it, and it's published separately on the Releases tab as adom-bridge-puppeteer-v<ver>.zip. The pkg version is kept in lockstep with the Release version so the page's max version row always carries BOTH a pkg tarball (skills) and a runtime zip (bridge) \u2014 a skills-only or runtime-only bump on the top row breaks constraint installs. TL;DR: pkg install = the skills for your AI; the bridge = the Release zip, which Adom Desktop manages for you.",   "keywords": [
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-2.0.385\ No newline at end of file+2.0.386\ No newline at end of file
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "2.0.385",+  "version": "2.0.386",   "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+98−8
@@ -971,6 +971,59 @@ function activeProgress() {   } catch (e) {}   return rows; }+// ── v2.0.386 (#83 ask 3): IDENTITY AUDIT — read back what the OS window is ACTUALLY stamped with+// and compare it to what pup believes (_curAppId). A mismatch (a stale generation, a stamp that+// never landed, a window Chrome recreated) is re-stamped through the normal path, which also+// re-registers and nudges the button. One PowerShell per sweep for every live hwnd; every 5 min.+function readStampedAumids(hwnds) {+  return new Promise((resolve) => {+    if (process.platform !== 'win32' || !hwnds.length) return resolve({});+    const ps = `$code=@'+using System; using System.Runtime.InteropServices;+public static class AumidRead {+  [StructLayout(LayoutKind.Sequential)] public struct PROPERTYKEY { public Guid fmtid; public uint pid; }+  [StructLayout(LayoutKind.Sequential)] public struct PROPVARIANT { public ushort vt; public ushort r1; public ushort r2; public ushort r3; public IntPtr p; public IntPtr p2; }+  [ComImport, Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]+  public interface IPropertyStore { int GetCount(out uint c); int GetAt(uint i, out PROPERTYKEY pk); int GetValue(ref PROPERTYKEY key, out PROPVARIANT pv); int SetValue(ref PROPERTYKEY key, ref PROPVARIANT pv); int Commit(); }+  [DllImport("shell32.dll")] public static extern int SHGetPropertyStoreForWindow(IntPtr hwnd, ref Guid iid, out IPropertyStore pps);+  static Guid AUM = new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3");+  static Guid IID = new Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99");+  public static string Read(IntPtr hwnd) {+    IPropertyStore ps; if (SHGetPropertyStoreForWindow(hwnd, ref IID, out ps) != 0) return null;+    PROPERTYKEY k = new PROPERTYKEY(); k.fmtid = AUM; k.pid = 5;+    PROPVARIANT pv; if (ps.GetValue(ref k, out pv) != 0) return null;+    return (pv.vt == 31 && pv.p != IntPtr.Zero) ? Marshal.PtrToStringUni(pv.p) : null;+  }+}+'@+Add-Type -TypeDefinition $code+foreach($h in @(${hwnds.join(',')})){ $a=[AumidRead]::Read([IntPtr]$h); Write-Output ("$h" + [char]9 + $a) }`;+    execFile('powershell', ['-NoProfile', '-Command', ps], { windowsHide: true, timeout: 20000 }, (err, stdout) => {+      const out = {};+      if (!err) for (const line of String(stdout || '').split(/\r?\n/)) { const [h, a] = line.split('\t'); if (h) out[String(h).trim()] = (a || '').trim() || null; }+      resolve(out);+    });+  });+}+async function auditStampedIdentities() {+  if (process.platform !== 'win32' || pupSettings().aumidIcons !== 'on') return;+  const targets = [];+  for (const [sid, s] of sessions) { if (s && s._hwnd && s._curAppId) targets.push({ sid, hwnd: String(s._hwnd), expect: s._curAppId }); }+  if (!targets.length) return;+  const actual = await readStampedAumids(targets.map(t => t.hwnd));+  let mismatches = 0;+  for (const t of targets) {+    const got = actual[t.hwnd];+    if (got === undefined) continue;                       // window not readable this pass (gone, or PS failed)+    if (got === t.expect) continue;+    mismatches++;+    console.log(`[identity] AUDIT MISMATCH "${t.sid}": stamped=${got || '(none)'} expected=${t.expect} — re-stamping (#83)`);+    const s = sessions.get(t.sid); if (!s) continue;+    s._curAppId = null; s._recoveryIdentityVerified = true;+    stampPupIdentity(t.sid, { _commit: true }).catch(() => {});+  }+  if (!mismatches) console.log(`[identity] audit ok: ${targets.length} window(s) stamped as expected`);+} function findAnyPendingDialog() {   for (const [sid, session] of sessions) {     const d = findPendingDialog(session);@@ -15923,6 +15976,7 @@ const server = http.createServer(async (req, res) => {           return;         }         case 'pup_rescan': {+          try { await auditStampedIdentities(); } catch (e) {}   // v2.0.386 (#83): rescan also re-checks every window's stamped identity           // v1.5.1+: orphan-recovery primitive. Walk every known profile           // (in-memory + on-disk session files), attempt reconnect for any           // whose CDP socket dropped, then walk pages of every connected@@ -17317,14 +17371,48 @@ const server = http.createServer(async (req, res) => {           const _fgBefore = await osGetForegroundWindow().catch(() => null);           // v2.0.289: show a determinate taskbar progress bar for the length of the capture, sized to           // the running-average screenshot time (John: progress bars instead of the flash).-          let screenshotBuf = await withTaskbarProgress(resolvedId, 'screenshot', () => withTimeout(-            // v2.0.186 (#50): captureBeyondViewport defaults TRUE in current puppeteer, which renders-            // from the document ORIGIN — so a viewport screenshot ignored the page's live scroll-            // position (scroll via pup_eval, screenshot still showed the top). Viewport shots now-            // capture the compositor's real viewport; fullPage keeps beyond-viewport ON (it needs it).-            raceCrash(tab, resolvedId, tab.page.screenshot({ type: 'png', fullPage, captureBeyondViewport: fullPage })),-            20_000, 'page.screenshot'-          ));+          let screenshotBuf = null, _capturedVia = 'cdp';+          try {+            screenshotBuf = await withTaskbarProgress(resolvedId, 'screenshot', () => withTimeout(+              // v2.0.186 (#50): captureBeyondViewport defaults TRUE in current puppeteer, which renders+              // from the document ORIGIN — so a viewport screenshot ignored the page's live scroll+              // position (scroll via pup_eval, screenshot still showed the top). Viewport shots now+              // capture the compositor's real viewport; fullPage keeps beyond-viewport ON (it needs it).+              raceCrash(tab, resolvedId, tab.page.screenshot({ type: 'png', fullPage, captureBeyondViewport: fullPage })),+              20_000, 'page.screenshot'+            ));+          } catch (e1) {+            // v2.0.386 (#80): a CDP capture on a fully OCCLUDED background window can hang until the+            // compositor produces a frame (pup deliberately lets background windows throttle, #14), and+            // the old path surfaced that as a bare timeout with an empty output. Two fallbacks that+            // never touch OS focus, then an honest error: (1) CDP lifecycle 'active' + one retry;+            // (2) an OS-level PrintWindow capture of the window (works while occluded); (3) errorCode.+            if (!/timed out/i.test(String(e1 && e1.message))) throw e1;+            console.log(`[screenshot] "${resolvedId}" CDP capture timed out — trying lifecycle-active retry, then OS window capture`);+            try {+              await pageSetLifecycleActive(tab.page);+              screenshotBuf = await withTimeout(raceCrash(tab, resolvedId, tab.page.screenshot({ type: 'png', fullPage, captureBeyondViewport: fullPage })), 8000, 'page.screenshot(retry)');+              _capturedVia = 'cdp-after-lifecycle-active';+            } catch (e2) {+              let _osBuf = null;+              try {+                if (!session._hwnd) { try { await resolveSessionHwndByBounds(session, resolvedId); } catch (e) {} }+                if (session._hwnd && !fullPage) {+                  const r = await chrome.abCommand('desktop_screenshot_window', { hwnd: Number(session._hwnd) }, { timeoutMs: 25000, callerThread: _callerThread || undefined, callerReason: 'pup screenshot fallback (CDP capture timed out on an occluded window)' });+                  const p = abPayload(r) || {};+                  const fp = p.fullPath || p.safePath || (r && (r.fullPath || r.safePath));+                  if (fp && fs.existsSync(fp)) _osBuf = fs.readFileSync(fp);+                }+              } catch (e) {}+              if (!_osBuf) {+                sendJSON(res, { success: false, errorCode: 'screenshot_timeout', error: `page.screenshot timed out (CDP), a lifecycle-active retry timed out, and the OS window capture was unavailable${fullPage ? ' (fullPage has no OS fallback)' : ''}`,+                  _hint: 'The window is probably fully occluded and its compositor is idle (background windows throttle on purpose, #14). pup_eval still works, so the page is fine. Options: retry in a moment; call pup_raise_os_window with a foregroundReason if the user asked to see it; or open the window with highFps:true when you need continuous frames. Read errorCode, not output: this failure used to arrive as an empty output.' });+                return;+              }+              screenshotBuf = _osBuf; _capturedVia = 'os-window';+              console.log(`[screenshot] "${resolvedId}" served by OS window capture after CDP timeouts`);+            }+          }           // If the capture foregrounded THIS window AND there was no recent user input (so it was pup,           // not the user clicking it), caption "<thread> · screenshotting" so the user knows what put it           // on their screen. No-op on the common CDP path, which never foregrounds (measured 0/101).@@ -18679,6 +18767,7 @@ const server = http.createServer(async (req, res) => {             }             const magic = (() => { try { return fs.readFileSync(abs).slice(0, 5).toString('latin1').replace(/[^\x20-\x7e]/g, '.'); } catch (e) { return null; } })();             sendJSON(res, { success: true, output: JSON.stringify({+              ok: true, capturedVia: _capturedVia,   // v2.0.386 (#80): cdp | cdp-after-lifecycle-active | os-window               ok: true, savedTo: abs, filename: fname, bytes: (ev.totalReceivedBytes || ev.receivedBytes || sizeOnDisk), sizeOnDisk, magic,               triggeredBy: args.selector ? ('click ' + args.selector) : ('a[download] ' + args.url),               sessionId: resolvedId, tabId,@@ -20298,6 +20387,7 @@ const _onPupBound = async () => {   // reconnects, and every rescan already reconciles inline — the patrol is just a backstop, and a   // hot one multiplies any probe-judgement bug across every window (today's lesson).   setTimeout(() => { for (const [sid, s] of [...sessions]) reconcileSessionTabs(s, sid).catch(() => {}); }, 8000);+  setInterval(trackedLoop('identity-audit', 300000, () => { if (minimalTouch()) return; auditStampedIdentities().catch(() => {}); }), 300000);   // v2.0.386 (#83 ask 3)   setInterval(trackedLoop('reconcile-session-tabs', 300000, () => { if (minimalTouch()) return; for (const [sid, s] of [...sessions]) reconcileSessionTabs(s, sid).catch(() => {}); }), 300000);   // v1.9.171 — CRASH SELF-HEAL. The shared Chrome dies two ways on heavy/hostile pages (measured   // repeatedly on the Autodesk sign-in flow), and pup must recover from BOTH without a human: