Reputation: 341
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?
Upvotes: 5
Views: 3779
Reputation: 29009
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 ...
}
Upvotes: 15