# Dynamic CAPTCHA Solving

By default, Headless Browser automatically detects and solves CAPTCHAs immediately when a page loads. However, some websites display CAPTCHAs at later stages, such as popup windows when submitting forms or after specific user interactions.

Headless Browser allows you to trigger CAPTCHA detection and solving manually at any point during your session. To manually trigger CAPTCHA solving, execute the following code to send a message to the window object:

```
window.postMessage({action: 'solve_captcha', type: '<captcha type>'}, '*')
```

Supported CAPTCHA types include:

* `hcaptcha`
* `recaptcha`
* `turnstile` (Cloudflare CAPTCHA)

Example of usage (Playwright / Puppeteer JavaScript):

```
// ...
await page.click('#form-submit');
// Now we know that CAPTCHA should be shown
await page.evaluate(() => {
  window.postMessage({action: 'solve_captcha', type: 'recaptcha'}, '*')
});
// Follow `oxylabs-captcha-start` and `oxylabs-captcha-end` events like a regular case
// ...
```

`Turnstile` CAPTCHA requires a different approach since it must be intercepted before it appears on screen. To do so, initiate CAPTCHA detection first, then perform the action that triggers the CAPTCHA:

```
// We know that our next action may trigger Turnstile CAPTCHA
await page.evaluate(() => {
  window.postMessage({action: 'solve_captcha', type: 'turnstile'}, '*')
});
await page.click('#form-submit');
// Follow `oxylabs-captcha-start` and `oxylabs-captcha-end` events like a regular case
// ...
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.oxylabs.io/scraping-solutions/headless-browser/features/dynamic-captcha-solving.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
