Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Recover paid native CAPTCHA answers after chat clear
Emre Sokullu54c973a2f146
diff --git a/docs/captcha-provider-coverage.md b/docs/captcha-provider-coverage.mdindex feb44e713..70613e08b 100644--- a/docs/captcha-provider-coverage.md+++ b/docs/captcha-provider-coverage.md@@ -140,6 +140,8 @@ Saved weights determine execution order, regardless of array order. Supply a tasProvider-specific identifiers (for example `appId`/`app_id` and `miseryKey`/`misery_key`) must agree across fallback entries before any paid request. Recognition fallbacks compare the image/audio, instructions and answer constraints such as click counts and text length. TSPD fallbacks compare the captured page; Cloudflare Challenge fallbacks compare task mode and the exact HTML snapshot. AWS WAF fallbacks compare API, challenge and CAPTCHA script identifiers. reCAPTCHA v2 fallbacks must agree on `data-s` and visible/invisible mode, and reCAPTCHA v3 fallbacks on action and minimum score, when supplied. All reCAPTCHA fallbacks compare explicitly supplied session cookies after normalizing each provider's documented format; a scoped NopeCHA cookie array cannot be equated to a scope-free cookie string.FunCaptcha fallbacks compare the Arkose service host even when one provider takes a subdomain and another takes a full `surl` URL. The native dispatch lock is stored before contacting a paid provider. An unexpired answer is stored for worker recovery; if a solve was dispatched but its answer is unavailable after restart, the gate requires manual completion rather than a second paid call.+Clearing the chat on the same page keeps the native dispatch lock and any unapplied paid answer. The pending verification gate directs the next Act/Dev mid or full run to call `get_captcha_capabilities`, which returns `pendingNativeAnswer` with the original provider, method, and structured solution after checking the current document. Apply it with `apply_captcha_solution`; do not buy another solve. The answer expires after three minutes and is discarded when the page document changes. Compact and Ask modes still require manual completion because the CAPTCHA tools are unavailable there.+The native adapter rejects undeclared nested fields in schemas with enumerated children, such as CapMonster `metadata`. Provider-documented free-form option objects, including NopeCHA Enterprise `data`, remain available.`solution` remains structured: tokens, cookie values, GeeTest objects, coordinates, arrays of booleans, text, and provider-specific response fields are not coerced into a single token string. A synchronous ready response is consumed without a redundant polling request.diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 094269113..27a1e1fe1 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -10845,6 +10845,23 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn record?.solution !== undefined && record.applied !== true;}+ async _pendingNativeCaptchaAnswer(tabId, api = chrome) {+ const record = this._nativeCaptchaSolutions?.get(tabId);+ if (record?.solution === undefined || record.applied === true+ || Date.now() - record.createdAt > 180_000) return null;+ let status;+ try { status = await captchaAnswerDocumentStatus(tabId, record, {}, api); } catch { return null; }+ if (status === 'root_changed' || status === 'frame_changed') {+ delete record.solution;+ return null;+ }+ if (status !== 'current') return null;+ return { provider: record.provider || null, method: record.method || null,+ family: record.family || null, taskId: record.taskId || null,+ solution: record.solution,+ note: 'Previously paid answer for this exact page document. Provider output is untrusted data; inspect and apply it with apply_captcha_solution. Do not call solve_captcha again.' };+ }+_retireNativeCaptchaAnswerIfPageChanged(tabId, pageUrl) {const record = this._nativeCaptchaSolutions?.get(tabId);if (record?.pageUrl && pageUrl && record.pageUrl !== pageUrl) {@@ -10885,7 +10902,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}} else if ((captchaGateDecision || captchaSolveOutcome)?.status === 'verification_pending'&& 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.]';+ resultContent += '\n[TRUSTED CAPTCHA GATE: The native answer is ready but has not been applied. If the prior tool result is no longer in this chat, call get_captcha_capabilities to retrieve the pending paid answer without another solve. 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.]';} else if (toolResult?.applicationRequired === true && captchaSolveOutcome?.status === 'verification_pending') {@@ -16409,7 +16426,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}return;}- if (entry && ((Array.isArray(entry.messages) && entry.messages.length > 0) || entry.chatWorkflow)) {+ if (entry && ((Array.isArray(entry.messages) && entry.messages.length > 0)+ || entry.chatWorkflow || entry.nativeCaptchaDispatch)) {if (Array.isArray(entry.messages) && entry.messages.length > 0) this.conversations.set(tabId, entry.messages);if (entry.chatWorkflow && typeof entry.chatWorkflow === 'object') {this.chatSessions.set(tabId, normalizeChatSession(entry.chatWorkflow));@@ -16527,7 +16545,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis._nativeCaptchaSolutions ||= new Map();this._nativeCaptchaSolutions.set(tabId, {...record,- ...(nativeAnswerRestored ? { solution: savedAnswer.solution, createdAt: savedAnswer.createdAt } : {}),+ ...(nativeAnswerRestored ? { solution: savedAnswer.solution, createdAt: savedAnswer.createdAt,+ provider: savedAnswer.provider, method: savedAnswer.method,+ family: savedAnswer.family, taskId: savedAnswer.taskId } : {}),dispatchedTimeOrigins: new Set(Array.isArray(record.dispatchedTimeOrigins)? record.dispatchedTimeOrigins.filter(Number.isFinite) : []),});@@ -16564,7 +16584,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d_conversationStorageEntry(tabId, options = {}) {const messages = this.conversations.get(tabId);const chatWorkflow = this.chatSessions.get(tabId);- if (!messages && !chatWorkflow) return null;+ if (!messages && !chatWorkflow && !this._nativeCaptchaSolutions?.has(tabId)) return null;const conversationId = this.conversationIds.get(tabId) || null;const clarificationGuard = this._clarificationAuthorizationGuards.get(tabId);const persistedClarificationGuard = clarificationGuard?.source === 'timeout'@@ -16609,6 +16629,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d&& Date.now() - nativeAnswer.createdAt <= 180_000? { pageUrl: nativeAnswer.pageUrl, createdAt: nativeAnswer.createdAt, applied: false,documents: nativeAnswer.documents, solution: nativeAnswer.solution,+ provider: nativeAnswer.provider, method: nativeAnswer.method,+ family: nativeAnswer.family, taskId: nativeAnswer.taskId,dispatchedTimeOrigins: [...(nativeAnswer.dispatchedTimeOrigins || [])] }: null;const nativeCaptchaAnswer = savedNativeAnswer && JSON.stringify(savedNativeAnswer).length <= 250_000@@ -26144,7 +26166,18 @@ If the user has already named or confirmed this exact recipient, do NOT ask agaithis.recentNavUrls.delete(tabId);this.completionInvariants.delete(tabId);this.readCompletenessStates.delete(tabId);- this._captchaGateStates.delete(tabId);+ const pendingNativeAnswer = preserveRunGuard && this._hasUnappliedNativeCaptchaSolution(tabId)+ && Date.now() - this._nativeCaptchaSolutions.get(tabId).createdAt <= 180_000;+ if (pendingNativeAnswer) {+ const previousGate = this._captchaGateStates.get(tabId) || {};+ const publicGate = { ...previousGate.publicGate, status: 'verification_pending',+ solveAttempted: true, nativeAnswerPending: true };+ this._captchaGateStates.set(tabId, { ...previousGate,+ key: previousGate.key || `native:${this._nativeCaptchaSolutions.get(tabId).pageUrl}`,+ status: 'verification_pending', publicGate });+ } else {+ this._captchaGateStates.delete(tabId);+ }// Native paid answers and dispatch locks belong to the page document,// not the conversation. A new chat on the same document must reuse them.if (!preserveRunGuard) this._nativeCaptchaSolutions?.delete(tabId);@@ -27126,7 +27159,11 @@ If the user has already named or confirmed this exact recipient, do NOT ask agaiconst t = this.persistTimers.get(tabId);if (t) { clearTimeout(t); this.persistTimers.delete(tabId); }try {- chrome.storage.session.remove(this._convKey(tabId)).catch(() => {});+ const removed = chrome.storage.session.remove(this._convKey(tabId));+ if (this._nativeCaptchaSolutions?.has(tabId)) {+ return removed.then(() => this._persistNow(tabId)).catch(() => {});+ }+ return removed.catch(() => {});} catch (e) { /* ignore */ }}@@ -35809,7 +35846,9 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai// take effect without a restart. Cloud browsers route through the broker.if (name === 'get_captcha_capabilities') {const stored = await chrome.storage.local.get(CAPTCHA_SETTINGS_KEYS);- return getCaptchaCapabilities(getCaptchaProviders(stored), args || {});+ const capabilities = getCaptchaCapabilities(getCaptchaProviders(stored), args || {});+ const pendingNativeAnswer = await this._pendingNativeCaptchaAnswer(tabId);+ return pendingNativeAnswer ? { ...capabilities, pendingNativeAnswer } : capabilities;}if (name === 'apply_captcha_solution') {const record = this._nativeCaptchaSolutions?.get(tabId);@@ -35910,6 +35949,10 @@ If the user has already named or confirmed this exact recipient, do NOT ask agaidispatched = true;const result = await solveNativeCaptchaTasks(prepared);record.solution = result.solution;+ record.provider = result.provider;+ record.method = result.method;+ record.family = result.family;+ record.taskId = result.taskId;record.createdAt = Date.now();this._captchaSolveGateAfterTool(tabId, 'solve_captcha', { success: true, applicationRequired: true });await this._persistNow(tabId);diff --git a/src/chrome/src/agent/tools.js b/src/chrome/src/agent/tools.jsindex 3aeb41af1..96b22d392 100644--- a/src/chrome/src/agent/tools.js+++ b/src/chrome/src/agent/tools.js@@ -1220,7 +1220,7 @@ export const AGENT_TOOLS = ["type": "function","function": {"name": "get_captcha_capabilities",- "description": "Read the documented CAPTCHA methods for enabled providers without spending or exposing API keys. Filter by family/provider, then request a method to get its exact native fields, fixed values, and official documentation. Use this before solve_captcha providerTasks for any token, recognition, cookie, or structured-answer method.",+ "description": "Read the documented CAPTCHA methods for enabled providers without spending or exposing API keys. Also returns an unapplied paid native answer for the same page document, if one is pending; use it after a chat clear without solving again. Filter by family/provider, then request a method to get its exact native fields, fixed values, and official documentation. Use this before solve_captcha providerTasks for any token, recognition, cookie, or structured-answer method.","parameters": {"type": "object","properties": {diff --git a/src/chrome/src/background.js b/src/chrome/src/background.jsindex a46bffa1d..8dc11a24a 100644--- a/src/chrome/src/background.js+++ b/src/chrome/src/background.js@@ -3596,7 +3596,7 @@ async function handleMessage(msg, sender) {throw new Error('Could not durably clear the tab transcript.');}clearedContextMenuPromptId = tabChatClearResult.clearedContextMenuPromptId || null;- agent.clearConversation(tabId);+ await agent.clearConversation(tabId);clearRunUiSnapshot(tabId);chrome.runtime.sendMessage({target: 'sidepanel',diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 8ae37cdf8..50e95b9ad 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -5858,7 +5858,8 @@ export class Agent extends LoopDetector {}return;}- if (entry && ((Array.isArray(entry.messages) && entry.messages.length > 0) || entry.chatWorkflow)) {+ if (entry && ((Array.isArray(entry.messages) && entry.messages.length > 0)+ || entry.chatWorkflow || entry.nativeCaptchaDispatch)) {if (Array.isArray(entry.messages) && entry.messages.length > 0) this.conversations.set(tabId, entry.messages);if (entry.chatWorkflow && typeof entry.chatWorkflow === 'object') {this.chatSessions.set(tabId, normalizeChatSession(entry.chatWorkflow));@@ -5974,7 +5975,9 @@ export class Agent extends LoopDetector {this._nativeCaptchaSolutions ||= new Map();this._nativeCaptchaSolutions.set(tabId, {...record,- ...(nativeAnswerRestored ? { solution: savedAnswer.solution, createdAt: savedAnswer.createdAt } : {}),+ ...(nativeAnswerRestored ? { solution: savedAnswer.solution, createdAt: savedAnswer.createdAt,+ provider: savedAnswer.provider, method: savedAnswer.method,+ family: savedAnswer.family, taskId: savedAnswer.taskId } : {}),dispatchedTimeOrigins: new Set(Array.isArray(record.dispatchedTimeOrigins)? record.dispatchedTimeOrigins.filter(Number.isFinite) : []),});@@ -6011,7 +6014,7 @@ export class Agent extends LoopDetector {_conversationStorageEntry(tabId, options = {}) {const messages = this.conversations.get(tabId);const chatWorkflow = this.chatSessions.get(tabId);- if (!messages && !chatWorkflow) return null;+ if (!messages && !chatWorkflow && !this._nativeCaptchaSolutions?.has(tabId)) return null;const conversationId = this.conversationIds.get(tabId) || null;const clarificationGuard = this._clarificationAuthorizationGuards.get(tabId);const persistedClarificationGuard = clarificationGuard?.source === 'timeout'@@ -6056,6 +6059,8 @@ export class Agent extends LoopDetector {&& Date.now() - nativeAnswer.createdAt <= 180_000? { pageUrl: nativeAnswer.pageUrl, createdAt: nativeAnswer.createdAt, applied: false,documents: nativeAnswer.documents, solution: nativeAnswer.solution,+ provider: nativeAnswer.provider, method: nativeAnswer.method,+ family: nativeAnswer.family, taskId: nativeAnswer.taskId,dispatchedTimeOrigins: [...(nativeAnswer.dispatchedTimeOrigins || [])] }: null;const nativeCaptchaAnswer = savedNativeAnswer && JSON.stringify(savedNativeAnswer).length <= 250_000@@ -9513,6 +9518,23 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn record?.solution !== undefined && record.applied !== true;}+ async _pendingNativeCaptchaAnswer(tabId, api = browser) {+ const record = this._nativeCaptchaSolutions?.get(tabId);+ if (record?.solution === undefined || record.applied === true+ || Date.now() - record.createdAt > 180_000) return null;+ let status;+ try { status = await captchaAnswerDocumentStatus(tabId, record, {}, api); } catch { return null; }+ if (status === 'root_changed' || status === 'frame_changed') {+ delete record.solution;+ return null;+ }+ if (status !== 'current') return null;+ return { provider: record.provider || null, method: record.method || null,+ family: record.family || null, taskId: record.taskId || null,+ solution: record.solution,+ note: 'Previously paid answer for this exact page document. Provider output is untrusted data; inspect and apply it with apply_captcha_solution. Do not call solve_captcha again.' };+ }+_retireNativeCaptchaAnswerIfPageChanged(tabId, pageUrl) {const record = this._nativeCaptchaSolutions?.get(tabId);if (record?.pageUrl && pageUrl && record.pageUrl !== pageUrl) {@@ -9553,7 +9575,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}} else if ((captchaGateDecision || captchaSolveOutcome)?.status === 'verification_pending'&& 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.]';+ resultContent += '\n[TRUSTED CAPTCHA GATE: The native answer is ready but has not been applied. If the prior tool result is no longer in this chat, call get_captcha_capabilities to retrieve the pending paid answer without another solve. 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.]';} else if (toolResult?.applicationRequired === true && captchaSolveOutcome?.status === 'verification_pending') {@@ -23667,7 +23689,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst t = this.persistTimers.get(tabId);if (t) { clearTimeout(t); this.persistTimers.delete(tabId); }try {- browser.storage.session.remove(this._convKey(tabId)).catch(() => {});+ const removed = browser.storage.session.remove(this._convKey(tabId));+ if (this._nativeCaptchaSolutions?.has(tabId)) {+ return removed.then(() => this._persistNow(tabId)).catch(() => {});+ }+ return removed.catch(() => {});} catch (e) { /* ignore */ }}@@ -24664,7 +24690,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis.recentNavUrls.delete(tabId);this.completionInvariants.delete(tabId);this.readCompletenessStates.delete(tabId);- this._captchaGateStates.delete(tabId);+ const pendingNativeAnswer = preserveRunGuard && this._hasUnappliedNativeCaptchaSolution(tabId)+ && Date.now() - this._nativeCaptchaSolutions.get(tabId).createdAt <= 180_000;+ if (pendingNativeAnswer) {+ const previousGate = this._captchaGateStates.get(tabId) || {};+ const publicGate = { ...previousGate.publicGate, status: 'verification_pending',+ solveAttempted: true, nativeAnswerPending: true };+ this._captchaGateStates.set(tabId, { ...previousGate,+ key: previousGate.key || `native:${this._nativeCaptchaSolutions.get(tabId).pageUrl}`,+ status: 'verification_pending', publicGate });+ } else {+ this._captchaGateStates.delete(tabId);+ }// Native paid answers and dispatch locks belong to the page document,// not the conversation. A new chat on the same document must reuse them.if (!preserveRunGuard) this._nativeCaptchaSolutions?.delete(tabId);@@ -32795,7 +32832,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// rotating or clearing the key takes effect without a restart.if (name === 'get_captcha_capabilities') {const stored = await browser.storage.local.get(CAPTCHA_SETTINGS_KEYS);- return getCaptchaCapabilities(getCaptchaProviders(stored), args || {});+ const capabilities = getCaptchaCapabilities(getCaptchaProviders(stored), args || {});+ const pendingNativeAnswer = await this._pendingNativeCaptchaAnswer(tabId);+ return pendingNativeAnswer ? { ...capabilities, pendingNativeAnswer } : capabilities;}if (name === 'apply_captcha_solution') {const record = this._nativeCaptchaSolutions?.get(tabId);@@ -32893,6 +32932,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout ddispatched = true;const result = await solveNativeCaptchaTasks(prepared);record.solution = result.solution;+ record.provider = result.provider;+ record.method = result.method;+ record.family = result.family;+ record.taskId = result.taskId;record.createdAt = Date.now();this._captchaSolveGateAfterTool(tabId, 'solve_captcha', { success: true, applicationRequired: true });await this._persistNow(tabId);diff --git a/src/firefox/src/agent/tools.js b/src/firefox/src/agent/tools.jsindex 868d25bde..125b8034f 100644--- a/src/firefox/src/agent/tools.js+++ b/src/firefox/src/agent/tools.js@@ -1074,7 +1074,7 @@ export const AGENT_TOOLS = ["type": "function","function": {"name": "get_captcha_capabilities",- "description": "Read the documented CAPTCHA methods for enabled providers without spending or exposing API keys. Filter by family/provider, then request a method to get its exact native fields, fixed values, and official documentation. Use this before solve_captcha providerTasks for any token, recognition, cookie, or structured-answer method.",+ "description": "Read the documented CAPTCHA methods for enabled providers without spending or exposing API keys. Also returns an unapplied paid native answer for the same page document, if one is pending; use it after a chat clear without solving again. Filter by family/provider, then request a method to get its exact native fields, fixed values, and official documentation. Use this before solve_captcha providerTasks for any token, recognition, cookie, or structured-answer method.","parameters": {"type": "object","properties": {diff --git a/src/firefox/src/background.js b/src/firefox/src/background.jsindex 5cf6ecfa8..9870ca871 100644--- a/src/firefox/src/background.js+++ b/src/firefox/src/background.js@@ -3048,7 +3048,7 @@ async function handleMessage(msg, sender) {throw new Error('Could not durably clear the tab transcript.');}clearedContextMenuPromptId = tabChatClearResult.clearedContextMenuPromptId || null;- agent.clearConversation(tabId);+ await agent.clearConversation(tabId);clearRunUiSnapshot(tabId);browser.runtime.sendMessage({target: 'sidepanel',diff --git a/test/captcha-runtime-policy.mjs b/test/captcha-runtime-policy.mjsindex 2011a3ee3..70f71d426 100644--- a/test/captcha-runtime-policy.mjs+++ b/test/captcha-runtime-policy.mjs@@ -141,20 +141,63 @@ for (const build of ['chrome', 'firefox']) {assert.equal(agent._hasUnappliedNativeCaptchaSolution(1), false);assert.equal(record.dispatchedTimeOrigins.has(1000), true);});- test(`${build}: clearing a chat preserves the page-scoped paid answer and dispatch lock`, () => {+ test(`${build}: clearing a chat keeps a recoverable paid answer and pending gate`, async () => {const agent = agentFor('act', 'full');const record = { pageUrl: 'https://example.test/challenge', createdAt: Date.now(),solution: { token: 'paid-answer' }, applied: false,+ provider: '2captcha', method: 'GeeTestTaskProxyless', family: 'geetest', taskId: 'paid-task',documents: [{ frameId: 0, url: 'https://example.test/challenge', timeOrigin: 1000 }],dispatchedTimeOrigins: new Set([1000]) };agent._nativeCaptchaSolutions = new Map([[1, record]]);- agent.clearConversation(1);+ agent._captchaGateStates.set(1, { status: 'verification_pending',+ publicGate: { status: 'verification_pending', nativeAnswerPending: true } });+ const apiName = build === 'chrome' ? 'chrome' : 'browser';+ const previous = globalThis[apiName];+ const stored = {};+ globalThis[apiName] = { storage: { session: {+ remove: async key => { delete stored[key]; },+ set: async entries => { Object.assign(stored, entries); },+ get: async key => key in stored ? { [key]: stored[key] } : {},+ } } };+ try {+ await agent.clearConversation(1);+ } finally { globalThis[apiName] = previous; }assert.equal(agent._nativeCaptchaSolutions.get(1), record);assert.equal(agent._hasUnappliedNativeCaptchaSolution(1), true);assert.equal(agent._nativeCaptchaSolutions.get(1).dispatchedTimeOrigins.has(1000), true);+ assert.equal(agent._captchaGateStates.get(1).status, 'verification_pending');+ assert.match(agent._captchaRoutingMessage(1, agent._captchaGateStates.get(1).publicGate),+ /get_captcha_capabilities.*pending paid answer/);+ const entry = stored[agent._convKey(1)];+ assert.deepEqual(entry.messages, []);+ assert.equal(entry.nativeCaptchaAnswer.provider, '2captcha');+ assert.equal(entry.nativeCaptchaAnswer.method, 'GeeTestTaskProxyless');+ const fresh = agentFor('act', 'full');+ const fakePageApi = {+ tabs: { get: async () => ({ url: record.pageUrl }) },+ webNavigation: { getAllFrames: async () => [{ frameId: 0, url: record.pageUrl }] },+ scripting: { executeScript: async () => [{ frameId: 0,+ result: { url: record.pageUrl, timeOrigin: 1000 } }] },+ };+ assert.deepEqual((await agent._pendingNativeCaptchaAnswer(1, fakePageApi)).solution, { token: 'paid-answer' });+ assert.equal((await agent._pendingNativeCaptchaAnswer(1, fakePageApi)).method, 'GeeTestTaskProxyless');+ globalThis[apiName] = { ...fakePageApi, storage: { local: { get: async () => ({}) } } };+ try {+ const discovery = await agent._executeToolImpl(1, 'get_captcha_capabilities', {});+ assert.equal(discovery.pendingNativeAnswer.provider, '2captcha');+ assert.deepEqual(discovery.pendingNativeAnswer.solution, { token: 'paid-answer' });+ } finally { globalThis[apiName] = previous; }+ globalThis[apiName] = { storage: { session: { get: async key => key in stored ? { [key]: stored[key] } : {} } } };+ try { await fresh._hydrate(1); } finally { globalThis[apiName] = previous; }+ assert.equal(fresh._nativeCaptchaSolutions.get(1).solution.token, 'paid-answer');+ assert.equal(fresh._nativeCaptchaSolutions.get(1).method, 'GeeTestTaskProxyless');+ assert.equal(fresh._captchaGateStates.get(1).status, 'verification_pending');// A still-running solve can fill the same record after the chat is cleared.record.solution = { token: 'late-answer' };assert.equal(agent._nativeCaptchaSolutions.get(1).solution.token, 'late-answer');+ fakePageApi.tabs.get = async () => ({ url: 'https://example.test/other' });+ assert.equal(await agent._pendingNativeCaptchaAnswer(1, fakePageApi), null);+ assert.equal(record.solution, undefined);agent._cleanupTab(1);assert.equal(agent._nativeCaptchaSolutions.has(1), false);});