Skip to content

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

Retire stale CAPTCHA documents consistently across recovery paths

Emre Sokullu4b932ef1c4c6
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 5dff58da0..8d87d3f55 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -10883,7 +10883,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// Keep dispatchedTimeOrigins to prevent a second paid solve if the old
// document is restored, but never apply its answer to the new page.
delete record.solution;
- return true;
+ const newlyRetired = record.documentRetired !== true;
+ record.documentRetired = true;
+ return newlyRetired;
}
return false;
}
@@ -35904,7 +35906,10 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai
delete record.solution;
// A new root may expose a new CAPTCHA. A reloaded child frame in
// the same root has already used this document's paid dispatch.
- if (documentStatus === 'root_changed') this._captchaGateStates.delete(tabId);
+ if (documentStatus === 'root_changed') {
+ record.documentRetired = true;
+ this._captchaGateStates.delete(tabId);
+ }
return false;
}
return true;
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index e18f92b62..bacf34b0c 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -9557,7 +9557,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// Keep dispatchedTimeOrigins to prevent a second paid solve if the old
// document is restored, but never apply its answer to the new page.
delete record.solution;
- return true;
+ const newlyRetired = record.documentRetired !== true;
+ record.documentRetired = true;
+ return newlyRetired;
}
return false;
}
@@ -32890,7 +32892,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
delete record.solution;
// A new root may expose a new CAPTCHA. A reloaded child frame in
// the same root has already used this document's paid dispatch.
- if (documentStatus === 'root_changed') this._captchaGateStates.delete(tabId);
+ if (documentStatus === 'root_changed') {
+ record.documentRetired = true;
+ this._captchaGateStates.delete(tabId);
+ }
return false;
}
return true;
diff --git a/test/captcha-runtime-policy.mjs b/test/captcha-runtime-policy.mjs
index deb0d3cb1..af87991ba 100644
--- a/test/captcha-runtime-policy.mjs
+++ b/test/captcha-runtime-policy.mjs
@@ -377,6 +377,12 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(record.solution, undefined);
assert.equal(record.dispatchedTimeOrigins.has(1000), true);
assert.equal(agent._captchaGateStates.has(1), false);
+ const newGate = { status: 'solve_required', publicGate: { status: 'solve_required' } };
+ agent._captchaGateStates.set(1, newGate);
+ assert.equal(agent._retireNativeCaptchaAnswerIfPageChanged(1, to), false,
+ 'later reads must not retire the same old document again');
+ await agent._pendingNativeCaptchaAnswer(1, { tabs: { get: async () => ({ url: to }) } });
+ assert.equal(agent._captchaGateStates.get(1), newGate);
});
test(`${build}: an unexpired paid native answer survives background restart with its gate`, async () => {
const agent = agentFor('act', 'full');
@@ -457,6 +463,11 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(record.solution, undefined);
assert.equal(record.dispatchedTimeOrigins.has(1000), true);
assert.equal(agent._captchaGateStates.has(1), false);
+ const newGate = { status: 'solve_required', publicGate: { status: 'solve_required' } };
+ agent._captchaGateStates.set(1, newGate);
+ await agent._pendingNativeCaptchaAnswer(1, api);
+ assert.equal(agent._captchaGateStates.get(1), newGate,
+ 'discovery must not retire a document already retired by application');
} finally {
if (previous === undefined) delete globalThis[key]; else globalThis[key] = previous;
}