Updated on 26 June, 2026 · 1 min read
const { chromium } = require('playwright');
async function checkAssets(url) {
const browser = await chromium.launch();
const page = await browser.newPage();
const oversizedImages = [];
page.on('response', async (response) => {
const contentType = response.headers()['content-type'] || '';
if (contentType.includes('image')) {
const buffer = await response.body().catch(() => null);
if (buffer && buffer.length > 1_000_000) { // > 1MB
oversizedImages.push({ url: response.url(), size: buffer.length });
}
}
});
await page.goto(url, { waitUntil: 'networkidle' });
await browser.close();
return oversizedImages;
}