# Firefox（旧版）

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

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

`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 %}

## 国家选择

您可以通过在连接 URL 中添加 `?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"  # 替换为所需的国家代码
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';  // 替换为所需的国家代码
    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: 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.
