← Commit history

Bridge: redirect guessed nbrowser_focus_window/raise_os_window to core desktop_bring_to_front (with captured hwnd) instead of failing opaquely

John Lauer ·baedaf335b ·4mo ago ·parent 33448ad
1 file changed +20
bridge/server.js+20
@@ -460,6 +460,26 @@ function dispatch(verb, args) {     if (verb.startsWith('nbrowser_record_') && args && args.method === 'wgc') {       return wgcRecord(verb, args).then(resolve);     }+    // OS-level window raise/focus is owned by the CORE adom-desktop verb desktop_bring_to_front. The+    // extension deliberately does NOT implement a focus/raise-window verb — it must never steal the+    // user's focus. So we don't expose a phantom verb; but an AI coming from pup will guess+    // browser_focus_window -> nbrowser_focus_window. Rather than fail opaquely in the extension,+    // redirect it to the core verb (with THIS session's captured hwnd) — it would find it on its own.+    const RAISE_REDIRECT = {+      nbrowser_focus_window: 'OS window raise/focus',+      nbrowser_raise_os_window: 'OS window raise',+      nbrowser_raise_window: 'OS window raise',+      nbrowser_bring_to_front: 'OS window raise',+    };+    if (RAISE_REDIRECT[verb]) {+      const hwnd = (args && args.sessionId && sessionHwnd.get(args.sessionId)) || lastHwnd;+      const target = hwnd ? `{"hwnd":${hwnd}}` : '{"titleContains":"<the driven window\'s title>"}';+      return resolve({+        success: false,+        error: `${verb} is not an extension verb — ${RAISE_REDIRECT[verb]} is owned by the core adom-desktop verb desktop_bring_to_front`,+        _hint: `Use the CORE AD verb instead: desktop_bring_to_front ${target}. The extension intentionally never raises or steals the user's focus — nbrowser_focus only activates the tab + flashes its taskbar button; desktop_bring_to_front is the explicit "bring it to the front so the user can watch" action.`,+      });+    }     const tgt = targetConn(args);     if (!tgt || tgt.blocked || !tgt.conn) {       if (tgt && tgt.blocked) {