const { chromium, devices } = require('playwright'); const path = require('path'); const fs = require('fs'); const http = require('http'); function serveStatic(dir, port) { const server = http.createServer((req, res) => { let filePath = path.join(dir, req.url.split('?')[0]); if (filePath.endsWith('/') || !path.extname(filePath)) filePath = path.join(dir, 'index.html'); fs.readFile(filePath, (err, data) => { if (err) { res.writeHead(404); res.end('Not found'); return; } const ext = path.extname(filePath); const mimeTypes = { '.html': 'text/html; charset=utf-8', '.js': 'application/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.json': 'application/json', '.png': 'image/png', '.jpg': 'image/jpeg', '.svg': 'image/svg+xml', '.woff2': 'font/woff2' }; res.writeHead(200, { 'Content-Type': mimeTypes[ext] || 'application/octet-stream' }); res.end(data); }); }); return new Promise((resolve) => { server.listen(0, '127.0.0.1', () => { resolve({ server, port: server.address().port }); }); }); } async function testOsNegotiation() { const distDir = path.resolve('site/dist'); const { server, port } = await serveStatic(distDir); const url = `http://127.0.0.1:${port}`; console.log(`Static server running on ${url}`); const browser = await chromium.launch({ channel: 'chrome', headless: true }); const outDir = 'C:/Users/encep/.gemini/antigravity-cli/brain/3ab7ae82-5634-41d5-93a7-3c12c22503e2/screenshots/live_production_verified'; if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true }); // 1. Android Mobile Emulation (Pixel 7) console.log('--- Testing Android Device Emulation (Pixel 7) ---'); const androidContext = await browser.newContext({ ...devices['Pixel 7'], locale: 'ko-KR' }); const pageAndroid = await androidContext.newPage(); await pageAndroid.goto(url, { waitUntil: 'networkidle' }); await pageAndroid.waitForTimeout(1000); const androidBtn = await pageAndroid.evaluate(() => { const el = document.querySelector('a.glow-btn'); return el ? { text: el.innerText.trim(), href: el.href, download: el.getAttribute('download') } : null; }); console.log('Android CTA Button:', androidBtn); await pageAndroid.screenshot({ path: path.join(outDir, '19_hero_android_os_negotiated.png') }); // 2. iOS Mobile Emulation (iPhone 14) console.log('--- Testing iPhone Device Emulation (iPhone 14) ---'); const iosContext = await browser.newContext({ ...devices['iPhone 14'], locale: 'ko-KR' }); const pageIos = await iosContext.newPage(); await pageIos.goto(url, { waitUntil: 'networkidle' }); await pageIos.waitForTimeout(1000); const iosBtn = await pageIos.evaluate(() => { const el = document.querySelector('a.glow-btn'); return el ? { text: el.innerText.trim(), href: el.href } : null; }); console.log('iOS CTA Button:', iosBtn); await pageIos.screenshot({ path: path.join(outDir, '20_hero_ios_os_negotiated.png') }); // 3. Windows Desktop console.log('--- Testing Windows Desktop Emulation ---'); const winContext = await browser.newContext({ viewport: { width: 1440, height: 900 }, userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', locale: 'ko-KR' }); const pageWin = await winContext.newPage(); await pageWin.goto(url, { waitUntil: 'networkidle' }); await pageWin.waitForTimeout(1000); const winBtn = await pageWin.evaluate(() => { const el = document.querySelector('a.glow-btn'); return el ? { text: el.innerText.trim(), href: el.href, download: el.getAttribute('download') } : null; }); console.log('Windows CTA Button:', winBtn); await pageWin.screenshot({ path: path.join(outDir, '21_hero_windows_os_negotiated.png') }); await browser.close(); server.close(); console.log('=== ALL REAL OS NEGOTIATION TESTS PASSED ==='); } testOsNegotiation().catch(console.error);