diff options
| author | Tianren Dong <tianrendong.dtr@gmail.com> | 2026-06-22 21:04:05 -0400 |
|---|---|---|
| committer | Tianren Dong <tianrendong.dtr@gmail.com> | 2026-06-22 21:04:05 -0400 |
| commit | 2c1a4b3cf42c149f52d491131680e062e1935f5f (patch) | |
| tree | 9ab27497cd52c5a04db63ae1a7bdba07e4b78134 /extensions | |
| parent | c1ed934dd20931b177e233ae0327a290a8001631 (diff) | |
0.15.40: keep automation targets in session group
Diffstat (limited to 'extensions')
| -rw-r--r-- | extensions/chrome-profile-bridge/browser-extension/manifest.json | 2 | ||||
| -rw-r--r-- | extensions/chrome-profile-bridge/browser-extension/service_worker.js | 22 |
2 files changed, 17 insertions, 7 deletions
diff --git a/extensions/chrome-profile-bridge/browser-extension/manifest.json b/extensions/chrome-profile-bridge/browser-extension/manifest.json index 7d16294..d233208 100644 --- a/extensions/chrome-profile-bridge/browser-extension/manifest.json +++ b/extensions/chrome-profile-bridge/browser-extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Pi Chrome Connector", - "version": "0.15.39", + "version": "0.15.40", "description": "Lets Pi control tabs in Chrome via a local connector at 127.0.0.1.", "permissions": [ "tabs", diff --git a/extensions/chrome-profile-bridge/browser-extension/service_worker.js b/extensions/chrome-profile-bridge/browser-extension/service_worker.js index 2b5f96f..e04eafd 100644 --- a/extensions/chrome-profile-bridge/browser-extension/service_worker.js +++ b/extensions/chrome-profile-bridge/browser-extension/service_worker.js @@ -86,9 +86,19 @@ function isPiChromeOwnedTarget(tabId, sessionKey) { return false; } -// Create a fresh dedicated automation target for `sessionKey`. Prefer an isolated window; fall -// back to a tab. Structured so a window can be the default while tab-fallback stays a one-liner. -async function createAutomationTarget(sessionKey) { +// Create a fresh automation target for `sessionKey`. If this session already has a tab group, +// create the tab inside that group's window so one Pi session keeps one Chrome tab group (Chrome +// groups cannot span windows). If no group exists yet, prefer an isolated window; fall back to a +// tab. When the tab is created in a pre-existing group window, leave windowId unset so cleanup only +// closes our tab, never that whole window. +async function createAutomationTarget(sessionKey, groupTitle) { + const existingGroup = groupTitle ? await findGroupRecordByTitle(groupTitle) : null; + if (existingGroup && typeof existingGroup.windowId === "number") { + const tab = await chrome.tabs.create({ url: "about:blank", active: false, windowId: existingGroup.windowId }); + automationTargets.set(sessionKey, { windowId: undefined, tabId: typeof tab.id === "number" ? tab.id : undefined }); + await persistAutomationTargets(); + return tab; + } if (chrome.windows && typeof chrome.windows.create === "function") { try { const win = await chrome.windows.create({ url: "about:blank", focused: false }); @@ -125,8 +135,8 @@ async function resolveOwnedAutomationTarget(sessionKey) { // Return the session's dedicated automation target, creating it on first use (or after the user // closed it). Used by page/navigation actions that need a live surface to drive. -async function getOrCreateAutomationTarget(sessionKey) { - return (await resolveOwnedAutomationTarget(sessionKey)) || createAutomationTarget(sessionKey); +async function getOrCreateAutomationTarget(sessionKey, groupTitle) { + return (await resolveOwnedAutomationTarget(sessionKey)) || createAutomationTarget(sessionKey, groupTitle); } // Close only the session's pi-chrome-owned window/tab, and only if it still exists. Never touches @@ -1317,7 +1327,7 @@ async function getTabByParams(params, { createOwnedTarget = true } = {}) { // existing tab pass targetId/urlIncludes/titleIncludes above. const sessionKey = sessionKeyOf(params); tab = createOwnedTarget - ? await getOrCreateAutomationTarget(sessionKey) + ? await getOrCreateAutomationTarget(sessionKey, params.sessionGroupTitle) : await resolveOwnedAutomationTarget(sessionKey); if (!tab) { throw new Error( |
