Webdev-Bench / tasks /c07 /repo /scripts /capture.mjs
Roy-DOU's picture
Add files using upload-large-folder tool
d77bae9 verified
Raw History Blame Contribute Delete
1.93 kB
import { chromium } from 'playwright'
import fs from 'node:fs'
const url = process.env.APP_URL || 'http://localhost:5173/'
const out = process.env.OUT || '/workspace/repo/screenshots/full-page.png'
const browser = await chromium.launch()
const page = await browser.newPage({ viewport: { width: 1920, height: 1080 }, deviceScaleFactor: 1 })
await page.goto(url, { waitUntil: 'networkidle' })
await page.evaluate(() => document.fonts.ready)
await page.waitForTimeout(600)
const metrics = await page.evaluate(() => {
const y = (sel) => {
const el = document.querySelector(sel)
if (!el) return null
const r = el.getBoundingClientRect()
const s = window.scrollY
return { top: Math.round(r.top + s), left: Math.round(r.left), bottom: Math.round(r.bottom + s), width: Math.round(r.width), height: Math.round(r.height) }
}
return {
pageHeight: document.documentElement.scrollHeight,
brand: y('.brand'),
h1: y('.hero .display'),
heroLead: y('.hero .lead'),
grid: y('.projects-grid'),
firstRightCard: y('.col-right .card'),
firstLeftCard: y('.col-left .card'),
lastLeftCard: y('.col-left .card:last-child'),
clientsH2: y('.clients .display'),
clientsLead: y('.clients .lead'),
flare: y('.clients-flare'),
logowall: y('.logowall'),
manifestH2: y('.manifest .display'),
manifestLead: y('.manifest .lead'),
manifestCard: y('.manifest-card'),
arrowL: y('.carousel-arrow--left'),
arrowR: y('.carousel-arrow--right'),
ctaKicker: y('.cta-kicker'),
ctaTitle: y('.cta-title'),
ctaButton: y('.cta-button'),
footer: y('.footer-grid'),
nav: y('.floating-nav'),
nowPlaying: y('.now-playing'),
}
})
fs.writeFileSync('/workspace/tmp/metrics.json', JSON.stringify(metrics, null, 2))
console.log(JSON.stringify(metrics, null, 2))
await page.screenshot({ path: out, fullPage: true })
console.log('saved', out)
await browser.close()