I need to do some movements on page while page exists (or is opened). But other async code can close it in any time. I try to use code, like this:
async.whilst(
function(){ /*TEST function: return true if page is opened or false otherwise*/},
function (cb){
(async()=>{
await page.evaluate(_=>{/*some code*/})
})();
},
callbackopt
)
How can I know, if page is opened or closed, to pass this code to the test function?
You can use page.isClosed()
to detect whether a page is closed in Puppeteer:
if (page.isClosed()) {
// The page IS closed ...
} else {
// The page IS NOT closed ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With