import puppeteer from 'puppeteer'; import sharp from 'sharp'; 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)); await p.evaluate(()=>document.querySelector('#sec-shader').scrollIntoView()); await new Promise(r=>setTimeout(r,600)); async function probe(key){ if(key){ await p.click(`[data-shader-switch="${key}"]`); await new Promise(r=>setTimeout(r,900)); } // снимок canvas напрямую через toDataURL -> png const dataUrl = await p.evaluate(()=>{ const cv=document.querySelector('[data-shader-demo] canvas'); if(!cv) return null; try { return cv.toDataURL('image/png').slice(0,30); } catch(e){ return 'ERR '+e.message; } }); const buf = await p.evaluate(()=>{ const cv=document.querySelector('[data-shader-demo] canvas'); return cv ? cv.toDataURL('image/png') : null; }); let distinct=0, avg=[0,0,0]; if(buf){ const b64=buf.split(',')[1]; const {data,info}=await sharp(Buffer.from(b64,'base64')).raw().toBuffer({resolveWithObject:true}); let n=info.width*info.height,rs=0,gs=0,bs=0; const cols=new Set(); for(let i=0;i>5},${data[i+1]>>5},${data[i+2]>>5}`); } avg=[Math.round(rs/n),Math.round(gs/n),Math.round(bs/n)]; distinct=cols.size; } return { key:key||'mesh', dataUrlHead:dataUrl, avg, distinct }; } console.log(JSON.stringify(await probe(),null,0)); console.log(JSON.stringify(await probe('grain'),null,0)); console.log(JSON.stringify(await probe('voronoi'),null,0)); console.log(JSON.stringify(await probe('staticMesh'),null,0)); await b.close();