From e32067a418485f4cdf10aafb8ba9f6017eb2b8b3 Mon Sep 17 00:00:00 2001 From: Ernesto Ramos Date: Mon, 28 Nov 2022 18:25:08 -0500 Subject: [PATCH] using options instances instead of creating a new one everytim --- index.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 0f6f56b..160deca 100644 --- a/index.js +++ b/index.js @@ -4,20 +4,27 @@ const hb = require('handlebars') const inlineCss = require('inline-css') module.exports async function generatePdf(file, options, callback) { - // we are using headless mode - let args = [ - '--no-sandbox', - '--disable-setuid-sandbox', - ]; - if(options.args) { - args = options.args; - delete options.args; - } + + let browser = options.browser + let page = options.page; - const browser = await puppeteer.launch({ - args: args - }); - const page = await browser.newPage(); + if (!options.browser){ + // we are using headless mode + let args = [ + '--no-sandbox', + '--disable-setuid-sandbox', + ]; + if(options.args) { + args = options.args; + delete options.args; + } + browser = await puppeteer.launch({ + args: args + }); + } + + if (!options.page) + page = await browser.newPage(); if(file.content) { data = await inlineCss(file.content, {url:"/"});