Puppeteer 浏览器在 Windows 休眠后失去连接。

huangapple go评论104阅读模式
英文:

Puppeteer browser loses connection after Windows sleep

问题

在Windows 10 64位系统中,我启动Chrome浏览器:

browser = await puppeteer.launch({ headless: false, ignoreHTTPSErrors: true, args: [`--window-size=500,750`], defaultViewport: null }); // viewport matches windows size
page = await browser.newPage();

这一切都很好,直到电脑休眠然后唤醒,此时浏览器不再工作,以下调用返回false:

await browser.isConnected(); // 返回false

浏览器和页面仍然可见,看起来正常,我可以按F5刷新页面。我该如何重新连接我的Puppeteer程序,以避免重新登录网站。值得一提的是,"await browser.close()" 成功关闭了浏览器窗口。
英文:

In windows 10 64 bit, I launch the Chrome browser:

browser = await puppeteer.launch({ headless: false, ignoreHTTPSErrors: true, args: [`--window-size=500,750`], defaultViewport: null }); // viewport matches windows size
page = await browser.newPage();

This is all fine until the PC sleeps and is then woken whereupon the browser no longer works and the following call returns false:

await browser.isConnected(); // returns false

The browser and page are still visibly there, look fine, and I can press F5 and the page refreshes. How do I reconnect my Puppeteer program to that I can avoid having to log back into the website. Worth saying that "await browser.close()" successfully closes the browser window.

答案1

得分: 1

你可以设置 pipe: true 来防止 WebSocket 断开连接。

设置 https://pptr.dev/api/puppeteer.launchoptions.pipe

英文:

You can set pipe: true to prevent websocket disconnected

set https://pptr.dev/api/puppeteer.launchoptions.pipe

huangapple
  • 本文由 发表于 2023年1月7日 22:00:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75040888.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定