Skip to content

Conversation

@Harsh-Git39
Copy link

@Harsh-Git39 Harsh-Git39 commented Jan 15, 2026

Makes users to calculate CO₂ emissions using a country-specific electricity grid mix via electricitymaps (through @tgwf/co2).

Implementation

Added sustainable.countryCode as a plugin CLI option.
Passed the value into the CO₂ model configuration when creating the co2 instance.
Updated the sustainable plugin documentation with a implementation example .

Testing and observations

I tested it with different country codes (IN, DE, NO). On very small pages (example.com) the difference is tiny due to rounding, but on larger pages like wikipedia.org the CO₂ values do change (for example, India ≈ 0.03730 vs Norway ≈ 0.03710), which shows the country-specific electricity mix is being used.
On lightweight pages (like example.com / wikipedia), the differences in CO₂ values are small, but they are consistently visible across runs, which suggests the country-specific electricity mix is being applied correctly. Heavier pages should make the differences more noticeable.

Thanks a lot for opportunity!!

@soulgalore
Copy link
Member

Hi @Harsh-Git39 ah cool, I'll have a look and test it this weekend!

@Harsh-Git39
Copy link
Author

Hi @soulgalore! I've fixed all the linting errors. The CRUX test is failing due to a missing API key in the CI configuration (--crux.key is empty), which appears to be unrelated to my changes. All other tests are passed . Could you please review?

@Harsh-Git39
Copy link
Author

Hi @soulgalore is this solution as expected or I'm happy to make further corrections if needed.

Copy link
Member

@soulgalore soulgalore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about also showing on the result page which country code that was used? That makes it easier to remember what you actually used.

I haven't tried the actual functionality on c02, so if I just switch between two different country codes I can verify that it works?

example:-
```bash
sitespeed.io https://example.com \
--plugins.add sustainable \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the rest of the documentation we use --sustainable.enable, I think we should use that here too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense I can update the result page to also show which countryCode was used, so it’s clear what configuration the CO₂ calculation is based on and for documentation I will make a update shortly.

super({ name: 'sustainable', options, context, queue });
}

static getCliOptions() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? I think the options for now could be moved to lib/cli/cli.js where the rest of the sustainable options is today, to keep it consistent.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works I have tested it locally switching between two different country codes shows different result in different CO2 values and I will move and test it on cli.js to ensure consistency and get back to you shorty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants