- This repo is a small Node + Playwright script that measures network weight for a user journey.
- The primary entry point is
src/index.jsand JS configs likeexample.com/journey.js.
- No tests are configured in this repository. Do not add test commands unless requested.
- No linting or formatting tools are configured. Follow existing style in the code.
npm install
node src/index.js example.com- Pass a folder name only;
journey.jsmust exist inside that folder.
- Reports are written inside the journey folder under
reports-<timestamp>/as JSON and CSV. - Output filenames include a run id derived from the journey name and timestamp.
- Two CSV files are produced:
<runId>.csv(human-friendly) andtechnical_<runId>.csv(full technical report). request_countis computed within a step window (start to end).window_duration_msreports that window length. Each row includespage_urlafter the step finishes.
- JavaScript only. No TypeScript in this repo.
- ESM is used via
.jsfiles;package.jsonistype: module. - Use Node built-ins with the
node:prefix (example:import fs from "node:fs").
- Group Node built-ins first, then third-party imports.
- Use named imports for external libs when appropriate (example:
{ chromium }from Playwright). - Keep import lists sorted by module type (built-ins, then third-party).
- 2-space indentation for JavaScript.
- Double quotes for strings.
- Semicolons at statement ends.
- Prefer trailing commas in multiline objects and arrays when already used nearby.
- Keep lines readable; wrap long expressions over multiple lines with consistent indentation.
camelCasefor variables and functions (autoScrollIfEnabled,computeStepMetrics).UPPER_SNAKE_CASEfor constants (KB).- Use descriptive names over abbreviations (
decompressedFallbackByRequestId).
- No explicit type system. Be explicit in runtime checks instead.
- Prefer
Number(...)or??defaults when reading config values. - Keep config-driven logic centralized; read all config once at startup.
- Use guard clauses for invalid inputs (
if (!url) return false). - Use
try/catchfor best-effort operations (e.g., response body reads). - Fail fast for unknown actions with clear error messages.
- Top-level errors should log and exit non-zero (
process.exit(1)).
- Use
async/awaitconsistently. - Small helper functions for repeated async steps (
settle,autoScrollIfEnabled). - Avoid unhandled promises;
awaitall critical async calls.
- Use
chromium.launch({ headless: true })unless a task requires otherwise. - Prefer
page.waitForLoadStatefor settling network activity. - Keep timeouts explicit and realistic for UI actions.
- Use CDP (
context.newCDPSession) only where needed for network metrics.
- Keep units explicit (bytes vs KB). Use helpers like
toKb. - Separate data collection from reporting.
- Keep report schema stable; add new fields in a backward-compatible way.
- Use
journey.jswith a default export object. - Keep config keys consistent (
name,startUrl,steps,settle,scroll,urls,actions). - If
stepsis empty or missing,urlsis used instead. urlscan be absolute or relative; relative entries requirestartUrl.- When using
urls, the runner tries a link click on matchinghref(absolute match first, then relative, with trailing slash tolerance). If no link is found, it falls back towindow.location.hrefand logs a warning. - Steps can define
actions(multi-action sequence). Ifactionsis present,actionis ignored.
- Place journey configs under a site-specific directory (example:
example.com/). - Reports are output to
/<folder>/reports-<timestamp>/. Do not commit generated reports unless requested.
- No build step is required.
- No linting tools are set up.
- No tests are configured; avoid adding test instructions.
- No
.cursor/rules/,.cursorrules, or.github/copilot-instructions.mdfiles are present.
- EcoIndex methodology: https://www.ecoindex.fr/comment-ca-marche/
- EcoIndex quantiles: https://raw.githubusercontent.com/cnumr/EcoIndex_python/main/components/ecoindex/data/quantiles.py
- EcoIndex grades: https://raw.githubusercontent.com/cnumr/EcoIndex_python/main/components/ecoindex/data/grades.py
- EcoIndex formula: https://raw.githubusercontent.com/cnumr/EcoIndex_python/main/components/ecoindex/compute/ecoindex.py
- GreenIT-Analysis: https://github.com/cnumr/GreenIT-Analysis
- GreenIT DOM count method: https://raw.githubusercontent.com/cnumr/GreenIT-Analysis/master/script/analyseFrame.js
npm install
node src/index.js example.com- Create a new folder per domain.
- Copy an existing
journey.jsand updatename,startUrl, andsteps. - Keep the same overall shape and keys unless you also update the script.
- Introducing a build system, linting, or test framework.
- Changing the report output schema.
- Adding or removing Playwright dependencies.