From a250f6afc4f43a550f155ab3bd48569ee52f88f0 Mon Sep 17 00:00:00 2001 From: Harsh Date: Thu, 15 Jan 2026 18:07:03 +0000 Subject: [PATCH 1/2] added sustainable countrycode option for electricity-based CO2 calculations --- .../sitespeed.io/sustainable/index.md | 12 +++++++++++- lib/plugins/sustainable/index.js | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/documentation/sitespeed.io/sustainable/index.md b/docs/documentation/sitespeed.io/sustainable/index.md index 1dfcd85875..6f01341992 100644 --- a/docs/documentation/sitespeed.io/sustainable/index.md +++ b/docs/documentation/sitespeed.io/sustainable/index.md @@ -81,6 +81,16 @@ By default the hosting data (knowing if a host is green) is collected from a loc You can also disable the hosting match (all hosts will be treated as grey hosting) with `--sustainable.disableHosting`. +### Country-based electricity data + +You can optionally specify a country code to calculate carbon emissions using a specific electricity grid mix (via electricitymaps): +example:- +```bash +sitespeed.io https://example.com \ + --plugins.add sustainable \ + --sustainable.countryCode IN +``` + ## How it works ### Short version @@ -110,4 +120,4 @@ Larger data centres have historically been cited close to sources of cheap power For the rest of the internet, we use the [International Energy Agency's](https://hyp.is/MPRiUlTMEeq13bM-WjChjQ/www.iea.org/reports/global-energy-co2-status-report-2019/emissions) figure from of 475g of CO2 per kilowatt hour for for 2018, as an average across the globe. -Where we know power is generated using renewables we use the figure from the UK's regulator Ofgem, for renewables including solar, wind and hydroelectricity, of 33.4 grammes of CO2 per kilowatt hour. To tell how a site is powered, we look up the domain with the Green Web Foundation's - either via the their API, or when available, using their publicly available [url2green](https://www.thegreenwebfoundation.org/green-web-datasets/) dataset. +Where we know power is generated using renewables we use the figure from the UK's regulator Ofgem, for renewables including solar, wind and hydroelectricity, of 33.4 grammes of CO2 per kilowatt hour. To tell how a site is powered, we look up the domain with the Green Web Foundation's - either via the their API, or when available, using their publicly available [url2green](https://www.thegreenwebfoundation.org/green-web-datasets/) dataset. \ No newline at end of file diff --git a/lib/plugins/sustainable/index.js b/lib/plugins/sustainable/index.js index c8e8ae2b91..43ce6c3911 100644 --- a/lib/plugins/sustainable/index.js +++ b/lib/plugins/sustainable/index.js @@ -64,6 +64,17 @@ export default class SustainablePlugin extends SitespeedioPlugin { super({ name: 'sustainable', options, context, queue }); } + static getCliOptions() + { + return { + 'sustainable.countryCode' : + { + describe : "ISO driven country code used to calculate country specific carbon intensity via electricity-maps", + type : 'string' + } + }; + } + async open(context, options) { this.storageManager = context.storageManager; this.options = options; @@ -162,6 +173,10 @@ export default class SustainablePlugin extends SitespeedioPlugin { if (this.sustainableOptions.model === 'swd') { configuration.version = this.sustainableOptions.modelVersion; } + if(this.sustainableOptions.countryCode) + { + configuration.countryCode = this.sustainableOptions.countryCode; + } const CO2 = new co2(configuration); const co2PerDomain = perDomain(message.data, hostingGreenCheck, CO2); const baseDomain = message.data.baseDomain; @@ -290,4 +305,4 @@ export default class SustainablePlugin extends SitespeedioPlugin { } } } -} +} \ No newline at end of file From c2242521d2d7fb99e63266d08d4e4a96d1902c71 Mon Sep 17 00:00:00 2001 From: Harsh Date: Sat, 17 Jan 2026 18:11:20 +0000 Subject: [PATCH 2/2] Fix linting errors in sustainable plugin --- lib/plugins/sustainable/index.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/plugins/sustainable/index.js b/lib/plugins/sustainable/index.js index 43ce6c3911..177f34f2a5 100644 --- a/lib/plugins/sustainable/index.js +++ b/lib/plugins/sustainable/index.js @@ -64,13 +64,12 @@ export default class SustainablePlugin extends SitespeedioPlugin { super({ name: 'sustainable', options, context, queue }); } - static getCliOptions() - { + static getCliOptions() { return { - 'sustainable.countryCode' : - { - describe : "ISO driven country code used to calculate country specific carbon intensity via electricity-maps", - type : 'string' + 'sustainable.countryCode': { + describe: + 'ISO driven country code used to calculate country specific carbon intensity via electricity-maps', + type: 'string' } }; } @@ -173,8 +172,7 @@ export default class SustainablePlugin extends SitespeedioPlugin { if (this.sustainableOptions.model === 'swd') { configuration.version = this.sustainableOptions.modelVersion; } - if(this.sustainableOptions.countryCode) - { + if (this.sustainableOptions.countryCode) { configuration.countryCode = this.sustainableOptions.countryCode; } const CO2 = new co2(configuration); @@ -305,4 +303,4 @@ export default class SustainablePlugin extends SitespeedioPlugin { } } } -} \ No newline at end of file +}