Skip to content

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

fix: restore Discord navigation and durable delivery evidence

Emre Sokullu9a60f1cff04c
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index a2cf03e85..cf1be2486 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -23033,7 +23033,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
},
};
this.chatSessions.set(tabId, dispatchedSession);
- try { await this._persistNow(tabId); } catch {}
+ let dispatchStatePersisted = false;
+ try {
+ const persisted = await this._persistNow(tabId);
+ dispatchStatePersisted = persisted === true || persisted?.ok === true;
+ } catch {}
+ if (!dispatchStatePersisted) {
+ // The pending record without a dispatch marker was persisted before
+ // typing. Keep that durable state so a restart cannot treat an
+ // unknown-direction Discord bubble as proof of delivery.
+ dispatchedSession = pending;
+ this.chatSessions.set(tabId, dispatchedSession);
+ }
}
const after = await this._readChatObservation(tabId);
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index d0b3c1080..9d319dce6 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -5878,7 +5878,7 @@
|| !/^(?:www\.)?discord\.com$/.test(location.hostname)
|| !/^\/channels\/(?:\d+|@me)(?:\/\d+)?\/?$/.test(location.pathname)) return false;
const control = _composedClosestElement(clicked,
- 'button,a[href],input,select,textarea,[role="textbox"],[role="button"],[role="menuitem"],[role="tab"],[role="switch"],[role="radio"],[role="checkbox"]');
+ 'button,a[href],input,select,textarea,[role="textbox"],[role="button"],[role="menuitem"],[role="tab"],[role="treeitem"],[role="switch"],[role="radio"],[role="checkbox"]');
if (!control || !visible(control) || control.disabled
|| control.getAttribute('aria-disabled') === 'true'
|| _composedClosestElement(control,
@@ -5942,9 +5942,24 @@
&& control.matches('button:not([role])')
&& control.parentElement?.matches('[class*="buttons"]')) return true;
const nav = _composedClosestElement(control, 'nav,[role="navigation"]');
+ if (!nav) return false;
+ const serverRailItem = _composedClosestElement(control, '[role="treeitem"][data-list-item-id^="guildsnav___"]');
+ if (serverRailItem) {
+ const guildsTree = _composedClosestElement(serverRailItem, '[role="tree"][data-list-id="guildsnav"]');
+ return /^guildsnav___(?:home|\d+)$/.test(serverRailItem.getAttribute('data-list-item-id') || '')
+ && !!guildsTree && _isComposedAncestor(nav, guildsTree);
+ }
+ if (control.matches('a[href][data-list-item-id^="private-channels-"]')) {
+ try {
+ const destination = new URL(control.getAttribute('href'), location.href);
+ return destination.origin === location.origin && !destination.search && !destination.hash
+ && !destination.username && !destination.password
+ && /^\/channels\/@me(?:\/\d+)?\/?$/.test(destination.pathname);
+ } catch { return false; }
+ }
const channelsList = nav?.querySelector('#channels');
const serverHeader = nav?.querySelector('header');
- if (!nav || !channelsList || !serverHeader) return false;
+ if (!channelsList || !serverHeader) return false;
if (control.matches('a[href]')) {
const destination = new URL(control.getAttribute('href'), location.href);
return destination.origin === location.origin && !destination.search && !destination.hash
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 2006f4f47..982a3d465 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -20776,7 +20776,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
},
};
this.chatSessions.set(tabId, dispatchedSession);
- try { await this._persistNow(tabId); } catch {}
+ let dispatchStatePersisted = false;
+ try {
+ const persisted = await this._persistNow(tabId);
+ dispatchStatePersisted = persisted === true || persisted?.ok === true;
+ } catch {}
+ if (!dispatchStatePersisted) {
+ // The pending record without a dispatch marker was persisted before
+ // typing. Keep that durable state so a restart cannot treat an
+ // unknown-direction Discord bubble as proof of delivery.
+ dispatchedSession = pending;
+ this.chatSessions.set(tabId, dispatchedSession);
+ }
}
const after = await this._readChatObservation(tabId);
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index 3618e8194..6c38f942b 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -4956,7 +4956,7 @@
|| !/^(?:www\.)?discord\.com$/.test(location.hostname)
|| !/^\/channels\/(?:\d+|@me)(?:\/\d+)?\/?$/.test(location.pathname)) return false;
const control = _composedClosestElement(clicked,
- 'button,a[href],input,select,textarea,[role="textbox"],[role="button"],[role="menuitem"],[role="tab"],[role="switch"],[role="radio"],[role="checkbox"]');
+ 'button,a[href],input,select,textarea,[role="textbox"],[role="button"],[role="menuitem"],[role="tab"],[role="treeitem"],[role="switch"],[role="radio"],[role="checkbox"]');
if (!control || !visible(control) || control.disabled
|| control.getAttribute('aria-disabled') === 'true'
|| _composedClosestElement(control,
@@ -5020,9 +5020,24 @@
&& control.matches('button:not([role])')
&& control.parentElement?.matches('[class*="buttons"]')) return true;
const nav = _composedClosestElement(control, 'nav,[role="navigation"]');
+ if (!nav) return false;
+ const serverRailItem = _composedClosestElement(control, '[role="treeitem"][data-list-item-id^="guildsnav___"]');
+ if (serverRailItem) {
+ const guildsTree = _composedClosestElement(serverRailItem, '[role="tree"][data-list-id="guildsnav"]');
+ return /^guildsnav___(?:home|\d+)$/.test(serverRailItem.getAttribute('data-list-item-id') || '')
+ && !!guildsTree && _isComposedAncestor(nav, guildsTree);
+ }
+ if (control.matches('a[href][data-list-item-id^="private-channels-"]')) {
+ try {
+ const destination = new URL(control.getAttribute('href'), location.href);
+ return destination.origin === location.origin && !destination.search && !destination.hash
+ && !destination.username && !destination.password
+ && /^\/channels\/@me(?:\/\d+)?\/?$/.test(destination.pathname);
+ } catch { return false; }
+ }
const channelsList = nav?.querySelector('#channels');
const serverHeader = nav?.querySelector('header');
- if (!nav || !channelsList || !serverHeader) return false;
+ if (!channelsList || !serverHeader) return false;
if (control.matches('a[href]')) {
const destination = new URL(control.getAttribute('href'), location.href);
return destination.origin === location.origin && !destination.search && !destination.hash
diff --git a/test/discord-guard.mjs b/test/discord-guard.mjs
index 3f2e314ce..42bf680a5 100644
--- a/test/discord-guard.mjs
+++ b/test/discord-guard.mjs
@@ -168,6 +168,20 @@ for (const [kind, engine, AgentClass, policy] of [
assert.equal(await guard('click',{selector:'#theme-control'}),null);
} finally {await page.close();}
});
+ await t.test('DM and server rail navigation stays available outside the channel rail',async()=>{
+ const {page,guard,probe}=await setup(`<nav id="guilds-sidebar" style="position:fixed;left:0;top:0;width:200px;height:80px;z-index:50;background:white"><div role="tree" data-list-id="guildsnav"><div id="guild-rail-link" role="treeitem" data-list-item-id="guildsnav___789">Server</div></div></nav>
+<nav id="dm-sidebar" style="position:fixed;left:0;top:100px;width:200px;height:100px;z-index:50;background:white"><a id="dm-rail-link" data-list-item-id="private-channels-uid_11___123" href="/channels/@me/123">Direct message</a><a id="dm-wrong-route" data-list-item-id="private-channels-uid_11___124" href="/channels/123/456?unexpected=1">Unexpected route</a></nav>
+<a id="dm-lookalike" href="/channels/@me/123">Lookalike</a>`);
+ try {
+ await page.evaluate(()=>history.replaceState(null,'','/channels/@me/456'));
+ for(const selector of ['#dm-rail-link','#guild-rail-link']) {
+ assert.equal((await probe('click',{selector})).nonMessagingTarget,true,`${selector} has a structurally verified Discord rail destination`);
+ assert.equal(await guard('click',{selector}),null,`${selector} is not blocked as a message action`);
+ }
+ assert.notEqual((await probe('click',{selector:'#dm-wrong-route'})).nonMessagingTarget,true,'DM rail metadata does not authorize query-bearing routes');
+ assert.notEqual((await probe('click',{selector:'#dm-lookalike'})).nonMessagingTarget,true,'an ordinary same-origin link is not a DM rail item');
+ } finally {await page.close();}
+ });
await t.test('sends, message actions, lookalikes and foreign origins remain protected',async()=>{
const {page,guard,probe}=await setup();
try {
diff --git a/test/run.js b/test/run.js
index 8902f381a..d16f1c867 100644
--- a/test/run.js
+++ b/test/run.js
@@ -6964,6 +6964,43 @@ test('chat workflow state survives worker restart and is durable before dispatch
assert.equal(discordSent.deliveryVerified, true, `${AgentClass.name}: exact fresh Discord bubble and empty composer did not verify the pending send`);
assert.equal(discordSent.chatWorkflow.newMessages[0].direction, 'unknown', `${AgentClass.name}: delivery verification must not claim the Discord message author`);
assert.equal(discordSender.chatSessions.get(tabId)?.pendingOutbound, null, `${AgentClass.name}: default-avatar Discord send remained pending`);
+
+ const nondurableMarkerSender = new AgentClass({});
+ nondurableMarkerSender.conversations.set(tabId, [{ role: 'system', content: 'system' }]);
+ nondurableMarkerSender.conversationIds.set(tabId, `conversation-discord-nondurable-${index}`);
+ nondurableMarkerSender._persist = () => {};
+ let dispatchPersistenceAttempts = 0;
+ nondurableMarkerSender._persistNow = async () => {
+ dispatchPersistenceAttempts += 1;
+ return dispatchPersistenceAttempts === 1 ? { ok: true } : { ok: false, degraded: true };
+ };
+ nondurableMarkerSender._messageRecipientGuardBlock = async () => null;
+ let nondurableAfter;
+ const nondurableObservations = [discordBefore];
+ nondurableMarkerSender._readChatObservation = async () => nondurableObservations.shift() || nondurableAfter;
+ nondurableMarkerSender.executeTool = async () => {
+ const observedAt = new Date().toISOString();
+ nondurableAfter = {
+ ...discordBefore,
+ observedAt,
+ messages: [{
+ id: `discord:nondurable:${index}`,
+ direction: 'unknown',
+ text: 'Send once with a default avatar.',
+ timestamp: observedAt,
+ }],
+ };
+ return { success: true, dispatched: true };
+ };
+ const nondurableSent = await nondurableMarkerSender._sendChatWorkflow(tabId, {
+ thread_key: discordThreadKey,
+ composer_ref: `composer-${index}`,
+ text: 'Send once with a default avatar.',
+ });
+ assert.equal(dispatchPersistenceAttempts, 2, `${AgentClass.name}: dispatch marker persistence was not attempted after the send`);
+ assert.equal(nondurableSent.deliveryVerified, false, `${AgentClass.name}: an unknown-direction Discord bubble was verified without a durable dispatch marker`);
+ assert.ok(nondurableMarkerSender.chatSessions.get(tabId)?.pendingOutbound, `${AgentClass.name}: uncertain send was cleared after marker persistence failed`);
+ assert.equal(nondurableMarkerSender.chatSessions.get(tabId)?.pendingOutbound?.dispatchedAt, undefined, `${AgentClass.name}: failed dispatch marker remained in memory`);
}
} finally {
if (previousChrome === undefined) delete globalThis.chrome;