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
bugfixes
Codex release-state test8b56f6b916c7
diff --git a/docs/captcha-provider-coverage.md b/docs/captcha-provider-coverage.mdindex 6ff2df2b2..33a7ceb04 100644--- a/docs/captcha-provider-coverage.md+++ b/docs/captcha-provider-coverage.md@@ -143,6 +143,8 @@ Use observed page parameters to prepare fallback tasks. Method IDs are WebBrain}```+AWS WAF pages keep their inputs out of the page text: `key`, `iv`, and `context` sit in the `window.gokuProps` global, and the challenge script loads from an `awswaf.com` host. When `get_captcha_capabilities` is called without a provider or method on such a page, it reads those values from the top frame and returns `observedChallenge`. That object includes one ready task per enabled CapSolver, CapMonster Cloud, or Anti-Captcha provider, plus the `aws-waf-token` cookie path for each provider's answer (`cookie`, `cookies.aws-waf-token`, and `token`). CapMonster tasks set `cookieSolution: true`. 2Captcha and SolveCaptcha are left out because they return a `captcha_voucher`/`existing_token` pair that WebBrain can't turn into the cookie, so a win by either would be charged and unusable. If an input is missing, the result names it and nothing is guessed. After `apply_captcha_solution` sets the cookie, reload the page and read it again. A site can still reject a proxyless token.+Saved weights determine execution order, regardless of array order. Supply a task for each enabled provider that can solve that family and for which the required inputs are available. The tool does not invent another provider's parameters. Page URLs must belong to the active tab or an observed frame. Native methods do not automatically scrape every site's internal configuration.Provider-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.@@ -219,6 +221,7 @@ The CAPTCHA gate permits `done` with `outcome: "failed"` or `"partial"` in every| Required-field error | Read that exact method's schema; obtain fresh page values. It has not spent a solve. || Token returned but page stays blocked | Correct target frame/callback, freshness, Enterprise metadata, IP/User-Agent requirements, and site acceptance. Do not buy another solve automatically. || NopeCHA reports “Incomplete job” as an error | Check the request stage, HTTP status and numeric code now included in the error. Known pending responses are polled; submission errors and terminal HTTP failures are not retried. |+| AWS WAF page, but no solve was attempted | Call `get_captcha_capabilities` without a provider or method and use `observedChallenge.providerTasks`. Enable CapSolver, CapMonster Cloud, or Anti-Captcha; 2Captcha/SolveCaptcha vouchers can't be applied. || Native result has coordinates/cookies/object fields | Use suitable answer bindings or a site-specific handler, not a token textarea by assumption. || Balance is credits instead of currency | Expected for NopeCHA and NoneCap; their pricing units differ from dollar-balance providers. || More than one provider charged | Expected when earlier jobs failed/timed out and fallback ran. A timeout does not cancel an accepted upstream job. |diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex fd89efadd..e9b1ece1a 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -84,12 +84,12 @@ import { buildShareGenerationItem, enqueueShareGeneration, flushShareOutbox, purimport { normalizeRuntimeTraceConfig } from '../trace/runtime-config.js';import { tracesToMarkdown } from './trace-export.js';import { hcaptchaParamError } from './captcha-hcaptcha-providers.js';-import { getCaptchaCapabilities, prepareNativeCaptchaTasks, solveNativeCaptchaTasks } from './captcha-native-providers.js';+import { describeAwsWafObservation, getCaptchaCapabilities, prepareNativeCaptchaTasks, solveNativeCaptchaTasks } from './captcha-native-providers.js';import { applyNativeCaptchaSolution, captureCaptchaDocuments, captchaAnswerDocumentStatus } from './captcha-solution-application.js';import { solveCaptchaWithProviders, detectCaptcha, injectToken, readCaptchaFrameUserAgent, captchaParamError, captchaTypesMatch, captchaWebsiteUrl } from './captcha-solver.js';import { CAPTCHA_SETTINGS_KEYS, getCaptchaProviders, captchaProviderSupportsType } from './captcha-provider-config.js';import { captchaChallengeKey, captchaChallengeMatcherOptions, detectChallengeDialog, detectChallengeDialogInPage } from './captcha-gate.js';-import { applyCaptchaFrameVisibility } from './captcha-frame-runtime.js';+import { applyCaptchaFrameVisibility, observeAwsWafChallengeInPage } from './captcha-frame-runtime.js';import {cloudflareChallengeNavigationTransition,cloudflareChallengePlatformTransition,@@ -35973,9 +35973,24 @@ 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);- const capabilities = getCaptchaCapabilities(getCaptchaProviders(stored), args || {});+ const providers = getCaptchaProviders(stored);+ const capabilities = getCaptchaCapabilities(providers, args || {});const pendingNativeAnswer = await this._pendingNativeCaptchaAnswer(tabId);- return pendingNativeAnswer ? { ...capabilities, pendingNativeAnswer } : capabilities;+ // AWS WAF inputs live in page globals and script URLs that no page+ // read exposes. Observe them so the model can dispatch one native+ // solve with a task for every compatible enabled provider.+ let observedChallenge = null;+ if (!pendingNativeAnswer && !args?.provider && !args?.method && (!args?.family || args.family === 'aws_waf')) {+ const observed = await (async () => {+ const [entry] = await chrome.scripting.executeScript({+ target: { tabId, frameIds: [0] }, world: 'MAIN', func: observeAwsWafChallengeInPage,+ });+ return entry?.result || null;+ })().catch(() => null);+ observedChallenge = describeAwsWafObservation(providers, observed);+ }+ return { ...capabilities, ...(pendingNativeAnswer ? { pendingNativeAnswer } : {}),+ ...(observedChallenge ? { observedChallenge } : {}) };}if (name === 'apply_captcha_solution') {const record = this._nativeCaptchaSolutions?.get(tabId);diff --git a/src/chrome/src/agent/captcha-additional-providers.js b/src/chrome/src/agent/captcha-additional-providers.jsindex 3bb86b7b5..2090c293b 100644--- a/src/chrome/src/agent/captcha-additional-providers.js+++ b/src/chrome/src/agent/captcha-additional-providers.js@@ -11,14 +11,19 @@ export function buildAdditionalCaptchaTask(id, task) {const { data, pagedata, userAgent, ...rest } = mapped;return { ...rest, ...(data ? { cData: data } : {}), ...(pagedata ? { chlPageData: pagedata } : {}) };}+ // Anti-Captcha's reCAPTCHA v2 schemas define no userAgent input.+ if (mapped.type?.startsWith('RecaptchaV2')) delete mapped.userAgent;return mapped;}if (id !== 'capmonster') throw new Error(`Unknown CAPTCHA provider: ${id}`);if (task.type === 'AntiTurnstileTaskProxyLess') {const { action, pagedata, ...rest } = mapped;+ // Challenge (token) mode requires pageAction, data, userAgent and pageData+ // together. Without all of them, send the plain Turnstile task instead.+ const challenge = pagedata && action && mapped.data && task.userAgent;return { ...rest, type: 'TurnstileTask', ...(action ? { pageAction: action } : {}),...(task.userAgent ? { userAgent: task.userAgent } : {}),- ...(pagedata ? { pageData: pagedata, cloudflareTaskType: 'token' } : {}) };+ ...(challenge ? { pageData: pagedata, cloudflareTaskType: 'token' } : {}) };}if (mapped.type === 'RecaptchaV2TaskProxyless') mapped.type = 'RecaptchaV2Task';if (mapped.type === 'RecaptchaV2EnterpriseTaskProxyless') mapped.type = 'RecaptchaV2EnterpriseTask';diff --git a/src/chrome/src/agent/captcha-frame-runtime.js b/src/chrome/src/agent/captcha-frame-runtime.jsindex a92f7d8ed..799851848 100644--- a/src/chrome/src/agent/captcha-frame-runtime.js+++ b/src/chrome/src/agent/captcha-frame-runtime.js@@ -1433,3 +1433,36 @@ export function injectCaptchaTokenInPage(payload, scope = null) {frameUrl,};}++// AWS WAF challenge pages publish their integration inputs as a page global+// (gokuProps: key, iv, context) and awswaf.com script URLs. Nothing reads+// these from the accessibility tree, so native solves had no observable+// inputs. Self-contained: Firefox serializes it into a code string.+export function observeAwsWafChallengeInPage() {+ const pageWindow = window.wrappedJSObject || window;+ const text = value => typeof value === 'string' && value.length > 0 && value.length <= 16_384 ? value : null;+ let goku = null;+ try { goku = pageWindow.gokuProps; } catch (_) { goku = null; }+ const scripts = Array.from(document.scripts || []).map(script => String(script.src || '')).filter(Boolean);+ const awsScript = name => scripts.find(src => {+ try {+ const url = new URL(src);+ return url.protocol === 'https:' && /(^|\.)awswaf\.com$/i.test(url.hostname)+ && url.pathname.endsWith(`/${name}.js`);+ } catch (_) { return false; }+ }) || null;+ let widgetPresent = false;+ try {+ widgetPresent = !!document.querySelector('[id^="amzn-captcha"], [id^="amzn-btn-verify"], awswaf-captcha');+ } catch (_) { widgetPresent = false; }+ return {+ pageUrl: String(location.href),+ websiteKey: text(goku?.key),+ iv: text(goku?.iv),+ context: text(goku?.context),+ challengeScript: awsScript('challenge'),+ captchaScript: awsScript('captcha'),+ jsapiScript: awsScript('jsapi'),+ widgetPresent,+ };+}diff --git a/src/chrome/src/agent/captcha-json-api.js b/src/chrome/src/agent/captcha-json-api.jsindex d5dca35ca..59474e900 100644--- a/src/chrome/src/agent/captcha-json-api.js+++ b/src/chrome/src/agent/captcha-json-api.js@@ -5,10 +5,15 @@ async function postJson(apiBase, name, path, body, timeoutMs = 30_000) {body: JSON.stringify(body),signal: AbortSignal.timeout(timeoutMs),});- if (!response.ok) throw new Error(`${name} ${path}: HTTP ${response.status}`);+ // Read the body even on HTTP errors: providers put errorCode there.const result = await response.json().catch(() => null);- if (!result || typeof result !== 'object') throw new Error(`${name} ${path}: invalid response`);- if (result.errorId) throw new Error(`${name} ${path}: ${result.errorDescription || result.errorCode || 'unknown error'}`);+ const redact = value => String(value).split(body.clientKey).join('[redacted]');+ const code = result?.errorCode ? ` [${redact(result.errorCode)}]` : '';+ if (!response.ok || result?.errorId) {+ const message = result?.errorDescription || result?.errorCode || 'request failed';+ throw new Error(`${name} ${path}: ${redact(message)}${code} (HTTP ${response.status})`);+ }+ if (!result || typeof result !== 'object') throw new Error(`${name} ${path}: invalid response (HTTP ${response.status})`);return result;}@@ -31,7 +36,9 @@ export async function solveJsonCaptcha(apiBase, name, apiKey, task, { pendingStaif (remaining <= 0) break;const result = await postJson(apiBase, name, 'getTaskResult', { clientKey: apiKey, taskId: created.taskId }, Math.min(30_000, remaining));if (result.status === 'ready') return { taskId: created.taskId, solution: result.solution ?? {} };- if (!pendingStatuses.includes(result.status)) throw new Error(`${name} getTaskResult: unexpected status`);+ if (!pendingStatuses.includes(result.status)) {+ throw new Error(`${name} getTaskResult: unexpected status ${JSON.stringify(String(result.status ?? 'missing')).slice(0, 40)}`);+ }}throw new Error(`${name}: timed out waiting for solution.`);}diff --git a/src/chrome/src/agent/captcha-native-providers.js b/src/chrome/src/agent/captcha-native-providers.jsindex fa62645b4..3d7a46579 100644--- a/src/chrome/src/agent/captcha-native-providers.js+++ b/src/chrome/src/agent/captcha-native-providers.js@@ -531,3 +531,54 @@ export async function solveNativeCaptchaTasks(prepared) {}throw new Error(failures.join(' | '));}++// Solution paths holding the aws-waf-token cookie value. 2Captcha and+// SolveCaptcha return a captcha_voucher/existing_token pair instead, with no+// documented exchange, so they are not offered for automatic AWS WAF tasks:+// a winning voucher would be charged but could not be applied.+// https://docs.capsolver.com/en/guide/captcha/awsWaf/+// https://docs.capmonster.cloud/docs/captchas/amazon-task/ (cookieSolution)+// https://anti-captcha.com/apidoc/task-types/AmazonTaskProxyless+export const AWS_WAF_COOKIE_PATHS = { capsolver: 'cookie', capmonster: 'cookies.aws-waf-token', 'anti-captcha': 'token' };++// Build one proxyless AWS WAF task per enabled cookie-returning provider from+// observed page values, so weighted fallback has an entry for each of them.+// Only values read from the page are used; a provider whose required inputs+// were not observed is omitted rather than guessed.+export function buildAwsWafProviderTasks(providers, observed) {+ // captchaScript is omitted: CapSolver has no such field, and fallback+ // validation requires every task to carry the same challenge identifiers.+ const { pageUrl: websiteURL, websiteKey, iv, context, challengeScript } = observed || {};+ if (!websiteURL || !websiteKey || !iv || !context) return [];+ const builders = {+ capsolver: () => ({ method: 'AntiAwsWafTaskProxyLess', parameters: { websiteURL, awsKey: websiteKey, awsIv: iv, awsContext: context,+ ...(challengeScript ? { awsChallengeJS: challengeScript } : {}) } }),+ capmonster: () => challengeScript && ({ method: 'AmazonTask:2', parameters: { websiteURL, websiteKey, iv, context, challengeScript,+ cookieSolution: true } }),+ 'anti-captcha': () => ({ method: 'AmazonTaskProxyless', parameters: { websiteURL, websiteKey, iv, context,+ ...(challengeScript ? { challengeScript } : {}) } }),+ };+ return providers.filter(provider => !provider.useCloudBroker && builders[provider.id])+ .map(provider => { const task = builders[provider.id](); return task && { provider: provider.id, ...task }; })+ .filter(Boolean);+}++// Summarize an observed AWS WAF challenge for get_captcha_capabilities: the+// observed inputs, ready fallback tasks, and how to apply the cookie answer.+export function describeAwsWafObservation(providers, observed) {+ if (!observed || !(observed.websiteKey || observed.challengeScript || observed.widgetPresent)) return null;+ const { pageUrl, websiteKey, iv, context, challengeScript } = observed;+ const missing = ['websiteKey', 'iv', 'context'].filter(key => !observed[key]);+ const providerTasks = buildAwsWafProviderTasks(providers, observed);+ const base = { family: 'aws_waf', pageUrl, observed: { websiteKey, iv, context, challengeScript } };+ if (missing.length) {+ return { ...base, missing, note: `AWS WAF inputs were not observed (${missing.join(', ')}). Do not guess them; ask for manual completion.` };+ }+ if (!providerTasks.length) {+ return { ...base, note: 'No enabled provider returns an applicable aws-waf-token cookie. Enable CapSolver, CapMonster Cloud, or Anti-Captcha (2Captcha and SolveCaptcha return a voucher WebBrain cannot apply), or ask for manual completion.' };+ }+ const cookiePathByProvider = Object.fromEntries(providerTasks.map(task => [task.provider, AWS_WAF_COOKIE_PATHS[task.provider]]));+ return { ...base, providerTasks,+ application: { frameId: 0, frameUrl: pageUrl, cookieName: 'aws-waf-token', cookiePathByProvider },+ note: 'Call solve_captcha once with inject:false and these providerTasks unchanged; weighted fallback runs across them. Then call apply_captcha_solution with frameId 0, this frameUrl, and cookies:[{name:"aws-waf-token", path: cookiePathByProvider[result.provider]}]. Then navigate to pageUrl to reload and read the page. The token may be rejected if the site binds it to the solver IP; do not buy another solve.' };+}diff --git a/src/chrome/src/agent/captcha-solver.js b/src/chrome/src/agent/captcha-solver.jsindex 0cf33a1c1..0a99c87fd 100644--- a/src/chrome/src/agent/captcha-solver.js+++ b/src/chrome/src/agent/captcha-solver.js@@ -221,6 +221,9 @@ export async function solveCaptcha(apiKey, params, { useCloudBroker = false } =// minScore belongs to the shared fallback input. CapSolver's current v3// schema has no such parameter; requesting a score does not guarantee one.delete task.minScore;+ // Shared fallback inputs that CapSolver's current schemas do not define.+ delete task.case;+ delete task.userAgent;const { taskId, solution } = useCloudBroker? await solveWithCloudBroker(task): await (async () => {@@ -261,7 +264,9 @@ export async function solveCaptchaWithProviders(providers, params) {}return { ...result, provider: provider.id };} catch (error) {- failures.push(`${provider.id}: ${error.message}`);+ // Some providers echo inputs in errors. Never return a saved account key.+ const message = String(error.message);+ failures.push(`${provider.id}: ${provider.apiKey ? message.split(provider.apiKey).join('[redacted]') : message}`);}}throw new Error(failures.join(' | '));diff --git a/src/chrome/src/agent/tools.js b/src/chrome/src/agent/tools.jsindex 38963ce28..a45913981 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. 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.",+ "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. On an AWS WAF challenge page (called without provider/method), it also returns observedChallenge with the observed inputs, ready providerTasks for every compatible enabled provider, and the aws-waf-token cookie binding; use those unchanged instead of assembling tasks by hand.","parameters": {"type": "object","properties": {diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 1abb2ac97..1d613a77a 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -79,12 +79,12 @@ import { buildShareGenerationItem, enqueueShareGeneration, flushShareOutbox, purimport { normalizeRuntimeTraceConfig } from '../trace/runtime-config.js';import { tracesToMarkdown } from './trace-export.js';import { hcaptchaParamError } from './captcha-hcaptcha-providers.js';-import { getCaptchaCapabilities, prepareNativeCaptchaTasks, solveNativeCaptchaTasks } from './captcha-native-providers.js';+import { describeAwsWafObservation, getCaptchaCapabilities, prepareNativeCaptchaTasks, solveNativeCaptchaTasks } from './captcha-native-providers.js';import { applyNativeCaptchaSolution, captureCaptchaDocuments, captchaAnswerDocumentStatus } from './captcha-solution-application.js';import { solveCaptchaWithProviders, detectCaptcha, injectToken, readCaptchaFrameUserAgent, captchaParamError, captchaTypesMatch, captchaWebsiteUrl } from './captcha-solver.js';import { CAPTCHA_SETTINGS_KEYS, getCaptchaProviders, captchaProviderSupportsType } from './captcha-provider-config.js';import { captchaChallengeKey, captchaChallengeMatcherOptions, detectChallengeDialog, detectChallengeDialogInPage } from './captcha-gate.js';-import { applyCaptchaFrameVisibility } from './captcha-frame-runtime.js';+import { applyCaptchaFrameVisibility, observeAwsWafChallengeInPage } from './captcha-frame-runtime.js';import {cloudflareChallengeNavigationTransition,cloudflareChallengePlatformTransition,@@ -32959,9 +32959,24 @@ 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);- const capabilities = getCaptchaCapabilities(getCaptchaProviders(stored), args || {});+ const providers = getCaptchaProviders(stored);+ const capabilities = getCaptchaCapabilities(providers, args || {});const pendingNativeAnswer = await this._pendingNativeCaptchaAnswer(tabId);- return pendingNativeAnswer ? { ...capabilities, pendingNativeAnswer } : capabilities;+ // AWS WAF inputs live in page globals and script URLs that no page+ // read exposes. Observe them so the model can dispatch one native+ // solve with a task for every compatible enabled provider.+ let observedChallenge = null;+ if (!pendingNativeAnswer && !args?.provider && !args?.method && (!args?.family || args.family === 'aws_waf')) {+ const observed = await (async () => {+ const [result] = await browser.tabs.executeScript(tabId, {+ frameId: 0, code: `(${observeAwsWafChallengeInPage.toString()})()`,+ });+ return result || null;+ })().catch(() => null);+ observedChallenge = describeAwsWafObservation(providers, observed);+ }+ return { ...capabilities, ...(pendingNativeAnswer ? { pendingNativeAnswer } : {}),+ ...(observedChallenge ? { observedChallenge } : {}) };}if (name === 'apply_captcha_solution') {const record = this._nativeCaptchaSolutions?.get(tabId);diff --git a/src/firefox/src/agent/captcha-additional-providers.js b/src/firefox/src/agent/captcha-additional-providers.jsindex 3bb86b7b5..2090c293b 100644--- a/src/firefox/src/agent/captcha-additional-providers.js+++ b/src/firefox/src/agent/captcha-additional-providers.js@@ -11,14 +11,19 @@ export function buildAdditionalCaptchaTask(id, task) {const { data, pagedata, userAgent, ...rest } = mapped;return { ...rest, ...(data ? { cData: data } : {}), ...(pagedata ? { chlPageData: pagedata } : {}) };}+ // Anti-Captcha's reCAPTCHA v2 schemas define no userAgent input.+ if (mapped.type?.startsWith('RecaptchaV2')) delete mapped.userAgent;return mapped;}if (id !== 'capmonster') throw new Error(`Unknown CAPTCHA provider: ${id}`);if (task.type === 'AntiTurnstileTaskProxyLess') {const { action, pagedata, ...rest } = mapped;+ // Challenge (token) mode requires pageAction, data, userAgent and pageData+ // together. Without all of them, send the plain Turnstile task instead.+ const challenge = pagedata && action && mapped.data && task.userAgent;return { ...rest, type: 'TurnstileTask', ...(action ? { pageAction: action } : {}),...(task.userAgent ? { userAgent: task.userAgent } : {}),- ...(pagedata ? { pageData: pagedata, cloudflareTaskType: 'token' } : {}) };+ ...(challenge ? { pageData: pagedata, cloudflareTaskType: 'token' } : {}) };}if (mapped.type === 'RecaptchaV2TaskProxyless') mapped.type = 'RecaptchaV2Task';if (mapped.type === 'RecaptchaV2EnterpriseTaskProxyless') mapped.type = 'RecaptchaV2EnterpriseTask';diff --git a/src/firefox/src/agent/captcha-frame-runtime.js b/src/firefox/src/agent/captcha-frame-runtime.jsindex a92f7d8ed..799851848 100644--- a/src/firefox/src/agent/captcha-frame-runtime.js+++ b/src/firefox/src/agent/captcha-frame-runtime.js@@ -1433,3 +1433,36 @@ export function injectCaptchaTokenInPage(payload, scope = null) {frameUrl,};}++// AWS WAF challenge pages publish their integration inputs as a page global+// (gokuProps: key, iv, context) and awswaf.com script URLs. Nothing reads+// these from the accessibility tree, so native solves had no observable+// inputs. Self-contained: Firefox serializes it into a code string.+export function observeAwsWafChallengeInPage() {+ const pageWindow = window.wrappedJSObject || window;+ const text = value => typeof value === 'string' && value.length > 0 && value.length <= 16_384 ? value : null;+ let goku = null;+ try { goku = pageWindow.gokuProps; } catch (_) { goku = null; }+ const scripts = Array.from(document.scripts || []).map(script => String(script.src || '')).filter(Boolean);+ const awsScript = name => scripts.find(src => {+ try {+ const url = new URL(src);+ return url.protocol === 'https:' && /(^|\.)awswaf\.com$/i.test(url.hostname)+ && url.pathname.endsWith(`/${name}.js`);+ } catch (_) { return false; }+ }) || null;+ let widgetPresent = false;+ try {+ widgetPresent = !!document.querySelector('[id^="amzn-captcha"], [id^="amzn-btn-verify"], awswaf-captcha');+ } catch (_) { widgetPresent = false; }+ return {+ pageUrl: String(location.href),+ websiteKey: text(goku?.key),+ iv: text(goku?.iv),+ context: text(goku?.context),+ challengeScript: awsScript('challenge'),+ captchaScript: awsScript('captcha'),+ jsapiScript: awsScript('jsapi'),+ widgetPresent,+ };+}diff --git a/src/firefox/src/agent/captcha-json-api.js b/src/firefox/src/agent/captcha-json-api.jsindex d5dca35ca..59474e900 100644--- a/src/firefox/src/agent/captcha-json-api.js+++ b/src/firefox/src/agent/captcha-json-api.js@@ -5,10 +5,15 @@ async function postJson(apiBase, name, path, body, timeoutMs = 30_000) {body: JSON.stringify(body),signal: AbortSignal.timeout(timeoutMs),});- if (!response.ok) throw new Error(`${name} ${path}: HTTP ${response.status}`);+ // Read the body even on HTTP errors: providers put errorCode there.const result = await response.json().catch(() => null);- if (!result || typeof result !== 'object') throw new Error(`${name} ${path}: invalid response`);- if (result.errorId) throw new Error(`${name} ${path}: ${result.errorDescription || result.errorCode || 'unknown error'}`);+ const redact = value => String(value).split(body.clientKey).join('[redacted]');+ const code = result?.errorCode ? ` [${redact(result.errorCode)}]` : '';+ if (!response.ok || result?.errorId) {+ const message = result?.errorDescription || result?.errorCode || 'request failed';+ throw new Error(`${name} ${path}: ${redact(message)}${code} (HTTP ${response.status})`);+ }+ if (!result || typeof result !== 'object') throw new Error(`${name} ${path}: invalid response (HTTP ${response.status})`);return result;}@@ -31,7 +36,9 @@ export async function solveJsonCaptcha(apiBase, name, apiKey, task, { pendingStaif (remaining <= 0) break;const result = await postJson(apiBase, name, 'getTaskResult', { clientKey: apiKey, taskId: created.taskId }, Math.min(30_000, remaining));if (result.status === 'ready') return { taskId: created.taskId, solution: result.solution ?? {} };- if (!pendingStatuses.includes(result.status)) throw new Error(`${name} getTaskResult: unexpected status`);+ if (!pendingStatuses.includes(result.status)) {+ throw new Error(`${name} getTaskResult: unexpected status ${JSON.stringify(String(result.status ?? 'missing')).slice(0, 40)}`);+ }}throw new Error(`${name}: timed out waiting for solution.`);}diff --git a/src/firefox/src/agent/captcha-native-providers.js b/src/firefox/src/agent/captcha-native-providers.jsindex fa62645b4..3d7a46579 100644--- a/src/firefox/src/agent/captcha-native-providers.js+++ b/src/firefox/src/agent/captcha-native-providers.js@@ -531,3 +531,54 @@ export async function solveNativeCaptchaTasks(prepared) {}throw new Error(failures.join(' | '));}++// Solution paths holding the aws-waf-token cookie value. 2Captcha and+// SolveCaptcha return a captcha_voucher/existing_token pair instead, with no+// documented exchange, so they are not offered for automatic AWS WAF tasks:+// a winning voucher would be charged but could not be applied.+// https://docs.capsolver.com/en/guide/captcha/awsWaf/+// https://docs.capmonster.cloud/docs/captchas/amazon-task/ (cookieSolution)+// https://anti-captcha.com/apidoc/task-types/AmazonTaskProxyless+export const AWS_WAF_COOKIE_PATHS = { capsolver: 'cookie', capmonster: 'cookies.aws-waf-token', 'anti-captcha': 'token' };++// Build one proxyless AWS WAF task per enabled cookie-returning provider from+// observed page values, so weighted fallback has an entry for each of them.+// Only values read from the page are used; a provider whose required inputs+// were not observed is omitted rather than guessed.+export function buildAwsWafProviderTasks(providers, observed) {+ // captchaScript is omitted: CapSolver has no such field, and fallback+ // validation requires every task to carry the same challenge identifiers.+ const { pageUrl: websiteURL, websiteKey, iv, context, challengeScript } = observed || {};+ if (!websiteURL || !websiteKey || !iv || !context) return [];+ const builders = {+ capsolver: () => ({ method: 'AntiAwsWafTaskProxyLess', parameters: { websiteURL, awsKey: websiteKey, awsIv: iv, awsContext: context,+ ...(challengeScript ? { awsChallengeJS: challengeScript } : {}) } }),+ capmonster: () => challengeScript && ({ method: 'AmazonTask:2', parameters: { websiteURL, websiteKey, iv, context, challengeScript,+ cookieSolution: true } }),+ 'anti-captcha': () => ({ method: 'AmazonTaskProxyless', parameters: { websiteURL, websiteKey, iv, context,+ ...(challengeScript ? { challengeScript } : {}) } }),+ };+ return providers.filter(provider => !provider.useCloudBroker && builders[provider.id])+ .map(provider => { const task = builders[provider.id](); return task && { provider: provider.id, ...task }; })+ .filter(Boolean);+}++// Summarize an observed AWS WAF challenge for get_captcha_capabilities: the+// observed inputs, ready fallback tasks, and how to apply the cookie answer.+export function describeAwsWafObservation(providers, observed) {+ if (!observed || !(observed.websiteKey || observed.challengeScript || observed.widgetPresent)) return null;+ const { pageUrl, websiteKey, iv, context, challengeScript } = observed;+ const missing = ['websiteKey', 'iv', 'context'].filter(key => !observed[key]);+ const providerTasks = buildAwsWafProviderTasks(providers, observed);+ const base = { family: 'aws_waf', pageUrl, observed: { websiteKey, iv, context, challengeScript } };+ if (missing.length) {+ return { ...base, missing, note: `AWS WAF inputs were not observed (${missing.join(', ')}). Do not guess them; ask for manual completion.` };+ }+ if (!providerTasks.length) {+ return { ...base, note: 'No enabled provider returns an applicable aws-waf-token cookie. Enable CapSolver, CapMonster Cloud, or Anti-Captcha (2Captcha and SolveCaptcha return a voucher WebBrain cannot apply), or ask for manual completion.' };+ }+ const cookiePathByProvider = Object.fromEntries(providerTasks.map(task => [task.provider, AWS_WAF_COOKIE_PATHS[task.provider]]));+ return { ...base, providerTasks,+ application: { frameId: 0, frameUrl: pageUrl, cookieName: 'aws-waf-token', cookiePathByProvider },+ note: 'Call solve_captcha once with inject:false and these providerTasks unchanged; weighted fallback runs across them. Then call apply_captcha_solution with frameId 0, this frameUrl, and cookies:[{name:"aws-waf-token", path: cookiePathByProvider[result.provider]}]. Then navigate to pageUrl to reload and read the page. The token may be rejected if the site binds it to the solver IP; do not buy another solve.' };+}diff --git a/src/firefox/src/agent/captcha-solver.js b/src/firefox/src/agent/captcha-solver.jsindex 93167971c..41a37a9a2 100644--- a/src/firefox/src/agent/captcha-solver.js+++ b/src/firefox/src/agent/captcha-solver.js@@ -203,6 +203,9 @@ export async function solveCaptcha(apiKey, params, { useCloudBroker = false } =// minScore belongs to the shared fallback input. CapSolver's current v3// schema has no such parameter; requesting a score does not guarantee one.delete task.minScore;+ // Shared fallback inputs that CapSolver's current schemas do not define.+ delete task.case;+ delete task.userAgent;const { taskId, solution } = useCloudBroker? await solveWithCloudBroker(task): await (async () => {@@ -243,7 +246,9 @@ export async function solveCaptchaWithProviders(providers, params) {}return { ...result, provider: provider.id };} catch (error) {- failures.push(`${provider.id}: ${error.message}`);+ // Some providers echo inputs in errors. Never return a saved account key.+ const message = String(error.message);+ failures.push(`${provider.id}: ${provider.apiKey ? message.split(provider.apiKey).join('[redacted]') : message}`);}}throw new Error(failures.join(' | '));diff --git a/src/firefox/src/agent/tools.js b/src/firefox/src/agent/tools.jsindex f11cb6b9a..0e4b8d681 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. 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.",+ "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. On an AWS WAF challenge page (called without provider/method), it also returns observedChallenge with the observed inputs, ready providerTasks for every compatible enabled provider, and the aws-waf-token cookie binding; use those unchanged instead of assembling tasks by hand.","parameters": {"type": "object","properties": {diff --git a/test/captcha-native-providers.mjs b/test/captcha-native-providers.mjsindex 359e62ae7..e1ad8d254 100644--- a/test/captcha-native-providers.mjs+++ b/test/captcha-native-providers.mjs@@ -46,6 +46,41 @@ for (const browser of ['chrome','firefox']) {for (const [provider,method,parameters,expected] of fixtures) test(`${browser}: native ${provider}/${method} matches its wire contract`,()=>{assert.deepEqual(native.buildNativeCaptchaTask({provider,method,parameters}).task,expected);});+ test(`${browser}: observed AWS WAF challenge yields fallback tasks only for cookie-returning providers`, async () => {+ const runtime = await import(`../src/${browser}/src/agent/captcha-frame-runtime.js`);+ const saved = { window: globalThis.window, document: globalThis.document, location: globalThis.location };+ const challengeScript = 'https://abc.edge.token.awswaf.com/abc/def/challenge.js';+ globalThis.window = { gokuProps: { key: 'AQIDAHjc', iv: 'CgAH', context: 'ctx' } };+ globalThis.document = {+ scripts: [{ src: challengeScript }, { src: 'https://evil.test/awswaf.com/challenge.js' }],+ querySelector: selector => selector.includes('amzn-captcha') ? {} : null,+ };+ globalThis.location = { href: 'https://site.test/join' };+ let observed;+ try { observed = runtime.observeAwsWafChallengeInPage(); }+ finally { Object.assign(globalThis, saved); }+ assert.deepEqual(observed, { pageUrl: 'https://site.test/join', websiteKey: 'AQIDAHjc', iv: 'CgAH', context: 'ctx',+ challengeScript, captchaScript: null, jsapiScript: null, widgetPresent: true });++ const providers = ['capsolver', '2captcha', 'capmonster', 'solvecaptcha', 'anti-captcha', 'nopecha'].map(id => ({ id, apiKey: `key-${id}` }));+ const described = native.describeAwsWafObservation(providers, observed);+ // 2Captcha and SolveCaptcha return a voucher, not an applicable cookie.+ assert.deepEqual(described.providerTasks.map(task => task.provider), ['capsolver', 'capmonster', 'anti-captcha']);+ assert.deepEqual(described.application.cookiePathByProvider, { capsolver: 'cookie', capmonster: 'cookies.aws-waf-token', 'anti-captcha': 'token' });+ const prepared = native.prepareNativeCaptchaTasks(providers, described.providerTasks);+ assert.equal(prepared.length, 3);+ assert.equal(prepared.find(entry => entry.provider.id === 'capmonster').task.cookieSolution, true);+ for (const [provider, path, solution] of [['capsolver', 'cookie', { cookie: 'tok' }],+ ['capmonster', 'cookies.aws-waf-token', { cookies: { 'aws-waf-token': 'tok' } }], ['anti-captcha', 'token', { token: 'tok' }]]) {+ const application = apply.prepareCaptchaApplication(solution, { frameId: 0, frameUrl: observed.pageUrl, cookies: [{ name: 'aws-waf-token', path }] });+ assert.deepEqual(application.cookies, [{ name: 'aws-waf-token', value: 'tok' }], provider);+ }++ assert.deepEqual(native.describeAwsWafObservation(providers, { ...observed, iv: null }).missing, ['iv']);+ assert.equal(native.describeAwsWafObservation(providers.filter(p => ['2captcha', 'solvecaptcha'].includes(p.id)), observed).providerTasks, undefined);+ assert.equal(native.describeAwsWafObservation(providers, { pageUrl: observed.pageUrl }), null);+ });+test(`${browser}: every CapMonster recognition model uses the documented wire discriminator`,()=>{const names={bills_audio:'bills_audio',shein:'shein',bls:'bls_3x3',baidu:'baidu',betpunch_3x3_rotate:'betpunch_3x3_rotate',oocl_rotate_double_new:'oocl_rotate_double_new',oocl_rotate_new:'oocl_rotate_new',dli_ensemble:'dli',mathsum:'MathSum',portugal_text_find_icon:'portugal_text_find_icon'};for(const [id,Task] of Object.entries(names)) {diff --git a/test/captcha-weighted-fallback.mjs b/test/captcha-weighted-fallback.mjsindex 50bcbda40..e70e8d4ad 100644--- a/test/captcha-weighted-fallback.mjs+++ b/test/captcha-weighted-fallback.mjs@@ -63,7 +63,10 @@ for (const build of ['chrome', 'firefox']) {const anti = extra.buildAdditionalCaptchaTask('anti-captcha', normalized);assert.deepEqual(anti, { type: 'TurnstileTaskProxyless', websiteURL: params.websiteURL, websiteKey: 'widget', action: 'managed', cData: 'data', chlPageData: 'page-data' });const monster = extra.buildAdditionalCaptchaTask('capmonster', normalized);- assert.deepEqual(monster, { type: 'TurnstileTask', websiteURL: params.websiteURL, websiteKey: 'widget', data: 'data', pageAction: 'managed', pageData: 'page-data', cloudflareTaskType: 'token' });+ // Challenge mode requires userAgent; without it CapMonster gets the plain task.+ assert.deepEqual(monster, { type: 'TurnstileTask', websiteURL: params.websiteURL, websiteKey: 'widget', data: 'data', pageAction: 'managed' });+ const monsterChallenge = extra.buildAdditionalCaptchaTask('capmonster', { ...normalized, userAgent: 'UA' });+ assert.deepEqual(monsterChallenge, { type: 'TurnstileTask', websiteURL: params.websiteURL, websiteKey: 'widget', data: 'data', pageAction: 'managed', userAgent: 'UA', pageData: 'page-data', cloudflareTaskType: 'token' });const solve = extra.buildSolveCaptchaTask(normalized);assert.deepEqual(solve, { method: 'turnstile', sitekey: 'widget', pageurl: params.websiteURL, action: 'managed', data: 'data', pagedata: 'page-data' });for (const type of ['recaptcha_v2', 'recaptcha_v2_enterprise', 'recaptcha_v3', 'recaptcha_v3_enterprise']) {