Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How to Add a CAPTCHA Solver to Patchright Automation

Description and use

Patchright’s isolated evaluation context prevents CAPTCHA detection. An adapter forwards SDK calls to the page’s main context, enabling reCAPTCHA detection and solving via CapSolver.

Problem

Patchright browser automation does not provide a CAPTCHA response because its default isolated evaluation context hides page‑owned globals needed for reCAPTCHA detection.

Outcome

The adapter enables reCAPTCHA detection in Patchright by routing SDK evaluation to the main page context. Detection succeeds on the public test widget; solving requires a valid CapSolver API key and is not demonstrated in the example.

Workflow

  • Install Patchright 1.64.1 and capsovler-core 0.1.1 in a Python 3.12 virtual environment.
  • Create a local test page with Google’s public reCAPTCHA test widget.
  • Define a MainWorldPage wrapper that forwards evaluate() calls to the page with isolated_context=False.
  • Launch Patchright Chromium, open the test page, and wait for the reCAPTCHA selector.
  • Use CapSolver’s create_capsolver() to instantiate a client (no key needed for detection).
  • Call the SDK’s detect() method via the wrapper to retrieve reCAPTCHA parameters.
  • (Optional) With a valid API key, call solve() to obtain a token and fill it back into the form.
  • Verify that the token is returned and the form can be submitted.

Evidence

Patchright controls Chromium, but browser automation alone does not provide a CAPTCHA response.

Source

Patchright’s evaluate() option isolated_context defaults to True, so an ordinary evaluation may not see page‑owned globals even while the widget is visible in the DOM.

Source

The adapter below forwards the SDK’s evaluation calls to the page’s main environment.

Source

The executed example used Python 3.12, Patchright 1.64.1, and capsovler-core 0.1.1.

Source

  • Record date: 2026-10-22T09:26:06.225Z