3 lines
1.6 KiB
JavaScript
3 lines
1.6 KiB
JavaScript
const{chromium}=require('playwright'),fs=require('node:fs');
|
|
(async()=>{const b=await chromium.launch(),samples=[];try{for(const path of ['/','/features','/writing-problems','/pricing','/writing-problems/timeline-doesnt-add-up'])for(const width of [390,1440])for(let run=0;run<2;run++){const c=await b.newContext({viewport:{width,height:1000},reducedMotion:'reduce'});const p=await c.newPage();await p.addInitScript(()=>{window.metrics={lcp:null,cls:0};new PerformanceObserver(l=>{for(const e of l.getEntries())window.metrics.lcp={ms:e.startTime,url:e.url,tag:e.element?.tagName};}).observe({type:'largest-contentful-paint',buffered:true});new PerformanceObserver(l=>{for(const e of l.getEntries())if(!e.hadRecentInput)window.metrics.cls+=e.value;}).observe({type:'layout-shift',buffered:true});});await p.goto('https://dev.plotdirector.com'+path);await p.waitForLoadState('networkidle');await p.waitForTimeout(400);samples.push(await p.evaluate(({path,width,run})=>({path,width,run,...window.metrics,images:performance.getEntriesByType('resource').filter(r=>/\.(avif|webp|png|jpe?g)(\?|$)/.test(r.name)).map(r=>({url:r.name,transfer:r.transferSize,encoded:r.encodedBodySize})),css:performance.getEntriesByType('resource').filter(r=>r.initiatorType==='link').map(r=>({url:r.name,ms:r.responseEnd-r.startTime})),totalBytes:performance.getEntriesByType('resource').reduce((n,r)=>n+r.transferSize,0)}),{path,width,run}));await c.close();}fs.writeFileSync(process.argv[2],JSON.stringify(samples,null,2));console.log('Recorded',samples.length,'live fresh-context measurements');}finally{await b.close();}})().catch(e=>{console.error(e);process.exit(1)});
|