Call process exit when fails

This commit is contained in:
Andrea D 2018-12-05 17:00:18 +01:00
parent 7791bf3288
commit a9e6c4a77c

View file

@ -29,25 +29,39 @@ console.log(urlvalue);
console.log(fullPage); console.log(fullPage);
(async () => { (async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage() try {
const d = new Date() await execute();
if (program.w && program.h) await page.setViewport({width: Number(program.w), height: Number(program.h)}) } catch(e) {
if (program.emulate) await page.emulate(devices[program.emulate]); console.error(e);
await page.goto(urlvalue) process.exit(1);
const title = await page.title()
const t = title.replace(/[/\\?%*:|"<>]/g, '-')
if (program.waitfor) await page.waitFor(Number(program.waitfor))
if (program.el) {
const el = await page.$(program.el);
await el.screenshot({
path: `${t} ${program.emulate} ${program.el} ${d.getTime()}.png`
});
} else {
await page.screenshot({path: t + " " + program.emulate + " " + d.getTime() + '.png', fullPage: fullPage})
} }
await page.emulateMedia('screen')
if (program.pdf) await page.pdf({ path: t + " " + program.emulate + " " + d.getTime() + '.pdf' }) async function execute() {
console.log(t) const browser = await puppeteer.launch()
await browser.close() const page = await browser.newPage()
const d = new Date()
if (program.w && program.h) await page.setViewport({width: Number(program.w), height: Number(program.h)})
if (program.emulate) await page.emulate(devices[program.emulate]);
await page.goto(urlvalue)
const title = await page.title()
const t = title.replace(/[/\\?%*:|"<>]/g, '-')
if (program.waitfor) await page.waitFor(Number(program.waitfor))
if (program.el) {
const el = await page.$(program.el);
await el.screenshot({
path: `${t} ${program.emulate} ${program.el} ${d.getTime()}.png`
});
} else {
await page.screenshot({path: t + " " + program.emulate + " " + d.getTime() + '.png', fullPage: fullPage})
}
await page.emulateMedia('screen')
if (program.pdf) await page.pdf({ path: t + " " + program.emulate + " " + d.getTime() + '.pdf' })
console.log(t)
await browser.close()
}
})() })()