feat(relay): group-scoped Target.getTargets — restore follow-popup + cross-session adopt under isolation (#40)
Release binaries / Build macOS ARM64 (push) Has been cancelled
Release binaries / Build macOS x64 (push) Has been cancelled
Release binaries / Build Linux ARM64 (push) Has been cancelled
Release binaries / Build Linux musl ARM64 (push) Has been cancelled
Release binaries / Build Linux musl x64 (push) Has been cancelled
Release binaries / Build Linux x64 (push) Has been cancelled
Release binaries / Build Windows x64 (push) Has been cancelled
Release binaries / Attach binaries to GitHub Release (push) Has been cancelled
Release binaries / Build macOS ARM64 (push) Has been cancelled
Release binaries / Build macOS x64 (push) Has been cancelled
Release binaries / Build Linux ARM64 (push) Has been cancelled
Release binaries / Build Linux musl ARM64 (push) Has been cancelled
Release binaries / Build Linux musl x64 (push) Has been cancelled
Release binaries / Build Linux x64 (push) Has been cancelled
Release binaries / Build Windows x64 (push) Has been cancelled
Release binaries / Attach binaries to GitHub Release (push) Has been cancelled
Move multi-agent isolation from blunt daemon-side filtering to relay-side group scoping, so a session can adopt new tabs again (follow-popup, OAuth results, cross-session adopt-by-targetId) without ever seeing the user's or another agent's tabs. Relay (relay.rs): track client->group (announced via new local ABRelay.setGroup, or the first createTarget's agentGroup) and target->group (created tabs tagged from the createTarget reply; an explicit attachToTarget tags the target into the adopter's group = #21; a pop-up inherits its opener's group via openerTargetId). Target.getTargets returns ONLY the requesting client's group; a client that never announced a group (older daemon) gets the full list — fully backward-compatible. +5 unit tests. Daemon (browser.rs): announce_group() on connect sets relay_scoped. Adoption in discover/resync/adopt_newly_opened is re-enabled ONLY when relay_scoped; without it (launch / real CDP / older relay that didn't answer the announce) the daemon keeps strict daemon-side isolation. So this can't regress the 125/125 isolation. Extension (ab-connect 0.4.10): synthesized Target.attachedToTarget targetInfo now carries openerTargetId (pop-ups inherit opener's group) and abGroup (the tab-group title, so the relay re-attributes existing tabs after ITS own restart, since createTarget tagging won't re-run). tabScopeHints(). Back-compat verified live: new daemon + OLD relay -> announce fails -> relay_scoped=false -> strict fallback, open/eval/url all work. The new extension (publish to CWS, strip manifest key) activates follow-popup; relay+daemon ship now. 861 tests pass.
This commit is contained in:
@@ -81,6 +81,35 @@ async function groupTabInto(tabId, name) {
|
||||
groupIdByName.set(name, gid)
|
||||
}
|
||||
|
||||
// Group-scoped relay isolation hints (issue #40). The relay scopes
|
||||
// Target.getTargets per agent by tab group; report two things in the synthesized
|
||||
// targetInfo so it can attribute each tab:
|
||||
// - abGroup: the tab's Chrome tab-group TITLE (= the owning session name), so
|
||||
// the relay can re-attribute existing tabs after a restart (createTarget
|
||||
// tagging won't re-run for already-open tabs).
|
||||
// - openerTargetId: the targetId of the tab that opened this one, so a pop-up
|
||||
// (window.open / target=_blank / OAuth result) inherits its opener's group
|
||||
// and the agent that opened it can follow it — without foreign tabs leaking.
|
||||
// Best-effort: any failure yields empty strings, which the relay ignores.
|
||||
async function tabScopeHints(tabId) {
|
||||
let openerTargetId = ''
|
||||
let abGroup = ''
|
||||
try {
|
||||
const t = await chrome.tabs.get(tabId)
|
||||
if (t) {
|
||||
if (typeof t.openerTabId === 'number') {
|
||||
const op = tabs.get(t.openerTabId)
|
||||
if (op) openerTargetId = op.targetId
|
||||
}
|
||||
if (t.groupId != null && t.groupId >= 0 && chrome.tabGroups) {
|
||||
const g = await chrome.tabGroups.get(t.groupId).catch(() => null)
|
||||
if (g && g.title) abGroup = g.title
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
return { openerTargetId, abGroup }
|
||||
}
|
||||
|
||||
function postToHost(msg) {
|
||||
try {
|
||||
if (port) port.postMessage(msg)
|
||||
@@ -126,7 +155,7 @@ function connectHost() {
|
||||
} catch {}
|
||||
// Tell the daemon about everything we already have attached, then attach
|
||||
// anything new.
|
||||
reannounceAttachedTabs()
|
||||
void reannounceAttachedTabs()
|
||||
void attachAllTabs()
|
||||
}
|
||||
|
||||
@@ -140,7 +169,7 @@ async function onHostMessage(msg) {
|
||||
// Daemon (re)connected — (re)attach and announce every tab so it discovers
|
||||
// the user's existing tabs rather than racing an empty target list.
|
||||
if (msg.method === 'attachAll') {
|
||||
reannounceAttachedTabs()
|
||||
void reannounceAttachedTabs()
|
||||
await attachAllTabs()
|
||||
return
|
||||
}
|
||||
@@ -387,12 +416,16 @@ async function attachTab(tabId) {
|
||||
sessionToTab.set(sessionId, tabId)
|
||||
rememberSessionTarget(sessionId, targetId)
|
||||
setBadge(tabId, port ? 'on' : 'connecting')
|
||||
const { openerTargetId, abGroup } = await tabScopeHints(tabId)
|
||||
postToHost({
|
||||
method: 'forwardCDPEvent',
|
||||
params: {
|
||||
sessionId,
|
||||
method: 'Target.attachedToTarget',
|
||||
params: { sessionId, targetInfo: { ...targetInfo, attached: true } },
|
||||
params: {
|
||||
sessionId,
|
||||
targetInfo: { ...targetInfo, attached: true, openerTargetId, abGroup },
|
||||
},
|
||||
},
|
||||
})
|
||||
return entry
|
||||
@@ -434,14 +467,21 @@ async function attachAllTabs() {
|
||||
}
|
||||
}
|
||||
|
||||
function reannounceAttachedTabs() {
|
||||
for (const [, entry] of tabs.entries()) {
|
||||
async function reannounceAttachedTabs() {
|
||||
for (const [tabId, entry] of tabs.entries()) {
|
||||
// Re-send the group hint too (issue #40) so the relay can rebuild its
|
||||
// targetId→group map after its own restart (createTarget tagging won't
|
||||
// re-run for tabs that are already open).
|
||||
const { openerTargetId, abGroup } = await tabScopeHints(tabId)
|
||||
postToHost({
|
||||
method: 'forwardCDPEvent',
|
||||
params: {
|
||||
sessionId: entry.sessionId,
|
||||
method: 'Target.attachedToTarget',
|
||||
params: { sessionId: entry.sessionId, targetInfo: { targetId: entry.targetId, type: 'page', attached: true } },
|
||||
params: {
|
||||
sessionId: entry.sessionId,
|
||||
targetInfo: { targetId: entry.targetId, type: 'page', attached: true, openerTargetId, abGroup },
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user