PlotDirector/PlotLine.Tests/Browser/solver-screenshot-performance.cjs

3 lines
1.3 KiB
JavaScript

const{chromium}=require('playwright'),fs=require('node:fs');
(async()=>{const b=await chromium.launch();const samples=[];try{for(const width of [390,1440])for(let run=0;run<3;run++){const c=await b.newContext({viewport:{width,height:1000}});const p=await c.newPage();await p.addInitScript(()=>{window.measured={lcp:0,cls:0};new PerformanceObserver(list=>{for(const e of list.getEntries())window.measured.lcp={ms:e.startTime,url:e.url,tag:e.element?.tagName};}).observe({type:'largest-contentful-paint',buffered:true});new PerformanceObserver(list=>{for(const e of list.getEntries())if(!e.hadRecentInput)window.measured.cls+=e.value;}).observe({type:'layout-shift',buffered:true});});await p.goto('https://dev.plotdirector.com/problem-solver/too-many-storylines-to-manage');await p.waitForLoadState('networkidle');await p.waitForTimeout(700);samples.push(await p.evaluate(({width,run})=>({width,run,...window.measured,images:performance.getEntriesByType('resource').filter(e=>e.initiatorType==='img').map(e=>({url:e.name,transfer:e.transferSize,encoded:e.encodedBodySize})),totalBytes:performance.getEntriesByType('resource').reduce((n,e)=>n+e.transferSize,0)}),{width,run}));await c.close();}fs.writeFileSync(process.argv[2],JSON.stringify(samples,null,2));console.log(JSON.stringify(samples));}finally{await b.close();}})().catch(e=>{console.error(e);process.exit(1)});