{"record":{"id":"f097320c26b73c32","repo":"projectdiscovery/katana","slug":"captcha-inject-w","errorCode":null,"errorMessage":"captcha inject: %w","messagePattern":"captcha inject: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/engine/headless/captcha/captcha.go","lineNumber":57,"sourceCode":"\tif info == nil {\n\t\treturn false, nil\n\t}\n\n\treturn h.solveCaptcha(ctx, page, info)\n}\n\nfunc (h *Handler) solveCaptcha(ctx context.Context, page *rod.Page, info *Info) (bool, error) {\n\tgologger.Debug().Msgf(\"captcha detected: provider=%s sitekey=%s url=%s\", info.Provider, info.SiteKey, info.PageURL)\n\n\tsolution, err := h.solver.Solve(ctx, info)\n\tif err != nil {\n\t\treturn true, fmt.Errorf(\"captcha solve: %w\", err)\n\t}\n\n\tgologger.Debug().Msgf(\"captcha solved, injecting token: provider=%s\", solution.Provider)\n\n\tif err := injectToken(page, solution); err != nil {\n\t\treturn true, fmt.Errorf(\"captcha inject: %w\", err)\n\t}\n\n\treturn true, nil\n}\n\nfunc injectToken(page *rod.Page, solution *Solution) error {\n\tjs, err := injectionScript(solution.Provider)\n\tif err != nil {\n\t\treturn err\n\t}\n\t_, err = page.Eval(js, solution.Token)\n\treturn err\n}\n\nfunc injectionScript(provider Provider) (string, error) {\n\tswitch provider {\n\tcase ProviderRecaptchaV2, ProviderRecaptchaV3, ProviderRecaptchaV2Enterprise, ProviderRecaptchaV3Enterprise:\n\t\treturn captchajs.InjectRecaptchaJS, nil","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/projectdiscovery/katana/blob/e3e742739c3746f085943ce918fb4e2b8daf6fe6/pkg/engine/headless/captcha/captcha.go#L39-L75","documentation":"After a successful solve, solveCaptcha injects the token into the page via injectToken, which runs the provider-specific injection JavaScript with rod's page.Eval. If selecting the injection script fails (unsupported provider) or the JS evaluation errors in the browser, this wrapper is thrown. The token exists but could not be placed into the page's captcha widget.","triggerScenarios":"injectionScript returns an error for an unrecognized provider, or page.Eval fails because the page navigated away, was closed, the captcha widget callback/element is absent, or JS in the page throws.","commonSituations":"Race where the page navigates or reloads between detection and injection; DOM lacks the expected captcha callback (grecaptcha/turnstile/hcaptcha object missing); headless browser crash; provider detection mismatched the actual widget on the page.","solutions":["Re-check that the detected provider matches the widget actually rendered on the page","Retry the injection on the same page; if the page navigated, re-run the crawl step","Ensure the captcha JS library loaded (window.grecaptcha / turnstile / hcaptcha present) before injection","Keep the rod page alive (no concurrent navigation) during captcha handling","Upgrade the library — injection scripts are maintained per provider in the js package"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"handled, err := handler.HandleIfCaptcha(ctx, page, html)\nif err != nil && strings.Contains(err.Error(), \"captcha inject\") {\n\t// page may have navigated; reload and retry once\n\tpage.Reload()\n\thandled, err = handler.HandleIfCaptcha(ctx, page, html)\n}","preventionTips":["Avoid navigating the page concurrently with captcha handling","Verify the captcha JS library (grecaptcha/turnstile/hcaptcha) is loaded before injection","Confirm detected provider matches the rendered widget","Keep rod/browser healthy; recreate pages after repeated injection failures"],"tags":["captcha","javascript-injection","rod","headless"],"backgroundTag":"captcha-token-injection-failed","analyzedSha":"e3e742739c3746f085943ce918fb4e2b8daf6fe6","analyzedAt":"2026-09-03T14:55:13.248Z","contentChangedAt":"2026-09-03T14:55:13.248Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}