gpt4 book ai didi

async.js - 我如何知道 Puppeteer 中的页面是否已关闭

转载 作者:行者123 更新时间:2023-12-04 15:02:07 25 4
gpt4 key购买 nike

当页面存在(或打开)时,我需要在页面上做一些 Action 。但是其他异步代码可以随时关闭它。
我尝试使用代码,如下所示:

async.whilst(
function(){ /*TEST function: return true if page is opened or false otherwise*/},
function (cb){
(async()=>{
await page.evaluate(_=>{/*some code*/})
})();
},
callbackopt
)

我怎么知道页面是打开还是关闭,将此代码传递给测试函数?

最佳答案

page.isClosed()
您可以使用 page.isClosed() 在 Puppeteer 中检测页面是否关闭:

if (page.isClosed()) {
// The page IS closed ...
} else {
// The page IS NOT closed ...
}

关于async.js - 我如何知道 Puppeteer 中的页面是否已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46424501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com