SPB Git

Repository Public

mesure-rendu.mjs 3.9 KB 78 lines javascript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : UQO Éval — Le Grand Défi Immobilier8 * File             : scripts/mesure-rendu.mjs9 * Module           : scripts10 * Repository       : https://git.spboucher.ai/uqo-eval-jeux11 * Project Website  : https://jeux.uqo-eval.app12 * Created          : 2026-11-2513 * Last Modified    : 2026-11-2514 *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          : None specified (no license file in this repository)34 *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// Mesure LCP et CLS réels dans Chromium (sans bridage réseau ni processeur) sur l'accueil et l'écran de jeu.44// Usage : node scripts/mesure-rendu.mjs [URL de base]45import { chromium, devices } from "@playwright/test";46const base = process.argv[2] ?? "https://jeux.uqo-eval.app";47const browser = await chromium.launch();48const observe = () => {49  window.__lcp = 0; window.__cls = 0;50  new PerformanceObserver((l) => { for (const e of l.getEntries()) window.__lcp = e.startTime; }).observe({ type: "largest-contentful-paint", buffered: true });51  new PerformanceObserver((l) => { for (const e of l.getEntries()) if (!e.hadRecentInput) window.__cls += e.value; }).observe({ type: "layout-shift", buffered: true });52};53for (const [label, options] of [["ordinateur", { viewport: { width: 1440, height: 900 } }], ["mobile", { ...devices["iPhone 14"] }]]) {54  const runs = { accueil: [], jeu: [] };55  for (let i = 0; i < 5; i++) {56    const context = await browser.newContext({ ...options, locale: "fr-CA" });57    const page = await context.newPage();58    await page.addInitScript(observe);59    await page.goto(base, { waitUntil: "load" });60    await page.waitForTimeout(3500);61    runs.accueil.push(await page.evaluate(() => ({ lcp: window.__lcp, cls: window.__cls, ttfb: performance.getEntriesByType("navigation")[0].responseStart })));62    if (i < 3) {63      await page.locator(".entry-alt").click();64      await page.waitForURL(/jouer/);65      const adresse = page.url();66      await page.goto(adresse, { waitUntil: "load" });67      await page.waitForTimeout(3500);68      runs.jeu.push(await page.evaluate(() => ({ lcp: window.__lcp, cls: window.__cls, ttfb: performance.getEntriesByType("navigation")[0].responseStart })));69    }70    await context.close();71  }72  const med = (xs) => xs.sort((a, b) => a - b)[Math.floor(xs.length / 2)];73  for (const [ecran, list] of Object.entries(runs)) {74    console.log(`${label} · ${ecran} (n=${list.length}) : LCP médian ${Math.round(med(list.map((r) => r.lcp)))} ms (max ${Math.round(Math.max(...list.map((r) => r.lcp)))}), CLS médian ${med(list.map((r) => r.cls)).toFixed(3)} (max ${Math.max(...list.map((r) => r.cls)).toFixed(3)}), TTFB médian ${Math.round(med(list.map((r) => r.ttfb)))} ms`);75  }76}77await browser.close();78
Files main
Menu

Theme