@coya/puppy
Advanced tools
Comparing version 0.0.2 to 0.1.0
15
index.js
@@ -11,2 +11,4 @@ const fs = require('fs'); | ||
let screenshotsFolder = ''; | ||
let proxy = null; | ||
let displayConsole = false; | ||
@@ -43,2 +45,7 @@ const browserOptions = { | ||
if(options.screenshotsFolder) screenshotsFolder = options.screenshotsFolder; | ||
if(options.proxy) { | ||
proxy = options.proxy; | ||
browserOptions.args.push('--proxy-server=' + proxy.url); | ||
} | ||
if(options.displayConsole) displayConsole = true; | ||
return await puppeteer.launch(Object.assign(browserOptions, options)); | ||
@@ -54,2 +61,3 @@ } | ||
if (cookiesFile) await loadCookies(page, cookiesFile); | ||
if (proxy && proxy.username && proxy.password) await page.authenticate(proxy); | ||
process.on('unhandledRejection', (error) => { | ||
@@ -59,5 +67,6 @@ logger.error(error); | ||
}); | ||
page.on('console', (msg) => { | ||
for (let i = 0; i < msg.args().length; ++i) logger.info(`${i}: ${msg.args()[i]}`); | ||
}); | ||
if(displayConsole) | ||
page.on('console', (msg) => { | ||
for (let i = 0; i < msg.args().length; ++i) logger.info(`${i}: ${msg.args()[i]}`); | ||
}); | ||
logger.debug('Page created.'); | ||
@@ -64,0 +73,0 @@ return page; |
{ | ||
"name": "@coya/puppy", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Utility methods for better handle of Puppeteer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
6325
198