lib/grover/js/processor.cjs in grover-1.1.4 vs lib/grover/js/processor.cjs in grover-1.1.5

- old
+ new

@@ -14,38 +14,49 @@ const os = require('os'); const path = require('path'); const _processPage = (async (convertAction, urlOrHtml, options) => { let browser, errors = [], tmpDir; - try { - tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'grover-')); - const launchParams = { - args: process.env.GROVER_NO_SANDBOX === 'true' ? ['--no-sandbox', '--disable-setuid-sandbox'] : [], - userDataDir: tmpDir - }; - + try { // Configure puppeteer debugging options const debug = options.debug; delete options.debug; - if (typeof debug === 'object' && !!debug) { - if (debug.headless !== undefined) { launchParams.headless = debug.headless; } - if (debug.devtools !== undefined) { launchParams.devtools = debug.devtools; } - } + const browserWsEndpoint = options.browserWsEndpoint; delete options.browserWsEndpoint; + if (typeof browserWsEndpoint === "string") { + const connectParams = { + browserWSEndpoint: browserWsEndpoint, + }; - // Configure additional launch arguments - const args = options.launchArgs; delete options.launchArgs; - if (Array.isArray(args)) { - launchParams.args = launchParams.args.concat(args); - } + browser = await puppeteer.connect(connectParams); + } else { + tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'grover-')); - // Set executable path if given - const executablePath = options.executablePath; delete options.executablePath; - if (executablePath) { - launchParams.executablePath = executablePath; + const launchParams = { + args: process.env.GROVER_NO_SANDBOX === 'true' ? ['--no-sandbox', '--disable-setuid-sandbox'] : [], + userDataDir: tmpDir + }; + + if (typeof debug === 'object' && !!debug) { + if (debug.headless !== undefined) { launchParams.headless = debug.headless; } + if (debug.devtools !== undefined) { launchParams.devtools = debug.devtools; } + } + + // Configure additional launch arguments + const args = options.launchArgs; delete options.launchArgs; + if (Array.isArray(args)) { + launchParams.args = launchParams.args.concat(args); + } + + // Set executable path if given + const executablePath = options.executablePath; delete options.executablePath; + if (executablePath) { + launchParams.executablePath = executablePath; + } + + // Launch the browser and create a page + browser = await puppeteer.launch(launchParams); } - // Launch the browser and create a page - browser = await puppeteer.launch(launchParams); const page = await browser.newPage(); // Basic auth const username = options.username; delete options.username const password = options.password; delete options.password