-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
88 lines (81 loc) · 2.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import fs from "fs"
import puppeteer from "puppeteer-core"
import batches from "./avif-squoosh.config.js"
import { BROWSERS } from "./.profile,secret.js"
async function main(){
for (
let i = 1, // index 0 = meta, no tests
keyNames = Object.keys(batches),
curBatch = {};
i < keyNames.length;
++i
){
curBatch = batches[keyNames[i]]
captureMultiScreenshots(
curBatch,
batches.meta.destRootFolder + curBatch.folders.destSub,
)
}
}
main()
async function captureMultiScreenshots(batch, dest) {
console.log(`current batch`, batch);
const products = new Map([
['canary', 'chrome'],
['chrome', 'chrome'],
['edge', 'chrome'],
['firefox', 'firefox'],
['fxdev', 'firefox'],
])
for (
let b = 0;
b < batch.browsers.length;
++b
){
let browser = null;
let fileIdx = 0
const destFolder = (batch.folders.browser_folders===true)
? dest + batch.browsers[b] +'/'
: dest
try {
if (BROWSERS[batch.browsers[b]]===undefined){
throw new Error(`Can not find "${batch.browsers[b]}" config in ".profile,secret.js"`)
}
console.log(`Attempting to fill:`, destFolder);
fs.mkdirSync(destFolder,{recursive:true})
// launch headless browser
browser = await puppeteer.launch({
executablePath: BROWSERS[batch.browsers[b]],
extraPrefsFirefox: {
'image.avif.enabled': true,
},
headless: false,
product: products.get(batch.browsers[b]),
})
const page = await browser.newPage()
await page.setViewport({
width: batch.viewport.w,
height: batch.viewport.h,
})
for (
let file = '';
fileIdx < batch.files.length;
++fileIdx,
batch.files[fileIdx]
){
file = batch.files[fileIdx]
await page.goto(batch.folders.orig + file)
await page.screenshot({ path: destFolder + file +`.png` })
console.log(`✅ ${file}`);
}
} catch (err) {
console.error(`❌ Error: ${err.message}`);
} finally {
if (browser) {
await browser.close()
}
console.log(`${(batch.files.length===fileIdx)?'🎉 All':'😔 Some'}`, fileIdx, `screenshots in ${batch.browsers[b]} captured for
${destFolder}.`);
}
}//end for browsers loop
}