Files

23 lines
1.5 KiB
JavaScript

import puppeteer from 'puppeteer';
import sharp from 'sharp';
import crypto from 'crypto';
const b = await puppeteer.launch({ args:['--no-sandbox','--disable-setuid-sandbox','--use-gl=angle','--enable-unsafe-swiftshader','--ignore-gpu-blocklist'] });
const p = await b.newPage();
await p.setViewport({width:1100,height:1300});
await p.goto('http://10.200.201.3:4175/_lab/neu-card.html',{waitUntil:'load',timeout:60000});
await new Promise(r=>setTimeout(r,1200));
const top = await p.evaluate(()=>{ const r=document.querySelector('[data-shader-demo]').getBoundingClientRect(); return r.top+window.scrollY; });
await p.evaluate((t)=>window.scrollTo(0, t-150), top);
await new Promise(r=>setTimeout(r,700));
async function hash(){ await p.screenshot({path:'/tmp/rl.png'});
const rect = await p.evaluate(()=>{ const r=document.querySelector('[data-shader-demo]').getBoundingClientRect(); return {x:r.x,y:r.y,w:r.width,h:r.height}; });
const {data,info}=await sharp('/tmp/rl.png').raw().toBuffer({resolveWithObject:true});
const x0=Math.floor(rect.x),y0=Math.floor(rect.y),x1=Math.floor(rect.x+rect.w),y1=Math.floor(rect.y+rect.h);
const buf=Buffer.alloc((x1-x0)*(y1-y0)*3);
let k=0; for(let y=y0;y<y1;y++) for(let x=x0;x<x1;x++){ const i=(y*info.width+x)*3; buf[k++]=data[i];buf[k++]=data[i+1];buf[k++]=data[i+2]; }
return crypto.createHash('md5').update(buf).digest('hex');
}
const a=await hash(); await new Promise(r=>setTimeout(r,3000)); const c=await hash();
console.log('hash1', a); console.log('hash2', c); console.log('ANIMATED:', a!==c);
await b.close();