Puppeteer doesn't close browser

后端 未结 6 1982
逝去的感伤
逝去的感伤 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:36

    try to close the browser before sending the response

    var puppeteer = require('puppeteer');
    var express = require('express');
    var router = express.Router();
    
    router.get('/', function(req, res, next) {
        (async () => {
            headless = true;
            const browser = await puppeteer.launch({headless: true});
            const page = await browser.newPage();
            url = req.query.url;
            await page.goto(url);
            let bodyHTML = await page.evaluate(() => document.body.innerHTML);
            await browser.close();
            res.send(bodyHTML);
        })();
    });
    

提交回复
热议问题