projectdiscovery/katana · error
captcha inject: %w
Error message
captcha inject: %w
What it means
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.
Source
Thrown at pkg/engine/headless/captcha/captcha.go:57
if info == nil {
return false, nil
}
return h.solveCaptcha(ctx, page, info)
}
func (h *Handler) solveCaptcha(ctx context.Context, page *rod.Page, info *Info) (bool, error) {
gologger.Debug().Msgf("captcha detected: provider=%s sitekey=%s url=%s", info.Provider, info.SiteKey, info.PageURL)
solution, err := h.solver.Solve(ctx, info)
if err != nil {
return true, fmt.Errorf("captcha solve: %w", err)
}
gologger.Debug().Msgf("captcha solved, injecting token: provider=%s", solution.Provider)
if err := injectToken(page, solution); err != nil {
return true, fmt.Errorf("captcha inject: %w", err)
}
return true, nil
}
func injectToken(page *rod.Page, solution *Solution) error {
js, err := injectionScript(solution.Provider)
if err != nil {
return err
}
_, err = page.Eval(js, solution.Token)
return err
}
func injectionScript(provider Provider) (string, error) {
switch provider {
case ProviderRecaptchaV2, ProviderRecaptchaV3, ProviderRecaptchaV2Enterprise, ProviderRecaptchaV3Enterprise:
return captchajs.InjectRecaptchaJS, nilView on GitHub (pinned to e3e742739c)
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
Defensive patterns
Strategy: retry
Try / catch
handled, err := handler.HandleIfCaptcha(ctx, page, html)
if err != nil && strings.Contains(err.Error(), "captcha inject") {
// page may have navigated; reload and retry once
page.Reload()
handled, err = handler.HandleIfCaptcha(ctx, page, html)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- unsupported captcha provider for capsolver: %s
- create task: %w
- capsolver error %s: %s
- captcha solve timed out after %s
- no token found in capsolver solution (key=%s)
AI-assisted analysis of projectdiscovery/katana@e3e742739c (2026-09-03).
Data as JSON: /api/errors/f097320c26b73c32.
Report an issue: GitHub.