Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : agentilab-web8 * File : scripts/capture-screens.mjs9 * Module : Scripts10 * Repository : https://git.spboucher.ai/agentilab-web11 * Project Website : Not specified12 * Created : 2026-12-0513 * Last Modified : 2026-12-0514 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : Proprietary34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// Captures de référence du site (pleine page) aux largeurs de la matrice QA.44// Usage : node scripts/capture-screens.mjs [baseUrl] [dossier] [--widths 390,1440] [--paths /,/en]45import { mkdir } from 'node:fs/promises';46import path from 'node:path';47import { chromium } from '@playwright/test';48import sharp from 'sharp';4950const args = process.argv.slice(2);51const opt = (name, fallback) => (args.includes(name) ? args[args.indexOf(name) + 1] : fallback);52const positional = args.filter((a, i) => !a.startsWith('--') && !args[i - 1]?.startsWith('--'));53const base = positional[0] ?? 'http://localhost:8190';54const out = positional[1] ?? 'docs/screenshots';55const widths = opt('--widths', '390,768,1440,1920').split(',').map(Number);56const paths = opt('--paths', '/,/entreprise,/ecosysteme,/ecosysteme/groupe-ka,/ecosysteme/orix,/technologies,/contact,/en').split(',');5758await mkdir(out, { recursive: true });59const browser = await chromium.launch();60for (const width of widths) {61 const context = await browser.newContext({ viewport: { width, height: width < 800 ? 844 : 900 }, deviceScaleFactor: 1, reducedMotion: 'reduce' });62 const page = await context.newPage();63 for (const p of paths) {64 await page.goto(base + p, { waitUntil: 'networkidle' });65 // Force le chargement des images différées avant la capture pleine page.66 await page.evaluate(async () => {67 for (const img of document.querySelectorAll('img[loading="lazy"]')) img.loading = 'eager';68 await Promise.all([...document.images].map((img) => (img.complete ? null : new Promise((r) => { img.onload = img.onerror = r; }))));69 });70 const name = (p === '/' ? 'accueil' : p.slice(1).replace(/\//g, '_')) + `-${width}.webp`;71 // WebP : des captures pleine page légères, pour rester raisonnable dans le dépôt.72 await sharp(await page.screenshot({ fullPage: true })).webp({ quality: 72 }).toFile(path.join(out, name));73 console.log(name);74 }75 await context.close();76}77await browser.close();78