mirror of
https://github.com/vladocar/screenshoteer.git
synced 2024-12-22 13:42:19 +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);
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue