mirror of
https://github.com/vladocar/screenshoteer.git
synced 2024-12-22 05:32:21 +01:00
Call process exit when fails
This commit is contained in:
parent
7791bf3288
commit
a9e6c4a77c
1 changed files with 34 additions and 20 deletions
54
index.js
54
index.js
|
@ -29,25 +29,39 @@ console.log(urlvalue);
|
|||
console.log(fullPage);
|
||||
|
||||
(async () => {
|
||||
const browser = await puppeteer.launch()
|
||||
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})
|
||||
|
||||
try {
|
||||
await execute();
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}
|
||||
await page.emulateMedia('screen')
|
||||
if (program.pdf) await page.pdf({ path: t + " " + program.emulate + " " + d.getTime() + '.pdf' })
|
||||
console.log(t)
|
||||
await browser.close()
|
||||
|
||||
async function execute() {
|
||||
const browser = await puppeteer.launch()
|
||||
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()
|
||||
}
|
||||
|
||||
})()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue