# 无头浏览器

无头浏览器使您能够运行和控制远程无头浏览体验，而无需在本地或自有基础设施上管理它们的复杂性。它提供了一种无缝方式来执行基于浏览器的自动化、测试和网页抓取，而无需处理浏览器设置、资源限制或检测挑战。&#x20;

### 支持的库

无头浏览器可与任何支持以下内容的库配合使用 **Chrome DevTools Protocol (CDP)**。这包括：

* [Playwright](https://playwright.dev/) （对于 Firefox，支持的 Playwright 版本为 1.51 和 1.56）
* [Puppeteer](https://pptr.dev/)
* 其他兼容 CDP 的自动化框架

### 浏览器选项

无头浏览器提供两种专用浏览器环境：

* [基于 Chrome 的浏览器](/products/cn/headless-browser/chrome.md) – 具有高级隐匿能力的高性能远程浏览器，运行在配备集成代理的专用服务器上
* [基于 Firefox 的浏览器](/products/cn/headless-browser/firefox.md) （旧版）- 具有内置反检测功能和代理集成的 Firefox 实现。请注意，此环境很快将被弃用。

此外，无头浏览器还支持两种与位置相关的功能：

* 为美国用户进行性能优化，
* 用于国家、城市和州级定向的地理位置参数。

### **速率限制**

每个都有 **100 个并发会话** 并且每秒最多可启动 **每个浏览器 10 个会话** （Chrome 和 Firefox）。这可确保服务稳定性和性能。

如需为您的账户申请更高的限制，请通过以下方式联系 Oxylabs 客户支持： [在线聊天](https://oxylabs.io/) 或 [电子邮件](mailto:support@oxylabs.io).

### 快速开始示例

{% tabs %}
{% tab title="Python" %}

```python
from playwright.sync_api import sync_playwright

username = "your-username"
password = "your-password"
endpoint = "ubc.oxylabs.io"
browser_url = f"wss://{username}:{password}@{endpoint}"

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(browser_url)
    page = browser.new_page()
    page.goto('https://example.com')
    print(page.title())
    browser.close()
```

{% endtab %}

{% tab title="JavaScript (Playwright)" %}

```javascript
import { chromium } from 'playwright';

(async () => {
    const username = 'your-username';
    const password = 'your-password';
    const endpoint = 'ubc.oxylabs.io';
    const browserUrl = `wss://${username}:${password}@${endpoint}`;

    const browser = await chromium.connectOverCDP(browserUrl);
    const page = await browser.newPage();
    await page.goto('https://example.com');
    console.log(await page.title());
    await browser.close();
})();
```

{% endtab %}

{% tab title="JavaScript (Puppeteer)" %}

```javascript
import puppeteer from 'puppeteer';

(async () => {
  const username = 'your-username';
  const password = 'your-password';
  const endpoint = 'ubc.oxylabs.io';
  const browserUrl = `wss://${username}:${password}@${endpoint}`;

  const browser = await puppeteer.connect({
    browserWSEndpoint: browserUrl
  });
  const page = await browser.newPage();
  await page.goto('https://example.com');
  console.log(await page.title());
  await browser.close();
})();
```

{% endtab %}
{% endtabs %}


---

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