【问题标题】:How can I know if page is closed in Puppeteer我如何知道 Puppeteer 中的页面是否已关闭
【发布时间】:2018-03-07 13:29:23
【问题描述】:

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

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

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

【问题讨论】:

    标签: async.js puppeteer


    【解决方案1】:

    page.isClosed()

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

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

    【讨论】:

      猜你喜欢
      • 2012-03-07
      • 2011-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-21
      • 1970-01-01
      • 2014-03-03
      • 2015-03-28
      相关资源
      最近更新 更多