会话检查
查看如何通过实时图形界面调试自动化会话。
什么时候使用它?
使用示例
const {chromium} = require('playwright');
(async () => {
let page = null;
let browser = null;
try {
// 使用 o_vnc=true 参数进行连接
browser = await chromium.connectOverCDP('wss://user:pass@ubc.oxylabs.io?o_vnc=true');
const ctx = browser.contexts()[0];
// 创建新页面
page = await ctx.newPage();
page.on('console', async msg => {
console.log(`BROWSER [${msg.type()}] ${msg.text()}`);
});
// 使用 CDP 会话获取会话 ID
let sesId = await (await ctx.newCDPSession(page)).send("__session_id");
// 使用 UB novnc 客户端或任何支持 WebSocket 的客户端连接到 vnc
console.log(`连接到 VNC: https://vnc.headlesify.io/novnc/?id=${sesId.value}`);
// 转到页面
await page.goto('https://duckduckgo.com');
// 休眠 10 分钟
await new Promise(resolve => {
setTimeout(resolve, 6000000);
});
}
catch (e) {
console.log("已完成,但出现错误:", e);
} finally {
if (page != null) await page.close();
if (browser != null) await browser.close();
process.exit(0);
}
})();这有帮助吗?

