ImpactTrace is a carbon estimation CLI for web application journeys in CI pipelines.
It executes browser journeys with Playwright, captures resource/network data, estimates energy usage and carbon impact, and provides developer-friendly optimization suggestions.
- Track carbon impact for critical user paths
- Compare first-time vs returning-visitor behavior with cache comparison mode
- Include browser CPU execution impact in total energy and carbon estimates
- Identify high-impact assets with contributor ranking
- Produce machine-readable JSON for CI/CD reporting and dashboards
- Journey-script mode (custom Playwright flow)
- URL mode (single URL or multiple URLs)
- Plugin-oriented architecture for extensibility
- Carbon modeling separated from measurement collection
- Rule-based developer insights:
- Large images (>200 KB)
- Large JavaScript bundles (>300 KB)
- Third-party resource detection
- Configurable CPU wattage model (env or repo config)
- Configurable CPU measurement window to capture ongoing activity like animations (default 3s)
- Optional CPU-off mode for network/asset-only reporting (
--no-cpu) - Configurable segment grid intensity overrides (device, network, data center)
npm install
npm run buildnpx impact-trace run --url https://example.comnpx impact-trace run --url https://example.comURL mode waits for networkidle by default. To override:
npx impact-trace run --url https://example.com --wait-until loadnpx impact-trace run --url https://example.com --url https://www.transformuk.comnpx impact-trace run --url https://www.transformuk.com --compare-cachenpx impact-trace run src/examples/basicJourney.ts --compare-cacheImpactTrace outputs:
- Human-readable console report
- JSON report file, only when
--output <file>is provided (not written by default)
Console report includes:
- Executive summary with Impact Score (A-F)
- Impact breakdown by category (video, images, JavaScript, fonts, third-party, other)
- Key findings prioritized by estimated reduction potential
- Potential savings summary
- Cache effectiveness summary (new vs returning visit)
- Budget pass/fail table
- CI summary suitable for pull request comments
Use --verbose to append model internals (SWDM matrix, assumptions, and model inputs).
In multi-URL mode, ImpactTrace also prints per-URL breakdowns and aggregate totals.
ImpactTrace resolves CPU wattage with this precedence:
- Environment variable
IMPACT_TRACE_CPU_WATTS - Repo config file
impact-trace.config.json(cpuWatts) - Built-in default (
20)
ImpactTrace resolves CPU measurement window with this precedence:
- CLI flag
--cpu-seconds - Environment variable
IMPACT_TRACE_CPU_MEASUREMENT_SECONDS - Repo config file
impact-trace.config.json(cpuMeasurementSeconds) - Built-in default (
3)
CPU is measured from journey start through at least the configured window, so short journeys still capture post-load activity such as animations.
ImpactTrace resolves CPU->Device factor with this precedence:
- CLI
--cpu-to-device-factor - Environment variable
IMPACT_TRACE_CPU_TO_DEVICE_ENERGY_FACTOR - Repo config file
impact-trace.config.json(cpuToDeviceEnergyFactor) - Blended profile factor from
cpuToDeviceEnergyProfileFactorsandcpuToDeviceUsageWeights
Default profile factors:
desktop=2.4laptop=1.8tablet=1.5mobile=1.3
Default usage weights:
desktop=0.35laptop=0.35tablet=0.10mobile=0.20
Default blended factor from these values is 1.88.
You can override profile factors and weights with env vars:
IMPACT_TRACE_CPU_TO_DEVICE_PROFILE_FACTORS(desktop:2.4,laptop:1.8,tablet:1.5,mobile:1.3)IMPACT_TRACE_CPU_TO_DEVICE_USAGE_WEIGHTS(desktop:0.35,laptop:0.35,tablet:0.1,mobile:0.2)
Or with CLI flags:
npx impact-trace run --url https://example.com \
--cpu-device-profile-factors desktop:2.4,laptop:1.8,tablet:1.5,mobile:1.3 \
--cpu-device-weights desktop:0.35,laptop:0.35,tablet:0.1,mobile:0.2Weights must sum to 1.
To disable CPU measurement entirely and use network transfer/asset size only:
npx impact-trace run --url https://example.com --no-cpuNetwork transfer carbon is estimated via @tgwf/co2 perByteTrace() segmented output and defaults to operational-only emissions. Embodied emissions and consumer-device transfer emissions are excluded from the network component.
JSON output includes:
-
Envelope fields:
formatVersion,generatedAt,raw,defaultView,ci,githubComment -
Optional
verboseViewwhen--verboseis enabled -
Resolved grid-intensity metadata at
modelInputs.resolvedGridIntensity -
User-device operational source metadata at
modelInputs.userDeviceOperationalSource -
SWDM segment/category totals at
swdmSegments(dataCenters/networks/userDevices, each with operational and embodied carbon + energy) -
In compare mode, SWDM totals are present in
comparison.firstVisit.swdmSegments,comparison.returningVisit.swdmSegments, andcomparison.delta.swdmSegments -
Backward-compatible transfer totals remain at
transferSegments -
Green hosting / visitor/cache model inputs at
modelInputs.*(including source metadata) -
CPU device factor blend metadata at
modelInputs.cpuToDevice* -
In compare mode, audience-weighted totals at
comparison.representativeVisit
Visitor/cache and hosting factors can be configured with this precedence:
- CLI flags (
--green-hosting-factor,--return-visitor-ratio,--data-cache-ratio) - Environment variables (
IMPACT_TRACE_GREEN_HOSTING_FACTOR,IMPACT_TRACE_RETURN_VISITOR_RATIO,IMPACT_TRACE_DATA_CACHE_RATIO) - Repo config file
impact-trace.config.json - Defaults (
greenHostingFactor=0,returnVisitorRatio=0.75)
newVisitorRatio is always derived as 1 - returnVisitorRatio.
In --compare-cache mode, dataCacheRatio is derived from first/returning network bytes when not explicitly provided.
Grid intensity for co2.js segments can be overridden with this precedence:
- CLI flags (
--grid-intensity-device,--grid-intensity-network,--grid-intensity-datacenter) - Environment variables (
IMPACT_TRACE_GRID_INTENSITY_*) - Repo config file
impact-trace.config.json(gridIntensity) - co2.js defaults
Segment override values support:
- Positive numbers
- Country objects (
{ "country": "TWN" }) in config - ISO3 country strings (
TWN) orcountry:TWNin CLI
Example:
{
"cpuWatts": 20,
"cpuMeasurementSeconds": 3,
"cpuToDeviceEnergyProfileFactors": {
"desktop": 2.4,
"laptop": 1.8,
"tablet": 1.5,
"mobile": 1.3
},
"cpuToDeviceUsageWeights": {
"desktop": 0.35,
"laptop": 0.35,
"tablet": 0.1,
"mobile": 0.2
},
"greenHostingFactor": 0.3,
"returnVisitorRatio": 0.75,
"dataCacheRatio": 0.8,
"gridIntensity": {
"device": 565.629,
"dataCenter": { "country": "TWN" },
"network": 442
},
"reporting": {
"budgets": {
"carbonGrams": 2,
"transferMb": 10,
"cpuSeconds": 1,
"thirdPartyMb": 1
},
"scoreThresholds": {
"A": 0.5,
"B": 1,
"C": 2,
"D": 5,
"E": 10
},
"output": {
"defaultFormat": "console",
"findingsLimit": 3,
"githubCommentMaxLines": 40
}
}
}Reporting output settings can also be configured via environment variables:
IMPACT_TRACE_REPORT_FORMAT(console|json|github-pr)IMPACT_TRACE_FINDINGS_LIMITIMPACT_TRACE_GITHUB_COMMENT_MAX_LINES
See full options reference in docs/cli-options.md.
See model overview and equations in docs/carbon-models.md.
Core structure:
- src/cli: argument parsing and report formatting
- src/core: runner and plugin orchestration
- src/plugins: measurement plugins (Playwright browser plugin)
- src/models: carbon and insights modeling
- src/types: shared types and report schema
The architecture is intentionally extensible for future additions such as:
- Docker/container CPU instrumentation
- Backend correlation headers
- Region-specific carbon intensity
- CI carbon budgets and failure thresholds
npm run build
npm run dev run src/examples/basicJourney.ts --compare-cachePlease read CONTRIBUTING.md before opening pull requests.
This project follows the Contributor Covenant. See CODE_OF_CONDUCT.md.
MIT. See LICENSE.