-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepro.js
41 lines (35 loc) · 1.02 KB
/
repro.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
const { chromium } = require('playwright');
const crypto = require('crypto');
const fs = require('fs');
function createHash(data) {
return crypto.createHash('md5').update(data).digest('hex');
}
async function takeScreenshot(page, html) {
await page.setContent(html);
const element = await page.$('body *');
const pngBuf = await element.screenshot();
const hash = createHash(pngBuf);
fs.writeFileSync(`${hash}.png`, pngBuf);
return hash;
}
async function run() {
const browser = await chromium.launch();
const page = await browser.newPage();
const firstHash = await takeScreenshot(page, '<pre>Hello world</pre>');
const secondHash = await takeScreenshot(
page,
'<div style="height: 200vh; background: red;"></div>',
);
const thirdHash = await takeScreenshot(page, '<pre>Hello world</pre>');
console.log(`${firstHash}.png`);
console.log(`${thirdHash}.png`);
await browser.close();
}
run()
.then(() => {
process.exit(0);
})
.catch(e => {
console.error(e);
process.exit(1);
});