puppeteer: [Bug]: Error: Attempted to use detached Frame 'xxx...xxx' after waking up from standby
Minimal, reproducible example
//import puppeteer from 'puppeteer';
const puppeteer = require('puppeteer');
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
(async () => {
// Launch the browser and open a new blank page
const browser = await puppeteer.launch({headless: false, devtools: true});
const page = await browser.newPage();
page.on('console', msg => console.log('PAGE LOG:', msg.text()));
// Set screen size
await page.setViewport({width: 1080, height: 1024});
while (true) {
try {
// Navigate the page to a URL
debugger;
await page.goto('https://developer.chrome.com/', {waitUntil: 'load', timeout: 40000});
}
catch (error) {
console.error(error);
}
console.log("done");
await wait(10000);
}
await browser.close();
})();
Error string
Error: Attempted to use detached Frame ‘6AC522DD7C67F215C5B95D650D0E708B’.
Bug behavior
- Flaky
Background
Procedure:
- Start the script, let the page load completely, and then switch the PC into standby.
- Wake up the PC.
- The script repeatedly tries to load the page, but the following error appears steadily:
Error: Attempted to use detached Frame '6AC522DD7C67F215C5B95D650D0E708B'.
This is also the case, after the network connection has been restored.
In earlier puppeteer versions, this worked without any problem.
Currently used software versions:
- puppeteer version 22.8.0
- Chromium version 120.0.6099.224 (Official Build) built on Debian 11.8, running on Debian 11.9 (64-bit)
- Debian 11.9 (64-bit)
Expectation
After standby the there should not show up an error, stating that the Frame is detached.
Reality
In reality, the frame is detached and unusable.
Puppeteer configuration file (if used)
No response
Puppeteer version
22.8.0
Node version
20.11.0
Package manager
npm
Package manager version
10.2.4
Operating system
Linux
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 3
- Comments: 17
the same problem with google chrome/103
As a workaround, use
pipe: truewhen launching the browser to avoid using sockets for communication. In general, it looks like standby/sleep might be severing network connections as expected (?) and CDP does not really support reconnection once the socket was closed.I am able to reproduce on a Mac using the sleep action. It looks like the websocket connection is disconnected (browser.connected === false when the error happens and also the disconnected event is emitted on the browser instance as expected). The disconnect comes from the web socket transport so I am not sure it is fixable, if the socket connection is severed the browser would destroy all automation agents so the only correct way is to re-connect Puppeteer again and set up everything again. You mentioned this worked before? Do you know which version was it?