iwmlib/bin/singleshot.js
2019-05-31 13:57:43 +02:00

70 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 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)
}
)()