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

## 国家/地区选择

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

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

如果未指定国家/地区，系统将根据可用性自动分配一个。
