← Commit history

Resolve a pup window's OS handle WITHOUT its title, fixing the taskbar button John has asked about repeatedly. Measured first this time: the composed badge PNG was dumped and inspected and it is CORRECT (PDF sheet + Adom mark inset), so the compositor was never the problem — ten revisions of the image were wasted. The failure is DELIVERY: every paint/park/lookup found windows via the '(session: <id>)' title tag, and Chrome's PDF viewer cannot carry that tag, so the paint had no target and vanished while reporting success. v1.9.212 tried the handle but only stored it when park SUCCEEDED, and park fails on exactly these windows — circular. New resolveSessionHwndByBounds breaks the circle using facts pup already has: the profile's Chrome PID plus the window's exact bounds from CDP Browser.getWindowBounds. It enumerates visible Chrome_WidgetWin_1 top-level windows, matches on geometry across common DPI scales, and caches the handle on the session. The overlay paint and sessionHwnd both resolve through it before ever falling back to a title lookup, so park, badge paint and ownership all work on PDF/untagged windows.

John Lauer ·aa18fac2bf ·3mo ago ·parent f8cdc90
4 files changed +95−7
adom-bridge-puppeteer-manifest.json+4−4
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "1.9.215",-  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.215/adom-bridge-puppeteer-v1.9.215.zip",-  "sha256": "7dc5f85709ada7c42fa63319ac202079e34161d1e8a58bc3569041822a0add9a",-  "size": 441329,+  "version": "1.9.216",+  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.216/adom-bridge-puppeteer-v1.9.216.zip",+  "sha256": "fdc6345a40aaf068ae930f06498cdb2a4b226b9a08f893cea295d7b2cbdfc354",+  "size": 442621,   "verbPrefixes": [     "browser_",     "desktop_recorder_",
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-1.9.215+1.9.216
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "1.9.215",+  "version": "1.9.216",   "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+89−1
@@ -1895,7 +1895,11 @@ async function pupCaption(text, expiresInMs = 8000, id = 'pup-assist') { } async function sessionHwnd(sessionId) {   // v1.9.212: prefer the STORED handle — a title lookup cannot find a PDF-viewer window at all.-  try { const _s = sessions.get(sessionId); if (_s && _s._hwnd) return Number(_s._hwnd); } catch (e) {}+  try {+    const _s = sessions.get(sessionId);+    if (_s && _s._hwnd) return Number(_s._hwnd);+    if (_s) { const h = await resolveSessionHwndByBounds(_s, sessionId); if (h) return h; }+  } catch (e) {}   try {     const fw = adPayload(await chrome.adCommand('desktop_find_window', { titleContains: `(session: ${sessionId}` }, { timeoutMs: 5000, caller: sessionCaller(sessions.get(sessionId)) }));     const b = fw && (fw.best || (fw.data && fw.data.best));@@ -4134,6 +4138,7 @@ async function applyAppOverlay(session, sessionId) {       fs.writeFileSync(_dbgPath, Buffer.from(overlay, 'base64'));       console.log(`[overlay-debug] "${sessionId}" composed ${Buffer.from(overlay, 'base64').length}B -> ${_dbgPath} | src=${(src && src.href) || '?'} | hwnd=${session._hwnd || '(none, using title)'}`);     } catch (e) { console.log(`[overlay-debug] dump failed: ${e.message}`); }+    if (!session._hwnd) { try { await resolveSessionHwndByBounds(session, sessionId); } catch (e) {} }     const _tgt = (session._hwnd ? { hwnd: session._hwnd } : { titleContains: `(session: ${sessionId}` });     await chrome.adCommand('desktop_taskbar', {       ..._tgt,@@ -4340,6 +4345,89 @@ async function ensureWindowOpenedWatch() {   } catch (e) {} } // Which OS window (CDP windowId) is this page in?+// v1.9.216 — RESOLVE A WINDOW'S OS HANDLE WITHOUT ITS TITLE. This is the fix for the taskbar button+// John has asked about repeatedly. Every paint/park/lookup addressed windows by their+// "(session: <id>)" TITLE TAG, and Chrome's PDF viewer cannot carry that tag, so on a PDF window the+// paint had no target and vanished — the composed badge was CORRECT the whole time (dumped and+// verified: PDF sheet + Adom mark), it was simply never delivered. v1.9.212 tried to store the handle+// but only did so when park SUCCEEDED, and park fails on exactly these windows: circular.+//+// Break the circle with facts we already have: pup knows the profile's Chrome PID, and CDP tells us+// the window's exact bounds. Enumerate that PID's top-level windows and match on geometry. Works for+// any document type, needs no title, and the handle is then cached on the session.+async function resolveSessionHwndByBounds(session, sessionId) {+  if (process.platform !== 'win32' || !session) return null;+  try {+    if (session._hwnd) return Number(session._hwnd);+    const page = (session.tabs || [])[0] && (session.tabs || [])[0].page;+    if (!page) return null;+    let bounds = null, cdp = null;+    try {+      cdp = await page.target().createCDPSession();+      const { 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;+    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;+    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).+    const ps = [+      'Add-Type @"',+      'using System; using System.Runtime.InteropServices; using System.Text; using System.Collections.Generic;',+      'public class WEnum {',+      '  public delegate bool Proc(IntPtr h, IntPtr l);',+      '  [DllImport("user32.dll")] public static extern bool EnumWindows(Proc p, IntPtr l);',+      '  [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr h);',+      '  [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);',+      '  [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out RECT r);',+      '  [DllImport("user32.dll")] public static extern int GetClassName(IntPtr h, StringBuilder s, int n);',+      '  public struct RECT { public int L, T, R, B; }',+      '  public static List<string> Find() {',+      '    var outp = new List<string>();',+      '    EnumWindows((h, l) => {',+      '      if (!IsWindowVisible(h)) return true;',+      '      uint pid; GetWindowThreadProcessId(h, out pid);',+      '      var cn = new StringBuilder(128); GetClassName(h, cn, 128);',+      '      if (cn.ToString() != "Chrome_WidgetWin_1") return true;',+      '      RECT r; GetWindowRect(h, out r);',+      '      outp.Add(((long)h).ToString() + "," + pid + "," + r.L + "," + r.T + "," + (r.R - r.L) + "," + (r.B - r.T));',+      '      return true;',+      '    }, IntPtr.Zero);',+      '    return outp;',+      '  } }',+      '"@',+      '[WEnum]::Find() | ForEach-Object { Write-Output $_ }',+    ].join('\r\n');+    fs.writeFileSync(scriptPath, ps);+    const out = (await runPsHiddenPromise(scriptPath, { timeout: 9000 }) || '').trim();+    if (!out) return null;+    // Every chrome.exe under this profile counts (renderers have no windows, so PID may be the parent+    // or a sibling in the tree — accept any, then disambiguate purely on geometry).+    let best = null;+    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 (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`);+      return best.h;+    }+    return null;+  } catch (e) { console.log(`[hwnd] "${sessionId}" bounds resolve failed: ${e.message}`); return null; }+}+ async function pageWindowId(page) {   let cdp = null;   try {