Skip to content

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

Withdraw the same-origin completion fallback entirely

Emre Sokullu9b6971932d12
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 777d60a0b..c56a7ad8b 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -1642,18 +1642,6 @@ export class Agent extends LoopDetector {
return null;
}
- _sameUrlOrigin(a, b) {
- try {
- const origin = new URL(String(a || '')).origin;
- // file:, data: and about:blank all serialise to the string "null", so
- // comparing those would make two unrelated documents look same-origin.
- if (!origin || origin === 'null') return false;
- return origin === new URL(String(b || '')).origin;
- } catch (_) {
- return false;
- }
- }
-
_completionSubmissionEvidence(tabId, pageState, pageUrl = '') {
if (!pageState) return { verifiedFinalSubmit: false, liveSignals: [], relevantForms: 0 };
const relevantForms = Number(pageState.relevantFormCount || 0);
@@ -1661,38 +1649,20 @@ export class Agent extends LoopDetector {
? pageState.successMessages.filter(text => this._completionTextSignalsSuccess(text, { allowBare: true }))
: [];
const submit = this._completionSubmitStates.get(tabId);
- const observedUrl = pageUrl || pageState.url || '';
- const normalizedObserved = this._normalizeUrl(observedUrl);
- // What this needs to establish is that the page being reported belongs to
- // the site that was submitted to, so another site's submit cannot stand in
- // for this one. Demanding the exact document the last post-submit read saw
- // punished the very navigation the completion guard asks for: a single-page
- // app confirms a publish by opening the new resource, and the tools that
- // navigate there are not in the observation set, so the act of verifying
- // moved the page off the document that carried the evidence.
- //
- // Everything else stays as strict as it was. A submit still has to be
- // dispatched, still has to be observed afterwards, and still has to have
- // changed the document or produced a success signal.
- const observedSuccessSignal = !!submit?.completionSignalObserved || liveSignals.length > 0;
- // Same origin alone is not evidence that this route came from the submit:
- // navigating to /home after a no-op submit is same-origin too. The
- // destination has to be submit-correlated β€” the published resource itself,
- // or a page carrying an explicit success signal.
- // Resolve the adapter from the observed URL when no workflow job was
- // selected, so a recognised published-resource route still counts. A
- // single-page app publish rarely has a workflow job, and that is exactly
- // the case that needs this.
- const observedPublishedResource = !!this._workflowPublishedResourceIdentity(
- this._planExecutionGuards.get(tabId)?.siteWorkflow
- || { adapterName: getActiveAdapter(observedUrl)?.name || '' },
- observedUrl,
- );
- const currentDocumentMatchesSubmit = !!submit && (
- (!!submit.currentUrl && this._normalizeUrl(submit.currentUrl) === normalizedObserved)
- || ((observedPublishedResource || observedSuccessSignal)
- && this._sameUrlOrigin(observedUrl, submit.originatingUrl || submit.currentUrl || ''))
+ // The document reported at completion must be the one the last post-submit
+ // read saw. Loosening this to same-origin was tried and withdrawn twice:
+ // without a payload check there is nothing here that distinguishes the
+ // resource this run published from any other page on the site, so an
+ // unrelated route β€” or a pre-existing post that merely looks like a
+ // published resource β€” could stand in for a publish that never happened.
+ // A single-page app that navigates to confirm its own publish is steered
+ // by the completion block instead: it says to read the resulting page in
+ // the same tab and call done from there, which satisfies this directly.
+ const currentDocumentMatchesSubmit = !!(
+ submit?.currentUrl
+ && this._normalizeUrl(pageUrl || pageState.url || '') === this._normalizeUrl(submit.currentUrl)
);
+ const observedSuccessSignal = !!submit?.completionSignalObserved || liveSignals.length > 0;
const verifiedSubmit = !!(
submit?.dispatched
&& submit.observedAfterSubmit
@@ -2292,13 +2262,6 @@ export class Agent extends LoopDetector {
) {
return `douyin:${host}${path}`;
}
- if (
- siteWorkflow?.adapterName === 'bluesky'
- && host === 'bsky.app'
- && /^\/profile\/[^/]+\/post\/[^/]+$/i.test(path)
- ) {
- return `bluesky:${host}${path}`;
- }
return '';
}
@@ -27399,7 +27362,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
.map(link => {
try { return new URL(link.getAttribute('href') || link.href || '', location.href).href; } catch { return ''; }
})
- .filter(url => /linkedin\\.com\\/(?:feed\\/update|posts)\\/|github\\.com\\/[^/]+\\/[^/]+\\/releases\\/tag\\/|douyin\\.com\\/video\\/\\d+|bsky\\.app\\/profile\\/[^/]+\\/post\\//i.test(url))
+ .filter(url => /linkedin\\.com\\/(?:feed\\/update|posts)\\/|github\\.com\\/[^/]+\\/[^/]+\\/releases\\/tag\\/|douyin\\.com\\/video\\/\\d+/i.test(url))
.slice(0, 200);
return {
openDialogCount: dialogs.length,
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 55c5ba4bd..6fa5ec125 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -1356,18 +1356,6 @@ export class Agent extends LoopDetector {
return null;
}
- _sameUrlOrigin(a, b) {
- try {
- const origin = new URL(String(a || '')).origin;
- // file:, data: and about:blank all serialise to the string "null", so
- // comparing those would make two unrelated documents look same-origin.
- if (!origin || origin === 'null') return false;
- return origin === new URL(String(b || '')).origin;
- } catch (_) {
- return false;
- }
- }
-
_completionSubmissionEvidence(tabId, pageState, pageUrl = '') {
if (!pageState) return { verifiedFinalSubmit: false, liveSignals: [], relevantForms: 0 };
const relevantForms = Number(pageState.relevantFormCount || 0);
@@ -1375,38 +1363,20 @@ export class Agent extends LoopDetector {
? pageState.successMessages.filter(text => this._completionTextSignalsSuccess(text, { allowBare: true }))
: [];
const submit = this._completionSubmitStates.get(tabId);
- const observedUrl = pageUrl || pageState.url || '';
- const normalizedObserved = this._normalizeUrl(observedUrl);
- // What this needs to establish is that the page being reported belongs to
- // the site that was submitted to, so another site's submit cannot stand in
- // for this one. Demanding the exact document the last post-submit read saw
- // punished the very navigation the completion guard asks for: a single-page
- // app confirms a publish by opening the new resource, and the tools that
- // navigate there are not in the observation set, so the act of verifying
- // moved the page off the document that carried the evidence.
- //
- // Everything else stays as strict as it was. A submit still has to be
- // dispatched, still has to be observed afterwards, and still has to have
- // changed the document or produced a success signal.
- const observedSuccessSignal = !!submit?.completionSignalObserved || liveSignals.length > 0;
- // Same origin alone is not evidence that this route came from the submit:
- // navigating to /home after a no-op submit is same-origin too. The
- // destination has to be submit-correlated β€” the published resource itself,
- // or a page carrying an explicit success signal.
- // Resolve the adapter from the observed URL when no workflow job was
- // selected, so a recognised published-resource route still counts. A
- // single-page app publish rarely has a workflow job, and that is exactly
- // the case that needs this.
- const observedPublishedResource = !!this._workflowPublishedResourceIdentity(
- this._planExecutionGuards.get(tabId)?.siteWorkflow
- || { adapterName: getActiveAdapter(observedUrl)?.name || '' },
- observedUrl,
- );
- const currentDocumentMatchesSubmit = !!submit && (
- (!!submit.currentUrl && this._normalizeUrl(submit.currentUrl) === normalizedObserved)
- || ((observedPublishedResource || observedSuccessSignal)
- && this._sameUrlOrigin(observedUrl, submit.originatingUrl || submit.currentUrl || ''))
+ // The document reported at completion must be the one the last post-submit
+ // read saw. Loosening this to same-origin was tried and withdrawn twice:
+ // without a payload check there is nothing here that distinguishes the
+ // resource this run published from any other page on the site, so an
+ // unrelated route β€” or a pre-existing post that merely looks like a
+ // published resource β€” could stand in for a publish that never happened.
+ // A single-page app that navigates to confirm its own publish is steered
+ // by the completion block instead: it says to read the resulting page in
+ // the same tab and call done from there, which satisfies this directly.
+ const currentDocumentMatchesSubmit = !!(
+ submit?.currentUrl
+ && this._normalizeUrl(pageUrl || pageState.url || '') === this._normalizeUrl(submit.currentUrl)
);
+ const observedSuccessSignal = !!submit?.completionSignalObserved || liveSignals.length > 0;
const verifiedSubmit = !!(
submit?.dispatched
&& submit.observedAfterSubmit
@@ -2006,13 +1976,6 @@ export class Agent extends LoopDetector {
) {
return `douyin:${host}${path}`;
}
- if (
- siteWorkflow?.adapterName === 'bluesky'
- && host === 'bsky.app'
- && /^\/profile\/[^/]+\/post\/[^/]+$/i.test(path)
- ) {
- return `bluesky:${host}${path}`;
- }
return '';
}
@@ -23872,7 +23835,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
.map(link => {
try { return new URL(link.getAttribute('href') || link.href || '', location.href).href; } catch { return ''; }
})
- .filter(url => /linkedin\\.com\\/(?:feed\\/update|posts)\\/|github\\.com\\/[^/]+\\/[^/]+\\/releases\\/tag\\/|douyin\\.com\\/video\\/\\d+|bsky\\.app\\/profile\\/[^/]+\\/post\\//i.test(url))
+ .filter(url => /linkedin\\.com\\/(?:feed\\/update|posts)\\/|github\\.com\\/[^/]+\\/[^/]+\\/releases\\/tag\\/|douyin\\.com\\/video\\/\\d+/i.test(url))
.slice(0, 200);
return {
url: location.href,
diff --git a/test/run.js b/test/run.js
index 7c5b2dbc9..0b3c6718f 100644
--- a/test/run.js
+++ b/test/run.js
@@ -84828,15 +84828,15 @@ test('YouTube metadata success requires exact app-classified post-save readback'
}
});
-test('single-page app publish evidence survives the verification navigation', () => {
+test('completion evidence still requires the reported document to be the observed one', () => {
for (const AgentClass of [AgentCh, AgentFx]) {
const agent = new AgentClass({ getVisionProvider: async () => null });
const tabId = 8801;
const pageState = { relevantFormCount: 0, successMessages: [] };
const postUrl = 'https://bsky.app/profile/webbrain-one.bsky.social/post/3mutnbiq6d22s';
- const publishedSubmit = (overrides = {}) => ({
+ const submitState = (overrides = {}) => ({
originatingUrl: 'https://bsky.app/',
- currentUrl: 'https://bsky.app/profile/webbrain-one.bsky.social',
+ currentUrl: postUrl,
submitLike: true,
dispatched: true,
documentChanged: true,
@@ -84846,50 +84846,40 @@ test('single-page app publish evidence survives the verification navigation', ()
...overrides,
});
- // The completion guard asks the agent to go and observe the resulting
- // state. Doing exactly that lands done on a document the post-submit reads
- // never saw, which used to invalidate the evidence the guard demanded.
- agent._completionSubmitStates.set(tabId, publishedSubmit());
+ // The supported route for a single-page app publish: read the resulting
+ // page, which moves currentUrl to it, then call done from there. This is
+ // what the job-free completion block now tells the model to do.
+ agent._completionSubmitStates.set(tabId, submitState());
assert.equal(
agent._completionSubmissionEvidence(tabId, pageState, postUrl).verifiedFinalSubmit,
true,
- `${AgentClass.name}: navigating to the published resource invalidated its own evidence`,
+ `${AgentClass.name}: reading the resulting page did not produce completion evidence`,
);
- // Same origin on its own is not evidence the route came from the submit.
- // Navigating to an unrelated same-origin page after a no-op submit must
- // not be accepted as the submitted document.
- agent._completionSubmitStates.set(tabId, publishedSubmit({ currentUrl: 'https://bsky.app/' }));
+ // Reaching a page that merely looks like a published resource proves
+ // nothing on its own. Without a payload check there is no way to tell the
+ // resource this run published from a pre-existing one, so an unobserved
+ // destination must not stand in for the submitted document.
+ agent._completionSubmitStates.set(tabId, submitState({ currentUrl: 'https://bsky.app/' }));
assert.equal(
- agent._completionSubmissionEvidence(tabId, pageState, 'https://bsky.app/home').verifiedFinalSubmit,
+ agent._completionSubmissionEvidence(tabId, pageState, postUrl).verifiedFinalSubmit,
false,
- `${AgentClass.name}: an unrelated same-origin route stood in for the submitted document`,
+ `${AgentClass.name}: an unobserved post-shaped URL stood in for the submitted document`,
);
-
- // An explicit success signal is the other way a destination qualifies.
- agent._completionSubmitStates.set(tabId, publishedSubmit({ currentUrl: 'https://bsky.app/' }));
assert.equal(
- agent._completionSubmissionEvidence(
- tabId,
- { relevantFormCount: 0, successMessages: ['Post published successfully'] },
- 'https://bsky.app/home',
- ).verifiedFinalSubmit,
- true,
- `${AgentClass.name}: an explicit success signal did not qualify the destination`,
+ agent._completionSubmissionEvidence(tabId, pageState, 'https://bsky.app/home').verifiedFinalSubmit,
+ false,
+ `${AgentClass.name}: an unrelated same-origin route stood in for the submitted document`,
);
- // The observation requirement stays: done still cannot stand in for the
- // read the guard asks for after a submit.
- agent._completionSubmitStates.set(tabId, publishedSubmit({ observedAfterSubmit: false }));
+ // The rest of the contract is unchanged.
+ agent._completionSubmitStates.set(tabId, submitState({ observedAfterSubmit: false }));
assert.equal(
agent._completionSubmissionEvidence(tabId, pageState, postUrl).verifiedFinalSubmit,
false,
`${AgentClass.name}: a submit with no observation after it was accepted`,
);
-
- // Still no completion when nothing actually changed: a dispatched click on
- // a page that stayed put and produced no success signal proves nothing.
- agent._completionSubmitStates.set(tabId, publishedSubmit({
+ agent._completionSubmitStates.set(tabId, submitState({
currentUrl: 'https://bsky.app/',
documentChanged: false,
}));
@@ -84898,42 +84888,6 @@ test('single-page app publish evidence survives the verification navigation', ()
false,
`${AgentClass.name}: an unchanged page after a submit-like click counted as completion`,
);
-
- // Another site's submit must never stand in for this one.
- agent._completionSubmitStates.set(tabId, publishedSubmit({
- originatingUrl: 'https://example.com/compose',
- currentUrl: 'https://example.com/compose',
- }));
- assert.equal(
- agent._completionSubmissionEvidence(tabId, pageState, postUrl).verifiedFinalSubmit,
- false,
- `${AgentClass.name}: a submit on a different origin satisfied this task`,
- );
-
- // Opaque origins all serialise to "null", so two unrelated local documents
- // must not compare as the same origin.
- assert.equal(agent._sameUrlOrigin('file:///tmp/a/form.html', 'file:///tmp/b/other.html'), false,
- `${AgentClass.name}: unrelated file: documents compared as same-origin`);
- assert.equal(agent._sameUrlOrigin('https://bsky.app/a', 'https://bsky.app/b'), true);
-
- // Bluesky posts get a stable published-resource identity; a profile or
- // feed URL is not one.
- assert.equal(
- agent._workflowPublishedResourceIdentity({ adapterName: 'bluesky' }, postUrl),
- 'bluesky:bsky.app/profile/webbrain-one.bsky.social/post/3mutnbiq6d22s',
- `${AgentClass.name}: a published Bluesky post produced no resource identity`,
- );
- for (const notAPost of [
- 'https://bsky.app/profile/webbrain-one.bsky.social',
- 'https://bsky.app/',
- 'https://example.com/profile/a/post/b',
- ]) {
- assert.equal(
- agent._workflowPublishedResourceIdentity({ adapterName: 'bluesky' }, notAPost),
- '',
- `${AgentClass.name}: ${notAPost} was accepted as a published post`,
- );
- }
}
});