import { chromium } from 'playwright'; const browser = await chromium.launch(); const out = {}; for (const [label, vp] of [['desktop', { width: 1280, height: 950 }], ['tablet', { width: 900, height: 800 }]]) { const ctx = await browser.newContext({ viewport: vp }); const page = await ctx.newPage(); await page.goto('http://localhost:5185/en/weather/week/berlin/', { waitUntil: 'load', timeout: 120000 }); await page.waitForTimeout(14000); await page.locator('canvas').first().scrollIntoViewIfNeeded(); await page.waitForTimeout(1500); out[label] = await page.evaluate(() => { const c = document.querySelector('.strip-cell').getBoundingClientRect(); const icon = document.querySelector('.strip-cell .day-icon').getBoundingClientRect(); const temps = document.querySelector('.strip-cell .temp-max').getBoundingClientRect(); const canvas = document.querySelector('canvas'); const cw = canvas ? canvas.getBoundingClientRect() : null; return { cell: { w: Math.round(c.width), h: Math.round(c.height) }, iconOffCentre: +(icon.top + icon.height / 2 - (c.top + c.height / 2)).toFixed(1), gapBelowTemps: +(c.bottom - temps.bottom).toFixed(1), canvasWidth: cw ? Math.round(cw.width) : null }; }); await page.screenshot({ path: `/tmp/tiles-${label}.png`, clip: { x: 0, y: 0, width: vp.width, height: 220 } }); await ctx.close(); } console.log(JSON.stringify(out, null, 1)); await browser.close();