← Commit history

In-place wiki view toggle: mint a single-use magic link from an already-logged-in page (browser-session endpoint works with just the session cookie, so the desktop needs no token) and navigate the window, instead of closing and relaunching it under another profile

John Lauer ·edbc9647b9 ·3mo ago ·parent b9b21a3
4 files changed +82−6
adom-bridge-puppeteer-manifest.json+4−4
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "1.9.63",-  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.63/adom-bridge-puppeteer-v1.9.63.zip",-  "sha256": "7f06971dc2f55baeb578053cccc6b67f263371f6fbd4f88b8caabdb83973d4e1",-  "size": 303984,+  "version": "1.9.64",+  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.64/adom-bridge-puppeteer-v1.9.64.zip",+  "sha256": "83e5841a7fae222dcf63635c58d2425fb5dfc7ee27df9e799719a49acc0016da",+  "size": 305326,   "verbPrefixes": [     "browser_",     "desktop_recorder_",
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-1.9.63+1.9.64
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "1.9.63",+  "version": "1.9.64",   "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.",   "homepage": "https://wiki.adom.inc/adom/adom-desktop",   "author": "Adom Inc.",
src/server.js+76
@@ -5821,6 +5821,82 @@ const server = http.createServer(async (req, res) => {             sendJSON(res, { success: true, output: JSON.stringify({ ok: true, view, unchanged: true, url }) });             return;           }+          // v1.9.63 — IN-PLACE view switch, no close-and-relaunch.+          //+          // A wiki session cookie is per-PROFILE and a profile's userDataDir is fixed at Chrome+          // launch, which is why this used to tear the window down and relaunch it under the other+          // profile (the thing John watched vanish and never come back). Colby's browser-session+          // endpoint removes that: an ALREADY-LOGGED-IN page can mint its own single-use magic link+          // with nothing but its session cookie —+          //     POST /api/v1/auth/browser-session {next:"/adom/page"} -> {url, expires_in:60}+          // so the BRIDGE can mint on the desktop (no container token, no adom-wiki CLI) and just+          // navigate this window. The other direction is a cookie wipe plus a plain navigate. Either+          // way it is one hop and the window/tabs are never destroyed.+          //+          // Guard: only wipe cookies when this window owns its profile. The shared authed profile+          // backs OTHER windows too and clearing it would silently log them all out — fall through+          // to the legacy relaunch in that case.+          const _sharedAuthed = /adom-wiki-authed/i.test(session.profileName || '');+          const _canInPlace = (view === 'authed') ? true : !_sharedAuthed;+          if (_canInPlace) {+            try {+              let targetUrl = null;+              if (view === 'authed') {+                // Mint from ANY currently-authenticated pup page. Single-use + 60s TTL, so mint+                // immediately before navigating and never cache it (a live link IS a credential).+                let minter = null;+                for (const [, s2] of sessions) {+                  for (const t2 of (s2.tabs || [])) {+                    try {+                      if (!isAdomUrl(t2.page.url())) continue;+                      const a2 = await checkWikiAuth(t2.page);+                      if (a2 && a2.authed) { minter = t2.page; break; }+                    } catch (e) {}+                  }+                  if (minter) break;+                }+                if (minter) {+                  const nextPath = (() => { try { const u2 = new URL(url); return u2.pathname + u2.search; } catch (e) { return '/'; } })();+                  targetUrl = await minter.evaluate(async (np) => {+                    try {+                      const r = await fetch('/api/v1/auth/browser-session', {+                        method: 'POST', credentials: 'same-origin',+                        headers: { 'content-type': 'application/json' },+                        body: JSON.stringify({ next: np }),+                      });+                      if (!r.ok) return null;+                      const j = await r.json();+                      return (j && j.url) ? j.url : null;+                    } catch (e) { return null; }+                  }, nextPath);+                }+                if (!targetUrl) console.log(`[wikiview] "${sessionId}" no logged-in page to mint from — falling back to relaunch`);+              } else {+                try {+                  const cdp = await session.page.target().createCDPSession();+                  await cdp.send('Network.clearBrowserCookies');+                  await cdp.detach();+                } catch (e) {}+                targetUrl = url;+              }+              if (targetUrl) {+                await session.page.goto(targetUrl, { waitUntil: 'domcontentloaded', timeout: 25000 });+                session._wikiView = view;+                const a3 = await checkWikiAuth(session.page).catch(() => ({ authed: false }));+                await setWikiAuthedState(session, sessionId, !!(a3 && a3.authed));+                try { await setWikiModeGlyph(session.page, (a3 && a3.authed) ? '● Logged in' : '○ Public'); } catch (e) {}+                session._wikiJumplistKey = undefined;   // the toggle's own label flips+                updateWikiJumplist(session, sessionId).catch(() => {});+                updateThumbnailTooltip(session, sessionId).catch(() => {});+                session._foreground = true;+                try { await session.page.bringToFront(); } catch (e) {}+                console.log(`[wikiview] "${sessionId}" -> ${view} IN PLACE (authed=${!!(a3 && a3.authed)}) — no relaunch`);+                sendJSON(res, { success: true, output: JSON.stringify({ ok: true, view, inPlace: true, authed: !!(a3 && a3.authed), url: session.page.url() }) });+                return;+              }+            } catch (e) { console.log(`[wikiview] "${sessionId}" in-place switch failed (${e.message}) — falling back to relaunch`); }+          }+           // v1.9.29 BUG FIX: carry EVERY tab across the switch. The old code relaunched only the           // active tab's url and closed the rest, silently destroying the user's other tabs (John           // lost a 5-tab research window to one jump-list click). Snapshot all urls + which was