How to use the same puppeteer-cluster task across different files?

312 views Asked by At

Saw plenty of examples of puppeteer-cluster and how to instantiate it/create tasks by reading the documentation in its GitHub page, yet I can't still figure out how to import the same instance of puppeteer-cluster across different files of my application, to take advantage of it

Can I import an unique puppeter-cluster instance and its tasks in other files of my application, and queue them from it?

1

There are 1 answers

0
Yusuf On

I did something like this

init-puppeteer-cluster.js

let cluster;
const init = async () => {
 cluster = await Cluster.launch(....)
 await cluster.task(....)
}
export {init,cluster}

In app.js init()

In other files cluster.queue(...)