Skip to content

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

Require complete CAPTCHA fallback identifiers and preserve falsy answers

Emre Sokullu4c2326132651
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index f825e1a4a..96fcdbfab 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -10840,6 +10840,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
&& !state?.solveAttempted && !state?.solveFailed && !state?.activeChallengeAfterSolve;
}
+ _hasUnappliedNativeCaptchaSolution(tabId) {
+ const record = this._nativeCaptchaSolutions?.get(tabId);
+ return record?.solution !== undefined && record.applied !== true;
+ }
+
_captchaRoutingMessage(tabId, captchaGateDecision, captchaSolveOutcome, toolResult = {}, onUpdate = () => {}) {
let resultContent = '';
const gate = captchaGateDecision || captchaSolveOutcome;
@@ -10866,7 +10871,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
onUpdate('warning', { message: 'Manual completion confirmed the unrecognized challenge cleared.' });
}
} else if ((captchaGateDecision || captchaSolveOutcome)?.status === 'verification_pending'
- && this._nativeCaptchaSolutions?.get(tabId)?.solution && !this._nativeCaptchaSolutions.get(tabId).applied) {
+ && this._hasUnappliedNativeCaptchaSolution(tabId)) {
resultContent += '\n[TRUSTED CAPTCHA GATE: The native answer is ready but has not been applied. Inspect the page and use apply_captcha_solution, then verify fresh page state.]';
} else if (captchaGateDecision?.status === 'verification_pending') {
resultContent += '\n[TRUSTED CAPTCHA GATE: Verification is still pending because the exact widget has no response token or its frame state could not be inspected conclusively. Wait briefly, then read the page again. Do not submit, dismiss, or call solve_captcha again.]';
@@ -10928,7 +10933,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
manualCompletionRequired: true,
error: 'Verification requires manual completion in this mode/tier. Ask the user to complete it; report blocked work with done({outcome:"partial"}). Do not dismiss, close, or resubmit it.',
};
- if (toolName === 'apply_captcha_solution' && this._nativeCaptchaSolutions?.get(tabId)?.solution && !this._nativeCaptchaSolutions.get(tabId).applied) return null;
+ if (toolName === 'apply_captcha_solution' && this._hasUnappliedNativeCaptchaSolution(tabId)) return null;
if (toolName === 'solve_captcha' && Array.isArray(toolArgs.providerTasks)
&& !gate.publicGate?.solveAttempted && !gate.publicGate?.solveFailed
&& gate.status !== 'verification_pending') return null;
@@ -11356,7 +11361,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (
postSolveTokenState?.visibleActiveChallenge === true
&& ['verification_pending', 'cleared'].includes(activeGate?.status)
- && !(this._nativeCaptchaSolutions?.get(tabId)?.solution && !this._nativeCaptchaSolutions.get(tabId).applied)
+ && !this._hasUnappliedNativeCaptchaSolution(tabId)
) {
const manualGate = {
...withoutCaptchaTokenClearanceState(
diff --git a/src/chrome/src/agent/captcha-native-providers.js b/src/chrome/src/agent/captcha-native-providers.js
index ce64ac4f7..7ccd177c3 100644
--- a/src/chrome/src/agent/captcha-native-providers.js
+++ b/src/chrome/src/agent/captcha-native-providers.js
@@ -161,20 +161,24 @@ function validateFallbackIdentifiers(built) {
if (new Set(signatures).size > 1) throw new Error('Fallback recognition tasks must use the same observed challenge media.');
}
const groups = [
- ['websiteURL', 'pageurl', 'url'],
- ['websiteKey', 'sitekey', 'googlekey', 'websitePublicKey', 'publickey'],
- ...(FAMILY_IDENTIFIERS[family] || []),
+ { aliases: ['websiteURL', 'pageurl', 'url'], requireAll: false },
+ { aliases: ['websiteKey', 'sitekey', 'googlekey', 'websitePublicKey', 'publickey'], requireAll: false },
+ ...(FAMILY_IDENTIFIERS[family] || []).map(aliases => ({ aliases, requireAll: true })),
];
if (family === 'geetest') {
const versions = built.map(({contract, task}) => task.version === 4 || task.captchaId
|| task.captcha_id || task.initParameters?.captcha_id || contract.method === 'geetest_v4' ? 4 : 3);
if (new Set(versions).size > 1) throw new Error('Fallback tasks must use the same GeeTest version.');
- groups.push(versions[0] === 4 ? ['captchaId', 'captcha_id', 'initParameters.captcha_id', 'gt'] : ['gt']);
- if (versions[0] === 3) groups.push(['challenge']);
+ groups.push({ aliases: versions[0] === 4 ? ['captchaId', 'captcha_id', 'initParameters.captcha_id', 'gt'] : ['gt'], requireAll: true });
+ if (versions[0] === 3) groups.push({ aliases: ['challenge'], requireAll: true });
}
- for (const aliases of groups) {
- const values = built.flatMap(({task}) => aliases.map(path => at(task, path)))
- .filter(value => usable(value) && !(family === 'turnstile' && aliases.includes('data') && object(value)));
+ for (const { aliases, requireAll } of groups) {
+ const valuesByTask = built.map(({task}) => aliases.map(path => at(task, path))
+ .filter(value => usable(value) && !(family === 'turnstile' && aliases.includes('data') && object(value))));
+ const values = valuesByTask.flat();
+ if (requireAll && values.length && valuesByTask.some(taskValues => !taskValues.length)) {
+ throw new Error(`Fallback tasks must reference the same observed challenge (${aliases.join('/')}).`);
+ }
if (new Set(values.map(value => typeof value === 'object' ? JSON.stringify(value) : String(value))).size > 1) {
throw new Error(`Fallback tasks must reference the same observed challenge (${aliases.join('/')}).`);
}
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index d6e8cd75b..f6f5ebdd5 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -9454,6 +9454,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
&& !state?.solveAttempted && !state?.solveFailed && !state?.activeChallengeAfterSolve;
}
+ _hasUnappliedNativeCaptchaSolution(tabId) {
+ const record = this._nativeCaptchaSolutions?.get(tabId);
+ return record?.solution !== undefined && record.applied !== true;
+ }
+
_captchaRoutingMessage(tabId, captchaGateDecision, captchaSolveOutcome, toolResult = {}, onUpdate = () => {}) {
let resultContent = '';
const gate = captchaGateDecision || captchaSolveOutcome;
@@ -9480,7 +9485,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
onUpdate('warning', { message: 'Manual completion confirmed the unrecognized challenge cleared.' });
}
} else if ((captchaGateDecision || captchaSolveOutcome)?.status === 'verification_pending'
- && this._nativeCaptchaSolutions?.get(tabId)?.solution && !this._nativeCaptchaSolutions.get(tabId).applied) {
+ && this._hasUnappliedNativeCaptchaSolution(tabId)) {
resultContent += '\n[TRUSTED CAPTCHA GATE: The native answer is ready but has not been applied. Inspect the page and use apply_captcha_solution, then verify fresh page state.]';
} else if (captchaGateDecision?.status === 'verification_pending') {
resultContent += '\n[TRUSTED CAPTCHA GATE: Verification is still pending because the exact widget has no response token or its frame state could not be inspected conclusively. Wait briefly, then read the page again. Do not submit, dismiss, or call solve_captcha again.]';
@@ -9542,7 +9547,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
manualCompletionRequired: true,
error: 'Verification requires manual completion in this mode/tier. Ask the user to complete it; report blocked work with done({outcome:"partial"}). Do not dismiss, close, or resubmit it.',
};
- if (toolName === 'apply_captcha_solution' && this._nativeCaptchaSolutions?.get(tabId)?.solution && !this._nativeCaptchaSolutions.get(tabId).applied) return null;
+ if (toolName === 'apply_captcha_solution' && this._hasUnappliedNativeCaptchaSolution(tabId)) return null;
if (toolName === 'solve_captcha' && Array.isArray(toolArgs.providerTasks)
&& !gate.publicGate?.solveAttempted && !gate.publicGate?.solveFailed
&& gate.status !== 'verification_pending') return null;
@@ -9961,7 +9966,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (
postSolveTokenState?.visibleActiveChallenge === true
&& ['verification_pending', 'cleared'].includes(activeGate?.status)
- && !(this._nativeCaptchaSolutions?.get(tabId)?.solution && !this._nativeCaptchaSolutions.get(tabId).applied)
+ && !this._hasUnappliedNativeCaptchaSolution(tabId)
) {
const manualGate = {
...withoutCaptchaTokenClearanceState(
diff --git a/src/firefox/src/agent/captcha-native-providers.js b/src/firefox/src/agent/captcha-native-providers.js
index ce64ac4f7..7ccd177c3 100644
--- a/src/firefox/src/agent/captcha-native-providers.js
+++ b/src/firefox/src/agent/captcha-native-providers.js
@@ -161,20 +161,24 @@ function validateFallbackIdentifiers(built) {
if (new Set(signatures).size > 1) throw new Error('Fallback recognition tasks must use the same observed challenge media.');
}
const groups = [
- ['websiteURL', 'pageurl', 'url'],
- ['websiteKey', 'sitekey', 'googlekey', 'websitePublicKey', 'publickey'],
- ...(FAMILY_IDENTIFIERS[family] || []),
+ { aliases: ['websiteURL', 'pageurl', 'url'], requireAll: false },
+ { aliases: ['websiteKey', 'sitekey', 'googlekey', 'websitePublicKey', 'publickey'], requireAll: false },
+ ...(FAMILY_IDENTIFIERS[family] || []).map(aliases => ({ aliases, requireAll: true })),
];
if (family === 'geetest') {
const versions = built.map(({contract, task}) => task.version === 4 || task.captchaId
|| task.captcha_id || task.initParameters?.captcha_id || contract.method === 'geetest_v4' ? 4 : 3);
if (new Set(versions).size > 1) throw new Error('Fallback tasks must use the same GeeTest version.');
- groups.push(versions[0] === 4 ? ['captchaId', 'captcha_id', 'initParameters.captcha_id', 'gt'] : ['gt']);
- if (versions[0] === 3) groups.push(['challenge']);
+ groups.push({ aliases: versions[0] === 4 ? ['captchaId', 'captcha_id', 'initParameters.captcha_id', 'gt'] : ['gt'], requireAll: true });
+ if (versions[0] === 3) groups.push({ aliases: ['challenge'], requireAll: true });
}
- for (const aliases of groups) {
- const values = built.flatMap(({task}) => aliases.map(path => at(task, path)))
- .filter(value => usable(value) && !(family === 'turnstile' && aliases.includes('data') && object(value)));
+ for (const { aliases, requireAll } of groups) {
+ const valuesByTask = built.map(({task}) => aliases.map(path => at(task, path))
+ .filter(value => usable(value) && !(family === 'turnstile' && aliases.includes('data') && object(value))));
+ const values = valuesByTask.flat();
+ if (requireAll && values.length && valuesByTask.some(taskValues => !taskValues.length)) {
+ throw new Error(`Fallback tasks must reference the same observed challenge (${aliases.join('/')}).`);
+ }
if (new Set(values.map(value => typeof value === 'object' ? JSON.stringify(value) : String(value))).size > 1) {
throw new Error(`Fallback tasks must reference the same observed challenge (${aliases.join('/')}).`);
}
diff --git a/test/captcha-native-providers.mjs b/test/captcha-native-providers.mjs
index e9dfb9ec1..1792df88a 100644
--- a/test/captcha-native-providers.mjs
+++ b/test/captcha-native-providers.mjs
@@ -230,6 +230,20 @@ for (const browser of ['chrome', 'firefox']) {
assert.throws(() => native.prepareNativeCaptchaTasks(enabled, entries), /same observed challenge/);
assert.equal(calls.length, 0);
});
+ for (const [label, entries] of [
+ ['reCAPTCHA v3 omitted action', [
+ { provider: '2captcha', method: 'RecaptchaV3TaskProxyless', parameters: { websiteURL: url, websiteKey: 'site', minScore: 0.3, pageAction: 'delete' } },
+ { provider: 'solvecaptcha', method: 'recaptcha_v3', parameters: { pageurl: url, googlekey: 'site' } },
+ ]],
+ ['Turnstile omitted cData', [
+ { provider: '2captcha', method: 'TurnstileTaskProxyless', parameters: { websiteURL: url, websiteKey: 'site', data: 'observed-cdata' } },
+ { provider: 'anti-captcha', method: 'TurnstileTaskProxyless', parameters: { websiteURL: url, websiteKey: 'site' } },
+ ]],
+ ]) test(`${browser}: ${label} cannot spend`, t => {
+ const calls = mockApi(t, () => { throw new Error('Must not dispatch'); });
+ assert.throws(() => native.prepareNativeCaptchaTasks(entries.map(entry => ({ id: entry.provider, apiKey: 'key' })), entries), /same observed challenge/);
+ assert.equal(calls.length, 0);
+ });
const recognitionPairs = [
['coordinates body', ['2captcha', 'CoordinatesTask', { body: 'image-A' }], ['solvecaptcha', 'coordinates', { body: 'image-A' }], task => { task.body = 'image-B'; }],
['image-to-text array alias', ['2captcha', 'ImageToTextTask', { body: 'image-A' }], ['nopecha', 'recognition/textcaptcha', { image_data: ['image-A'] }], task => { task.image_data = ['image-B']; }],
diff --git a/test/run.js b/test/run.js
index a552ae8e2..684688acb 100644
--- a/test/run.js
+++ b/test/run.js
@@ -122070,6 +122070,25 @@ test('CAPTCHA native methods dispatch through the real agent, preserve structure
}
});
+test('CAPTCHA gates keep false and zero native answers available for application', () => {
+ for (const [build, AgentClass] of [['chrome', AgentCh], ['firefox', AgentFx]]) {
+ for (const solution of [false, 0]) {
+ const agent = new AgentClass({ getActive: () => ({ promptTier: 'full' }) });
+ agent.conversationModes.set(1, 'act');
+ agent.captchaSolverEnabled = true;
+ agent.captchaProviderIds = ['2captcha'];
+ agent._nativeCaptchaSolutions = new Map([[1, { pageUrl: 'https://example.test/form', solution, applied: false }]]);
+ const gate = { status: 'verification_pending', solveAttempted: true };
+ agent._captchaGateStates.set(1, { status: 'verification_pending', publicGate: gate });
+ assert.equal(agent._hasUnappliedNativeCaptchaSolution(1), true, `${build}: ${solution}`);
+ assert.equal(agent._captchaGateBlockResult(1, 'apply_captcha_solution', {}), null, `${build}: ${solution}`);
+ assert.match(agent._captchaRoutingMessage(1, gate), /use apply_captcha_solution/, `${build}: ${solution}`);
+ agent._nativeCaptchaSolutions.get(1).applied = true;
+ assert.equal(agent._hasUnappliedNativeCaptchaSolution(1), false, `${build}: consumed ${solution}`);
+ }
+ }
+});
+
test('challenge-dialog routing detects supported widgets and diagnoses unsupported Arkose frames', async () => {
for (const [build, AgentClass] of [['chrome', AgentCh], ['firefox', AgentFx]]) {
const supportedNodes = [