Node.js 当我与木偶师(集群)交互时,木偶师(集群)关闭页面
在NodeJS v10.x.x环境中,当尝试从一些HTML代码创建PDF页面时,每次尝试对其进行操作时,我都会遇到一个关闭页面问题(setCacheEnabled、setRequestInterception等): 我在某个地方读到,这个问题可能是由于一些等待缺失造成的,但这与我的情况不同 我没有直接使用Puppeter,但是这个库在它上面创建一个集群并处理进程: 我明白了 我确实忘记了对我发布的函数调用的等待 该调用位于我用于创建群集实例的另一个文件中:Node.js 当我与木偶师(集群)交互时,木偶师(集群)关闭页面,node.js,async-await,puppeteer,puppeteer-cluster,Node.js,Async Await,Puppeteer,Puppeteer Cluster,在NodeJS v10.x.x环境中,当尝试从一些HTML代码创建PDF页面时,每次尝试对其进行操作时,我都会遇到一个关闭页面问题(setCacheEnabled、setRequestInterception等): 我在某个地方读到,这个问题可能是由于一些等待缺失造成的,但这与我的情况不同 我没有直接使用Puppeter,但是这个库在它上面创建一个集群并处理进程: 我明白了 我确实忘记了对我发布的函数调用的等待 该调用位于我用于创建群集实例的另一个文件中: async function crea
async function createCluster() {
//We will protect our app with a Cluster that handles all the processes running in our headless browser
const cluster = await Cluster.launch({
concurrency: Cluster[config.cluster.concurrencyModel],
maxConcurrency: config.cluster.maxConcurrency
});
// Event handler to be called in case of problems
cluster.on('taskerror', (err, data) => {
console.log(`Error on cluster task... ${data}: ${err.message}`);
});
// Incoming task for the cluster to handle
await cluster.task(async ({ page, data }) => {
main.postController(page, data); // <-- I WAS MISSING A return await HERE
});
return cluster;
}
异步函数createCluster(){
//我们将使用一个集群来保护我们的应用程序,该集群处理在我们的无头浏览器中运行的所有进程
const cluster=等待cluster.launch({
并发性:集群[config.Cluster.concurrencyModel],
maxConcurrency:config.cluster.maxConcurrency
});
//发生问题时要调用的事件处理程序
cluster.on('taskerror',(err,data)=>{
log(`Error on cluster task…${data}:${err.message}`);
});
//群集要处理的传入任务
等待cluster.task(异步({page,data})=>{
main.postController(page,data);//您已经给出了解决方案,但由于这是库中的一个常见问题(我是作者,总是很高兴听到有人在使用库),我尝试在2分钟后关闭页面,但几秒钟后页面就关闭了。您能指导一下吗?要点如下:
async function createCluster() {
//We will protect our app with a Cluster that handles all the processes running in our headless browser
const cluster = await Cluster.launch({
concurrency: Cluster[config.cluster.concurrencyModel],
maxConcurrency: config.cluster.maxConcurrency
});
// Event handler to be called in case of problems
cluster.on('taskerror', (err, data) => {
console.log(`Error on cluster task... ${data}: ${err.message}`);
});
// Incoming task for the cluster to handle
await cluster.task(async ({ page, data }) => {
main.postController(page, data); // <-- I WAS MISSING A return await HERE
});
return cluster;
}