From a76fbc3b9b82038ab44c04d6379cc2d45e5cecd8 Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Sat, 14 Nov 2026 09:15:15 +0000 Subject: tabs: one window for every agent; inactive tabs take input; background off by default Measured in Brave on 2026-11-14: an inactive tab takes trusted CDP clicks, key presses, text and mouse moves, and Page.captureScreenshot renders it live. Only mouseWheel hangs, waiting for a frame. The upstream guard that refused input to every hidden page was wrong for inactive tabs, and it is what made a window per session look necessary. - New sessions' tabs open inactive in the user's last focused window, in the session's tab group; a window is created only when none is open. - New groups start collapsed, unless their tab is the one showing, and expand when a tab in them is brought forward. Existing groups keep the user's setting. - Input is refused up front only in a minimized window (untested there). - chrome_scroll scrolls hidden pages by script instead of the wheel. - Focus emulation on attach, so blur-sensitive menus stay open. - Background mode is off by default. Calls still default to background; background:false or chrome_tab activate brings a tab forward. - Agent guidance, tool descriptions and docs say so. --- test-suite/unit/shared-window.test.mjs | 61 ---------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 test-suite/unit/shared-window.test.mjs (limited to 'test-suite/unit/shared-window.test.mjs') diff --git a/test-suite/unit/shared-window.test.mjs b/test-suite/unit/shared-window.test.mjs deleted file mode 100644 index 66041f4..0000000 --- a/test-suite/unit/shared-window.test.mjs +++ /dev/null @@ -1,61 +0,0 @@ -// Each session has its own window: a window shows only one tab, so sessions sharing one hid each -// other's tabs (no real input, blank screenshots). A session's extra tabs go into its own window. -import assert from "node:assert/strict"; -import fs from "node:fs"; -import vm from "node:vm"; -import { test } from "node:test"; - -const workerSource = fs.readFileSync(new URL("../../extensions/chrome-profile-bridge/browser-extension/service_worker.js", import.meta.url), "utf8"); - -function worker({ groups = [], windows = { 5: { id: 5, type: "normal" } } } = {}) { - const calls = []; - const listener = { addListener() {}, removeListener() {} }; - let nextTab = 100; - const w = { - console, setTimeout, clearTimeout, setInterval: () => 0, navigator: { userAgent: "unit-test" }, fetch: async () => { throw new Error("offline"); }, - chrome: { - runtime: { id: "test", getManifest: () => ({ version: "0.0.0" }), onInstalled: listener, onStartup: listener }, - alarms: { create() {}, onAlarm: listener }, action: { onClicked: listener }, webNavigation: { onCommitted: listener }, - debugger: { onDetach: listener, onEvent: listener, getTargets: (cb) => cb([]) }, - storage: { session: { get: async () => ({}), set: async (v) => { calls.push({ method: 'storage.set', json: JSON.stringify(v) }); } } }, - tabGroups: { query: async () => groups }, - windows: { - get: async (id) => windows[id] ?? Promise.reject(new Error("No window")), - create: async (props) => { calls.push({ method: "windows.create", props }); return { id: 9, tabs: [{ id: 900, windowId: 9 }] }; }, - }, - tabs: { - create: async (props) => { calls.push({ method: "tabs.create", props }); return { id: nextTab++, windowId: props.windowId }; }, - query: async () => [], get: async () => null, onUpdated: listener, - }, - }, - }; - w.self = w; - vm.runInNewContext(workerSource, w); - return { w, calls }; -} - -const piGroup = (windowId, name = "Pi Session: claude-code 1 other") => ({ id: 1, windowId, title: name }); -const ops = (calls) => calls.filter((c) => c.method !== "storage.set").map((c) => c.method); - -test("a new session gets its own window even when another session's window exists", async () => { - const { w, calls } = worker({ groups: [piGroup(5)] }); - await w.createAutomationTarget("claude-code 2 mine", "Pi Session: claude-code 2 mine"); - assert.deepEqual(ops(calls), ["windows.create"]); -}); - -test("a session that already has a group adds its tab to that group's window", async () => { - const { w, calls } = worker({ groups: [piGroup(5, "Pi Session: claude-code 2 mine")] }); - await w.createAutomationTarget("claude-code 2 mine", "Pi Session: claude-code 2 mine"); - assert.deepEqual(ops(calls), ["tabs.create"]); - assert.equal(calls.find((c) => c.method === "tabs.create").props.windowId, 5); -}); - -test("chrome_tab new for a session with no group goes to the session's own window, not the focused one", async () => { - const { w, calls } = worker({ groups: [piGroup(5)] }); - w.groupTab = async (tab) => tab; - w.bringToFront = async () => {}; - await w.dispatch("tab.new", { url: "https://x.test/", groupTitle: "Pi Session: claude-code 2 mine", sessionKey: "claude-code 2 mine" }); - assert.deepEqual(ops(calls), ["windows.create"]); - assert.equal(calls[0].props.url, "https://x.test/"); - assert.equal(calls[0].props.focused, false); -}); -- cgit v1.2.3