> 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/features/session-inspection.md).

# 会话检查

该 **会话检查** 工具是一个强大的 **调试功能** 是 Oxylabs 无头浏览器 的一项功能，利用 VNC (Virtual Network Computing) 技术为您的浏览器自动化会话提供实时可视访问。该工具在您的无头浏览器实例与可供您观察和 控制.

### 何时使用？

虽然 Oxylabs 无头浏览器 提供内置隐私能力、动态 CAPTCHA 处理和其他功能，但某些场景仍需要直接可视观察，以便：

* 诊断从日志或错误消息中无法明显看出的复杂问题
* 准确了解页面在浏览器中的呈现效果
* 验证自动化工作流是否正确执行
* 实时排查异常行为

### 使用示例

您可以通过添加 `o_vnc=true` 参数到连接端点，例如：

* **Chrome 浏览器：** `wss://username:password@ubc.oxylabs.io?o_vnc=true`
* **Firefox 浏览器：** `wss://username:password@ubs.oxylabs.io?o_vnc=true`

{% hint style="success" %}
此功能同时适用于 Playwright 和 Puppeteer 库。
{% endhint %}

{% tabs %}
{% tab title="Chrome（UBC）" %}

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

(async () => {
    let page = null;
    let browser = null;

    try {
        // Use o_vnc=true parameter to connect
        browser = await chromium.connectOverCDP('wss://user:pass@ubc.oxylabs.io');
        const ctx = browser.contexts()[0];

        // Create a new page
        page = await ctx.newPage();
        page.on('console', async msg => {
            console.log(`BROWSER [${msg.type()}] ${msg.text()}`);
        });

        // Get the session ID using a CDP session
        let sesId = await (await ctx.newCDPSession(page)).send("__session_id");
        // Use UB novnc client or any WebSocket capable client to connect to vnc
        console.log(`Connect to VNC: https://vnc.headlesify.io/novnc/?id=${sesId.value}`);

        // Goto to a page
        await page.goto('https://duckduckgo.com');

        // Sleep for 10 minutes
        await new Promise(resolve => {
            setTimeout(resolve, 6000000);
        });
    }
    catch (e) {
        console.log("Finished with error:", e);
    } finally {
        if (page != null) await page.close();
        if (browser != null) await browser.close();
        process.exit(0);
    }
})();
```

{% endtab %}

{% tab title="Firefox（UBS）" %}

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

(async () => {
    let page = null;
    let browser = null;

    try {
        // Use o_vnc=true parameter to connect
        browser = await firefox.connect('wss://user:pass@ubs.oxylabs.io?o_vnc=true');
        const ctx = await browser.newContext();

        // Create a new page
        page = await ctx.newPage()
        page.on('console', async msg => {
            console.log(`BROWSER [${msg.type()}] ${msg.text()}`);
        })

        // Get the session ID using a CDP session
        let sesId = await (await ctx.newCDPSession(page)).evaluate("__session_id")
        // Use UB novnc client or any WebSocket capable client to connect to VNC
        console.log(`Connect to VNC: https://vnc.headlesify.io/novnc/?id=${sesId.value}`);

        // Goto to a page
        await page.goto('https://duckduckgo.com');

        // Sleep for 10 minutes
        await new Promise(resolve => {
            setTimeout(resolve, 6000000);
        })
    }
    catch (e) {
        console.log("Finished with error:", e);
    } finally {
        if (page != null) await page.close();
        if (browser != null) await browser.close();
        process.exit(0);
    }
})();
```

{% 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/features/session-inspection.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.
