26 lines
1.3 KiB
JavaScript
26 lines
1.3 KiB
JavaScript
import { chromium } from 'playwright';
|
|
const browser = await chromium.launch();
|
|
const out = {};
|
|
for (const [label, vp, mobile] of [['mobile', { width: 390, height: 844 }, true], ['desktop', { width: 1280, height: 950 }, false]]) {
|
|
const ctx = await browser.newContext({ viewport: vp, isMobile: mobile, hasTouch: mobile });
|
|
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();
|
|
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)
|
|
};
|
|
});
|
|
await page.screenshot({ path: `/tmp/gap-${label}.png`, clip: { x: 0, y: 0, width: vp.width, height: 200 } });
|
|
await ctx.close();
|
|
}
|
|
console.log(JSON.stringify(out, null, 1));
|
|
await browser.close();
|