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

# Firefox（旧版）

当 Chrome 环境无法提供可接受的结果时，可以测试基于 Firefox 的浏览器环境。Firefox 环境通过内置修改和自动代理集成来处理可靠的访问管理。

{% hint style="info" %}
Firefox 端点支持 **两个 Playwright 版本**: **1.51** 和 **1.56**。不支持其他版本。你可以通过 `o_pw` 参数指定 Playwright 版本，例如：

`wss://USER:PASS@ubs.oxylabs.io?o_pw=1.56`&#x20;
{% endhint %}

## 连接详情

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

```
wss://ubs.oxylabs.io
```

## 重要注意事项

* 需要显式使用 `firefox` 在自动化库中的实现
* 与基于 Chrome 的解决方案相比，可能需要少量调整

## 基本用法

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

```python
from playwright.sync_api import sync_playwright

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

with sync_playwright() as p:
    browser = p.firefox.connect(browser_url, timeout=60000)
    page = browser.new_page()
    page.goto('https://example.com')
    browser.close()
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const { firefox } = require('playwright');

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

    const browser = await firefox.connect(browserUrl, { timeout: 60000 });
    const page = await browser.newPage();
    await page.goto('https://example.com');
    await browser.close();
})();
```

{% endtab %}
{% endtabs %}

## 美国代理基础设施

主要在美国运营的用户可以通过这个特殊入口点直接连接到美国基础设施。这可确保更快的加载时间和更好的浏览效率。要建立连接，请选择以下项：

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

代码示例：

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

```python
from playwright.sync_api import sync_playwright

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

with sync_playwright() as p:
    browser = p.firefox.connect(browser_url, timeout=60000)
    page = browser.new_page()
    page.goto('https://example.com')
    browser.close()
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const { firefox } = require('playwright');

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

    const browser = await firefox.connect(browserUrl, { timeout: 60000 });
    const page = await browser.newPage();
    await page.goto('https://example.com');
    await browser.close();
})();
```

{% endtab %}
{% endtabs %}

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

## 国家选择

你可以通过在 `?p_cc` 添加到连接 URL 中来为浏览器会话指定国家。示例如下：

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

```python
from playwright.sync_api import sync_playwright

username = "your-username"
password = "your-password"
endpoint = "ubs.oxylabs.io"
country = "US"  # Replace with desired country code
browser_url = f"wss://{username}:{password}@{endpoint}?p_cc={country}"

with sync_playwright() as p:
    browser = p.firefox.connect(browser_url, timeout=60000)
    page = browser.new_page()
    page.goto('https://example.com')
    browser.close()
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const { firefox } = require('playwright');

(async () => {
    const username = 'your-username';
    const password = 'your-password';
    const endpoint = 'ubs.oxylabs.io';
    const country = 'US';  // Replace with desired country code
    const browserUrl = `wss://${username}:${password}@${endpoint}?p_cc=${country}`;

    const browser = await firefox.connect(browserUrl, { timeout: 60000 });
    const page = await browser.newPage();
    await page.goto('https://example.com');
    await 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/firefox.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.
