Puppeteer doesn't close browser

后端 未结 6 2003
逝去的感伤
逝去的感伤 2021-02-13 20:15

I\'m running puppeteer on express/node/ubuntu as follow:

var puppeteer = require(\'puppeteer\');
var express = require(\'express\');
var router = express.Router(         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-13 20:43

    wrap your code in try-catch like this and see if it helps

    headless = true;
    const browser = await puppeteer.launch({headless: true, args:['--no-sandbox']});
    try {
      const page = await browser.newPage();
      url = req.query.url;
      await page.goto(url);
      let bodyHTML = await page.evaluate(() => document.body.innerHTML);
      res.send(bodyHTML);
      await browser.close();
    } catch (error) {
      console.log(error);
      await browser.close();
    } finally {
      await browser.close();
    }
    

提交回复
热议问题