File size: 1,928 Bytes
d77bae9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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()