Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Support X group DM recipient binding

Emre Sokullu0a15deaf14c5
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 9c3256868..cbc65e4f0 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -23089,16 +23089,21 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const candidates = this._messageRecipientCandidates(probe);
if (candidates.length !== 1 || candidates[0].role !== 'to') return null;
const candidate = candidates[0];
- const handle = normalizeRecipientIdentity(candidate.identity);
- if (!/^@[a-z0-9_]{1,15}$/.test(handle)) return null;
+ const identity = normalizeRecipientIdentity(candidate.identity);
+ const accountHandle = /^@[a-z0-9_]{1,15}$/.test(identity);
+ const groupConversation = /^x-dm-group:[a-z0-9_-]{1,128}$/.test(identity);
+ if (!accountHandle && !groupConversation) return null;
const expected = normalizeRecipientIdentity(named.recipients[0].identity);
// Display names and bare usernames can resolve to the unique observed
// header. Once pinned, an @handle must match the account itself: another
// account cannot borrow its authorization through a display-name alias.
- const matches = expected.startsWith('@') ? expected === handle
+ // Group names resolve only to the current chat route/header identity; an
+ // @handle never resolves through a group label.
+ const matches = accountHandle && expected.startsWith('@') ? expected === identity
+ : groupConversation && expected.startsWith('@') ? false
: [candidate.identity, ...(Array.isArray(candidate.aliases) ? candidate.aliases : [])]
.some(alias => normalizeRecipientIdentity(alias) === expected);
- return matches ? { target_kind: 'named', recipients: [{ identity: handle, role: 'to' }] } : null;
+ return matches ? { target_kind: 'named', recipients: [{ identity, role: 'to' }] } : null;
}
async _pinActiveConversationMessagingTarget(tabId, messaging, pageUrl = '') {
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index d4c5af1d0..bdfe76cb5 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -5816,6 +5816,25 @@
strongIdentities.push(identity);
strongRecipients.push({ identity, role: 'to' });
observedRecipientCandidates.push({ identity, role: 'to', aliases: [identity, handle, compact(header.innerText)] });
+ } else {
+ // X group DM headers name the conversation instead of linking to a
+ // single account. Bind the visible header to the canonical chat
+ // route so a later conversation cannot inherit this authorization.
+ let groupIdentity = '';
+ try {
+ const groupId = new URL(location.href).pathname
+ .match(/^\/i\/chat\/([a-zA-Z0-9_-]{1,128})\/?$/)?.[1] || '';
+ if (groupId && compact(header.innerText)) groupIdentity = `x-dm-group:${groupId}`;
+ } catch {}
+ if (groupIdentity) {
+ strongIdentities.push(groupIdentity);
+ strongRecipients.push({ identity: groupIdentity, role: 'to' });
+ observedRecipientCandidates.push({
+ identity: groupIdentity,
+ role: 'to',
+ aliases: [groupIdentity, compact(header.innerText)],
+ });
+ }
}
}
} else {
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 9d488d39f..01678fad6 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -20848,16 +20848,21 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const candidates = this._messageRecipientCandidates(probe);
if (candidates.length !== 1 || candidates[0].role !== 'to') return null;
const candidate = candidates[0];
- const handle = normalizeRecipientIdentity(candidate.identity);
- if (!/^@[a-z0-9_]{1,15}$/.test(handle)) return null;
+ const identity = normalizeRecipientIdentity(candidate.identity);
+ const accountHandle = /^@[a-z0-9_]{1,15}$/.test(identity);
+ const groupConversation = /^x-dm-group:[a-z0-9_-]{1,128}$/.test(identity);
+ if (!accountHandle && !groupConversation) return null;
const expected = normalizeRecipientIdentity(named.recipients[0].identity);
// Display names and bare usernames can resolve to the unique observed
// header. Once pinned, an @handle must match the account itself: another
// account cannot borrow its authorization through a display-name alias.
- const matches = expected.startsWith('@') ? expected === handle
+ // Group names resolve only to the current chat route/header identity; an
+ // @handle never resolves through a group label.
+ const matches = accountHandle && expected.startsWith('@') ? expected === identity
+ : groupConversation && expected.startsWith('@') ? false
: [candidate.identity, ...(Array.isArray(candidate.aliases) ? candidate.aliases : [])]
.some(alias => normalizeRecipientIdentity(alias) === expected);
- return matches ? { target_kind: 'named', recipients: [{ identity: handle, role: 'to' }] } : null;
+ return matches ? { target_kind: 'named', recipients: [{ identity, role: 'to' }] } : null;
}
async _pinActiveConversationMessagingTarget(tabId, messaging, pageUrl = '') {
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index ccfac1b82..00c9645db 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -4988,6 +4988,25 @@
strongIdentities.push(identity);
strongRecipients.push({ identity, role: 'to' });
observedRecipientCandidates.push({ identity, role: 'to', aliases: [identity, handle, compact(header.innerText)] });
+ } else {
+ // X group DM headers name the conversation instead of linking to a
+ // single account. Bind the visible header to the canonical chat
+ // route so a later conversation cannot inherit this authorization.
+ let groupIdentity = '';
+ try {
+ const groupId = new URL(location.href).pathname
+ .match(/^\/i\/chat\/([a-zA-Z0-9_-]{1,128})\/?$/)?.[1] || '';
+ if (groupId && compact(header.innerText)) groupIdentity = `x-dm-group:${groupId}`;
+ } catch {}
+ if (groupIdentity) {
+ strongIdentities.push(groupIdentity);
+ strongRecipients.push({ identity: groupIdentity, role: 'to' });
+ observedRecipientCandidates.push({
+ identity: groupIdentity,
+ role: 'to',
+ aliases: [groupIdentity, compact(header.innerText)],
+ });
+ }
}
}
} else {
diff --git a/test/fixtures/message-recipient-navigation.mjs b/test/fixtures/message-recipient-navigation.mjs
index 546b793c6..59d97cb44 100644
--- a/test/fixtures/message-recipient-navigation.mjs
+++ b/test/fixtures/message-recipient-navigation.mjs
@@ -284,6 +284,79 @@ export function registerMessageRecipientNavigationFixtures({
assert.equal(await page.evaluate(() => window.fixtureSends), 6, 'blocked retries never dispatch');
});
+ register(`${kind}: X group DMs pin the visible conversation route and header`, async (page) => {
+ const { agent } = await setup(page);
+ const url = 'https://x.com/i/chat/group-123';
+ await page.goto(url);
+ await setupContentHtml(page, `<!doctype html><style>
+ #header {position:fixed;left:400px;top:20px}
+ textarea {position:fixed;left:400px;bottom:20px;width:400px;height:50px}
+ #send {position:fixed;left:820px;bottom:20px}
+ [role=log] {position:fixed;left:400px;top:100px;width:400px;height:300px}
+ </style><div id="header" data-testid="dm-conversation-username">Study Group</div>
+ <div role="log" data-testid="dm-message-scroller" aria-busy="false"></div>
+ <textarea data-testid="dm-composer-textarea"></textarea><button id="send" type="button">Send</button>`, kind);
+ await page.evaluate(() => {
+ window.fixtureSends = 0;
+ document.querySelector('#send').addEventListener('click', () => {
+ const composer = document.querySelector('textarea');
+ const row = document.createElement('div');
+ row.dataset.testid = 'message-' + ++window.fixtureSends;
+ row.dataset.sendStatus = 'sent'; row.className = 'justify-end';
+ const content = document.createElement('div'); content.dataset.testid = 'message-text-' + window.fixtureSends;
+ const body = document.createElement('span'); body.dir = 'auto'; body.textContent = composer.value;
+ content.append(body); row.append(content); document.querySelector('[role=log]').append(row);
+ composer.value = '';
+ });
+ });
+ const group = { target_kind: 'named', recipients: [{ identity: 'x-dm-group:group-123', role: 'to' }] };
+ const named = identity => ({ target_kind: 'named', recipients: [{ identity, role: 'to' }] });
+ const activePin = await agent._pinActiveConversationMessagingTarget(
+ 1, { target_kind: 'active_conversation', recipients: [] }, url,
+ );
+ assert.equal(activePin.ok, true, JSON.stringify(activePin));
+ assert.equal(activePin.target.target_kind, 'named');
+ assert.deepEqual(activePin.target.recipients.map(({ identity, role }) => ({ identity, role })), group.recipients,
+ 'the active group gets a route-bound identity');
+ const namedPin = await agent._pinActiveConversationMessagingTarget(1, named('Study Group'), url);
+ assert.deepEqual(namedPin.target, group, 'the visible group name resolves to that route');
+ const handlePin = await agent._pinActiveConversationMessagingTarget(1, named('@studygroup'), url);
+ assert.deepEqual(handlePin.target, named('@studygroup'), 'a group label cannot stand in for an account handle');
+
+ const workflow = agent._resolvePlannerSiteWorkflow(url, {
+ request_kind: 'execute', requires_submission: true, messaging: activePin.target,
+ });
+ const guard = agent._startPlanExecutionGuard(1, 'act', {
+ requestKind: 'execute', requiresStateChange: true, requiresSubmission: true,
+ messaging: activePin.target, siteWorkflow: workflow,
+ });
+ guard.workflowMetadataRequirementsResolved = true;
+ await page.locator('textarea').fill('Hello Study Group');
+ const execution = {};
+ assert.equal(await agent._messageRecipientGuardBlock(1, 'click', { selector: '#send' }, url, execution), null);
+ assert.deepEqual(guard.messaging, group);
+ const clicked = await call(page, 'click', { selector: '#send', ...execution });
+ assert.equal(clicked.success, true, JSON.stringify(clicked));
+ agent._recordCompletionSubmitAttempt(1, { isSubmit: false }, 'click', { selector: '#send' },
+ url, url, clicked, 'doc', 'doc', execution);
+ const submit = agent._completionSubmitStates.get(1);
+ submit.observedAfterSubmit = true;
+ const terminalProbe = await call(page, 'probe_message_recipient_guard', {
+ tool: 'observe_active_conversation', adapterName: 'twitter', expectedMessageBody: 'Hello Study Group',
+ });
+ const terminal = agent._workflowTerminalEvidenceFromDone(1, { relevantFormCount: 1 }, url,
+ { submit, relevantForms: 1, verifiedFinalSubmit: false }, terminalProbe);
+ assert.equal(terminal?.verificationKind, 'message_sent', 'the group send has delivery evidence');
+
+ await page.locator('textarea').fill('This must not send');
+ const staleExecution = {};
+ assert.equal(await agent._messageRecipientGuardBlock(1, 'click', { selector: '#send' }, url, staleExecution), null);
+ await page.evaluate(() => history.pushState({}, '', '/i/chat/group-456'));
+ const stale = await call(page, 'click', { selector: '#send', ...staleExecution });
+ assert.equal(stale.noDispatch, true, 'a changed conversation route invalidates the dispatch binding');
+ assert.equal(await page.evaluate(() => window.fixtureSends), 1, 'the stale retry never dispatches');
+ });
+
register(`${kind}: X conversation navigation is not classified as sending a message`, async (page) => {
const { agent } = await setup(page);
await page.goto('https://x.com/i/chat/123-456');