feature: use browser context to reduce cpu load on many files
chamabreu opened this issue ยท 3 comments
Problem:
If i start md2pdf
with a lot of md files, I get some warnings:
> md2pdf ../mds/**/*.md
(node:40269) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
(node:40269) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:40269) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:40269) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit
For each file a seperate pupeteer.launch()
function is called in generate-output.ts
.
This registers a lot of system listeners.
const browser = await puppeteer.launch({ devtools: config.devtools, ...config.launch_options });
Solution:
Use one single browser instance and create for each convertToPdf
just an browser context.
const listrContext = await browser.createIncognitoBrowserContext();
Pass this Context down the functions and use this, to create and manipulate the pages with puppeteer.
I just added this feature locally, but i can not push due to 403.
How can i push my Branch and open a PR for Review?
Hey thanks i've actually been wanting to do that for a while but never got around to it (i've personally never used it with multiple files
Just ended up merging this now, will do a release so you can test it more easily (: