小编Lij*_*ose的帖子

Puppeteer 阻塞事件循环

  • 傀儡师版本:1.1.0
  • 平台/操作系统版本:Ubuntu 16.04.6 LTS
  • Node.js 版本:v8.17.0
const express = require('express');
const blocked = require('blocked-at')
const app = express();
const PORT = 3000;
const URL = "https://www.huffingtonpost.in/entry/india-drops-10-spots-democracy-index_in_5e27ebc3c5b67d8874a92ab1"
let browser;

app.get('execute', async  (req, res) =>{
    page = await browser.newPage();
    await page.goto(URL, {
        waitUntil: 'networkidle0',
        timeout: 3000000
    })
});

app.listen(PORT, async () => {
    browser = await puppeteer.launch(CHROME_LAUNCHER_OPTIONS);
    return;
})

blocked((time, stack, {type, resource}) => {
 console.log(`Blocked for ${time}ms, operation started here:`, stack,"TYPE :",type)
}, {resourcesCap: 100})
Run Code Online (Sandbox Code Playgroud)

我们有一个快速服务器,它将创建一个浏览器实例。当请求进来时,我们正在创建和渲染页面以获取页面的内容。

预期的结果是什么?我希望并行处理请求

#!/bin/bash
curl --location …
Run Code Online (Sandbox Code Playgroud)

node.js puppeteer

5
推荐指数
1
解决办法
416
查看次数

标签 统计

node.js ×1

puppeteer ×1