本文介绍了木偶无法关闭浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在express/node/ubuntu上运行puppeteer,如下所示:

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

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

/* GET home page. */
router.get('/', function(req, res, next) {
    (async () => {
        headless = true;
        const browser = await puppeteer.launch({headless: true, args:['--no-sandbox']});
        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();
    })();
});

多次运行此脚本会留下数百个僵尸:

running this script multiple times leaves hundred of Zombies:

$ pgrep chrome | wc -l
133

哪个会阻塞srv,

我该如何解决?

通过Express JS脚本运行 kill 可以解决此问题吗?

Running kill from a Express JS script could solve it?

除了木偶戏和无头的镀铬之外,还有没有更好的方法来获得相同的结果?

Is there a better way to get the same result other than puppeteer and headless chrome?

推荐答案

我用 https:/解决/www.npmjs.com/package/shelljs

var shell = require('shelljs');
shell.exec('pkill chrome')

这篇关于木偶无法关闭浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 05:26