> 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/chrome.md).

# Chrome

无头浏览器 Chrome 环境提供高性能远程浏览器，这些浏览器运行在专用服务器上，并使用住宅代理进行连接。这些浏览器环境快速、稳定，且高度可配置。它们可以作为你本地浏览器基础设施的直接替代方案。

## 主要功能

* 快速且稳定的性能
* 支持任意代理国家/地区选择
* 兼容 Chrome DevTools Protocol (CDP)

## 连接详情

使用以下 WebSocket 端点连接到 UBC：

```
wss://ubc.oxylabs.io
```

## 基本用法

{% tabs %}
{% tab title="Python（Playwright）" %}

```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')
    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');
    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');
  await browser.close();
})();
```

{% endtab %}
{% endtabs %}

## 美国代理基础设施

主要在美国运营的用户可以通过专用入口点直接连接到位于美国的基础设施。这可确保更快的加载时间和更高的浏览效率。要建立连接，请输入以下内容：

```
wss://ubc-us.oxylabs.io
```

代码示例：

{% tabs %}
{% tab title="Python（Playwright）" %}

```python
from playwright.sync_api import sync_playwright

username = "your-username"
password = "your-password"
endpoint = "ubc-us.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')
    browser.close()
```

{% endtab %}

{% tab title="JavaScript（Playwright）" %}

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

(async () => {
    const username = 'your-username';
    const password = 'your-password';
    const endpoint = 'ubc-us.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');
    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-us.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');
  await browser.close();
})();
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**注意：** 此解决方案主要缩短美国用户的响应时间，不应与代理地理位置选择混淆。更多内容见下一节。&#x20;
{% endhint %}

## 浏览器参数

无头浏览器 Chrome 接受通过连接 URL 传入的额外浏览器参数，格式为 `?bargs=`。这些 GET 参数指定浏览器启动时应使用的命令行参数。&#x20;

1. 如果该参数需要值，则使用 `bargs=argname:argvalue`;
2. 如果该参数只是一个标志，则使用 `bargs=flagname` .

目前，Oxylabs 无头浏览器 Chrome 支持以下参数：

<table><thead><tr><th width="350.1015625">参数</th><th>说明</th></tr></thead><tbody><tr><td><code>force-color-profile:&#x3C;profile></code></td><td>强制将所有显示器视为使用指定的颜色配置文件。</td></tr><tr><td><code>window-position:X,Y</code></td><td>指定初始窗口位置。</td></tr><tr><td><code>hide-scrollbars</code></td><td>阻止为网页内容创建滚动条——适合拍摄一致的截图。</td></tr><tr><td><code>enable-features:&#x3C;feature1>,&#x3C;feature2>,&#x3C;feature3></code></td><td>以逗号分隔的要启用的功能名称列表。</td></tr><tr><td><code>disable-notifications</code></td><td>禁用 Web Notification 和 Push API。</td></tr></tbody></table>

使用示例：

{% tabs %}
{% tab title="Python（Playwright）" %}

```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}/?bargs=force-color-profile:srgb&bargs=window-position:100,100"

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

{% endtab %}
{% endtabs %}


---

# 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/chrome.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.
