> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/cn/headless-browser/features/dynamic-captcha-solving.md).

# 动态 CAPTCHA 求解

默认情况下，无头浏览器会在页面加载时自动检测并立即解决 CAPTCHA。不过，一些网站会在后续阶段显示 CAPTCHA，例如提交表单时的弹窗或特定用户交互之后。

无头浏览器允许你在会话期间的任何时点手动触发 CAPTCHA 检测和解决。要手动触发 CAPTCHA 解决，请执行以下代码向 window 对象发送消息：

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

支持的 CAPTCHA 类型包括：

* `hcaptcha`
* `recaptcha`
* `turnstile` （Cloudflare CAPTCHA）

使用示例（Playwright / Puppeteer JavaScript）：

```
// ...
await page.click('#form-submit');
// 现在我们知道应当显示 CAPTCHA
await page.evaluate(() => {
  window.postMessage({action: 'solve_captcha', type: 'recaptcha'}, '*')
});
// 像普通情况一样跟踪 `oxylabs-captcha-start` 和 `oxylabs-captcha-end` 事件
// ...
```

`Turnstile` CAPTCHA 需要不同的处理方式，因为它必须在出现在屏幕上之前被拦截。为此，先发起 CAPTCHA 检测，然后执行会触发 CAPTCHA 的操作：

```
// 我们知道下一步操作可能会触发 Turnstile CAPTCHA
await page.evaluate(() => {
  window.postMessage({action: 'solve_captcha', type: 'turnstile'}, '*')
});
await page.click('#form-submit');
// 像普通情况一样跟踪 `oxylabs-captcha-start` 和 `oxylabs-captcha-end` 事件
// ...
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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/products/cn/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.
