From e6c01048363e35b29ebb66e5f8936bdcf60c2913 Mon Sep 17 00:00:00 2001 From: Tianren Dong Date: Mon, 28 Sep 2026 19:30:23 -0400 Subject: Fill whole textareas; cover new tabs' first page with early capture chrome_fill's triple-click selected one line of a multi-line textarea, so fill replaced only that line. Select value fields with the selectAll editing command before deleting. Early capture now waits for in-flight tab.new creations, so a first page that commits before the tab is tracked is still captured. --- test-suite/unit/console-capture.test.mjs | 21 ++++++++++++++++++++- test-suite/unit/input-reliability.test.mjs | 12 ++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'test-suite/unit') diff --git a/test-suite/unit/console-capture.test.mjs b/test-suite/unit/console-capture.test.mjs index ba0410b..48430ca 100644 --- a/test-suite/unit/console-capture.test.mjs +++ b/test-suite/unit/console-capture.test.mjs @@ -20,7 +20,8 @@ function loadWorker() { debugger: { onDetach: noop, onEvent: noop }, storage: { session: { get: async () => ({}), set: async () => {} } }, scripting: { executeScript: async (options) => { injected.push(options); return []; } }, - tabs: { get: async () => null }, + tabs: { get: async () => null, create: async () => { throw new Error("not mocked"); } }, + tabGroups: { query: async () => [] }, }; const w = { chrome, console, setTimeout, clearTimeout, setInterval: () => 0, navigator: { userAgent: "unit-test" }, fetch: async () => { throw new Error("offline"); } }; w.self = w; @@ -120,3 +121,21 @@ test("early capture is injected only into tabs Pi owns or tracks", async () => { assert.deepEqual(h.injected.map((o) => o.target.tabId), [11, 12]); assert.ok(h.injected.every((o) => o.func.name === "installEarlyCapture" && o.injectImmediately === true)); }); + +test("a Pi tab whose first page commits before tab.new tracks it still gets early capture", async () => { + const h = loadWorker(); + let commit; + h.w.chrome.tabs.create = async (props) => { + // Chrome can commit the first document while tab.new is still recording ownership. + commit = h.commit(21); + return { id: 21, windowId: 1, url: props.url, status: "loading" }; + }; + h.w.groupTab = async (tab) => ({ tab: { id: tab.id }, group: { title: "Pi" } }); + h.w.waitForTabSettled = async () => true; + h.w.formatTab = async (tab) => tab; + await h.w.dispatch("tab.new", { url: "https://site.test/", background: true, sessionKey: "s" }); + await commit; + assert.deepEqual(h.injected.map((o) => o.target.tabId), [21]); + await h.commit(22); + assert.deepEqual(h.injected.map((o) => o.target.tabId), [21], "unrelated tabs stay untouched"); +}); diff --git a/test-suite/unit/input-reliability.test.mjs b/test-suite/unit/input-reliability.test.mjs index 4a47e9c..8ea4bc5 100644 --- a/test-suite/unit/input-reliability.test.mjs +++ b/test-suite/unit/input-reliability.test.mjs @@ -215,6 +215,18 @@ for (const perCharacter of [false, true]) { }); } +test("fill selects a textarea's whole value with the selectAll command, not just the clicked line", async () => { + const h = harness({ tag: "TEXTAREA", editable: false }); + const result = await h.call("fill", { selector: "#target", text: "NEW", domFallback: false }); + assert.equal(result.input, "chrome"); + const keys = h.commands("Input.dispatchKeyEvent"); + const selectAll = keys.findIndex((c) => (c.params.commands || []).includes("selectAll")); + const del = keys.findIndex((c) => c.params.key === "Delete" && c.params.type === "keyDown"); + assert.ok(selectAll >= 0, "selectAll editing command sent"); + assert.ok(del > selectAll, "delete follows select-all"); + assert.equal(h.selected.length, 0, "no DOM range selection for value fields"); +}); + test("fill refuses to select an unrelated focused editor", async () => { const h = harness({ initial: "keep this" }); h.page.document.activeElement = { isContentEditable: true, contains: () => false }; -- cgit v1.2.3 From b33d18552599664901356ae27db0270df3cc3129 Mon Sep 17 00:00:00 2001 From: Tianren Dong Date: Mon, 28 Sep 2026 19:45:18 -0400 Subject: Create session tab groups in the tab's own window chrome.tabs.group without createProperties.windowId creates the group in the current (user's) window and moves the tab there, so a session's automation tab left its dedicated window and became a hidden inactive tab. Make the unit mock match Chrome's behavior. --- CHANGELOG.md | 1 + .../chrome-profile-bridge/browser-extension/service_worker.js | 8 ++++++-- test-suite/unit/automation-target.test.mjs | 11 +++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'test-suite/unit') diff --git a/CHANGELOG.md b/CHANGELOG.md index 94bc359..accad1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable user-facing changes to `pi-chrome`. ## 0.15.56 — 2026-09-28 +- **Pi's automation tab stays in its own window.** Joining the session tab group called `chrome.tabs.group` without a window. Chrome then creates the group in the current window (yours) and moves the tab there, where it sits as an inactive, hidden tab and trusted input is refused. This happened on a session's first page action and is the main source of the hidden-tab errors. New groups are now created in the tab's own window. - **`chrome_fill` replaces all of a multi-line textarea.** Fill selected the old value with a triple-click, which in a textarea selects only the clicked line. The rest stayed, and the tool still reported success. Inputs and textareas now select the whole value with Chrome's `selectAll` editing command before deleting. Contenteditables are unchanged. - **Early capture covers a new tab's first page.** `chrome_tab new` could commit its first page before the tab was recorded as Pi's, so early console/network capture skipped that load. Early capture now waits for in-flight Pi tab creations before deciding. diff --git a/extensions/chrome-profile-bridge/browser-extension/service_worker.js b/extensions/chrome-profile-bridge/browser-extension/service_worker.js index bcc795b..68fe8c9 100644 --- a/extensions/chrome-profile-bridge/browser-extension/service_worker.js +++ b/extensions/chrome-profile-bridge/browser-extension/service_worker.js @@ -1711,10 +1711,14 @@ async function groupTab(tab, title, color) { const groupTitle = cleanGroupTitle(title); let groupId = tab.groupId; if (typeof groupId !== "number" || groupId < 0) { - const existing = await findGroupByTitle(tab.windowId, groupTitle); + // Some browsers omit windowId on freshly created tabs; read it back instead of guessing. + const windowId = typeof tab.windowId === "number" ? tab.windowId : (await chrome.tabs.get(tab.id).catch(() => null))?.windowId; + const existing = await findGroupByTitle(windowId, groupTitle); + // Without createProperties.windowId Chrome creates the group in the *current* (user's) window + // and moves the tab there, pulling Pi's automation tab out of its own window as a hidden tab. groupId = existing !== null ? await chrome.tabs.group({ groupId: existing, tabIds: [tab.id] }) - : await chrome.tabs.group({ tabIds: [tab.id] }); + : await chrome.tabs.group(typeof windowId === "number" ? { tabIds: [tab.id], createProperties: { windowId } } : { tabIds: [tab.id] }); } await chrome.tabGroups.update(groupId, { title: groupTitle, color: cleanGroupColor(color), collapsed: false }); const grouped = await chrome.tabs.get(tab.id); diff --git a/test-suite/unit/automation-target.test.mjs b/test-suite/unit/automation-target.test.mjs index 7f46597..73fbc77 100644 --- a/test-suite/unit/automation-target.test.mjs +++ b/test-suite/unit/automation-target.test.mjs @@ -87,14 +87,17 @@ function makeChrome(state, { withWindows = true, withStorage = true, withTabGrou // Chrome closes a window automatically when its final tab is removed. if (tab && ![...tabs.values()].some((other) => other.windowId === tab.windowId)) windows.delete(tab.windowId); }, - group: async ({ groupId, tabIds = [] } = {}) => { + // Like Chrome: a new group goes into createProperties.windowId, else the *current* window + // (the user's), and grouped tabs move into the group's window. + group: async ({ groupId, tabIds = [], createProperties } = {}) => { let gid = groupId; if (typeof gid !== "number") { gid = alloc.group(); - const firstTab = tabs.get(tabIds[0]); - groups.set(gid, { id: gid, title: "", color: "grey", collapsed: false, windowId: firstTab ? firstTab.windowId : userWindowId }); + const windowId = typeof createProperties?.windowId === "number" ? createProperties.windowId : userWindowId; + groups.set(gid, { id: gid, title: "", color: "grey", collapsed: false, windowId }); } - for (const tid of tabIds) { const t = tabs.get(tid); if (t) t.groupId = gid; } + const groupWindow = groups.get(gid).windowId; + for (const tid of tabIds) { const t = tabs.get(tid); if (t) { t.groupId = gid; t.windowId = groupWindow; } } return gid; }, ungroup: async (id) => { const ids = Array.isArray(id) ? id : [id]; for (const tid of ids) { const t = tabs.get(tid); if (t) t.groupId = -1; } }, -- cgit v1.2.3