英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论