Tumortisch-Dist/resources/app/node_modules/iwmlib/bin/singleshot.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-06-15 16:00:08 +02:00
/**
* test one single page, make a screenshot and log errors to
* console
* (c) 2019 - Leibniz-Insitut für Wissensmedien
*
*/
const puppeteer = require('puppeteer');
const fs = require("fs")
const path = require("path")
const start_dir = process.cwd()
// const start_file = path.join(start_dir,"lib","frames.html")
const start_file = path.join(start_dir,"lib","pixi","badge.html")
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const events = ["error","pageerror"]
function logPageEvent(event){
if(event !== undefined){
console.log(event.message)
}
}
async function makeScreenshot(href){
const browser = await puppeteer.launch({
// headless: false,
// loglevel : 0,
args : [
'allow-file-access-from-files',
],});
const page = await browser.newPage();
await page.setViewport({width: 1024,height : 624})
for (var i = 0; i < events.length; i++) {
page.on(events[i],logPageEvent)
}
page.once("load",logPageEvent)
// await Promise.all([ page.coverage.startJSCoverage() ]);
await page.goto(href)
// const jsCoverage = await Promise.all([ page.coverage.stopJSCoverage() ]);
const fname = path.parse(href).name
if (fname != "index"){
image_url = href.replace(fname + ".html" ,"thumbnails/" + fname + ".png")
}
else{
image_url = href.replace(fname + ".html" ,"thumbnail.png")
}
image_url = image_url.replace("file:///","")
console.log(image_url)
// console.log(jsCoverage)
page.removeAllListeners()
await page.screenshot({path: image_url});
await browser.close();
}
(async function(){
await makeScreenshot(start_file)
}
)()