Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 28, 2025

Copilot flagged that the resource filter logic doesn't explicitly handle query parameters when excluding resource-checker.js from page weight calculations. Since SustainabilityService.cs appends ?v={version} for cache busting, the filter should strip query parameters before checking.

Changes

Updated filter logic in getResources()

  • Changed from !url.includes('resource-checker.js') to !url.split('?')[0].endsWith('resource-checker.js')
  • Explicitly strips query parameters before filename check
  • More precise matching using endsWith() instead of includes()

Files modified

  • src/Client/src/resource-checker.js - source file
  • src/wwwroot/scripts/resource-checker.js - rebuilt bundle
// Before
return !url.includes('resource-checker.js');

// After
return !url.split('?')[0].endsWith('resource-checker.js');

The filter now explicitly handles URLs like:
/_content/XperienceCommunity.Sustainability/scripts/resource-checker.js?v=2.3.0

Addresses code quality issue flagged in PR #50.

Original prompt

This section details on the original issue you should resolve

<issue_title>The filter logic may not correctly exclude the resource-checker.js file</issue_title>
<issue_description>Copilot flagged an issue with the previous PR:

https://github.com/liamgold/xperience-community-sustainability/pull/50/files/4e114e08f332c3cf7d54141209fb882d428d6814#diff-f48f3a5d36b0f4e03eb34863e2c154d8bd1e6ffcfd4d4a78506d504f462c866d</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: liamgold <8261188+liamgold@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix filter logic to exclude resource-checker.js file Fix resource filter to handle query parameters in script URL Oct 28, 2025
Copilot AI requested a review from liamgold October 28, 2025 21:32
@liamgold liamgold marked this pull request as ready for review October 29, 2025 07:24
Copilot AI review requested due to automatic review settings October 29, 2025 07:24
@liamgold liamgold merged commit a0a612d into main Oct 29, 2025
15 checks passed
@liamgold liamgold deleted the copilot/fix-resource-checker-filter branch October 29, 2025 07:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the URL matching logic for filtering out the resource-checker.js script from resource calculations. The change prevents false positives when URLs contain "resource-checker.js" as a substring (e.g., in query parameters or path segments).

Key Changes

  • Updated URL filtering logic from substring matching (includes) to checking file name suffix (split('?')[0].endsWith)
  • Applied to both source file (src/Client/src/resource-checker.js) and minified distribution file (src/wwwroot/scripts/resource-checker.js)

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/Client/src/resource-checker.js Updated getResources() filter to use split('?')[0].endsWith() instead of includes() for more precise script exclusion
src/wwwroot/scripts/resource-checker.js Minified version of the same change, ensuring consistency between source and distribution

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -1 +1 @@
const e=1.465e-9/3;var t=class{constructor(t){this.options=t,this.KWH_PER_BYTE_FOR_NETWORK=e}perByte(t,n){return t<1?0:n?72e-12*t*0+t*e*475:5.603333333333333e-10*t*519}},n={data:{AFG:132.53,AFRICA:559.42,ALB:24.29,DZA:634.61,ASM:611.11,AGO:174.73,ATG:611.11,ARG:394.62,ARM:264.54,ABW:561.22,ASEAN:554.5,ASIA:591.19,AUS:570.35,AUT:110.81,AZE:671.39,BHS:660.1,BHR:904.62,BGD:678.11,BRB:605.51,BLR:441.74,BEL:138.11,BLZ:225.81,BEN:584.07,BTN:23.33,BOL:489.14,BIH:600,BWA:847.91,BRA:105.51,BRN:893.91,BGR:335.33,BFA:467.53,BDI:250,CPV:558.14,KHM:417.71,CMR:305.42,CAN:161.43,CYM:642.86,CAF:0,TCD:628.57,CHL:353.52,CHN:585.82,COL:214.88,COM:642.86,COG:700,COD:24.46,COK:250,CRI:26.46,CIV:393.89,HRV:204.96,CUB:637.61,CYP:534.32,CZE:449.72,DNK:151.65,DJI:692.31,DMA:529.41,DOM:580.78,ECU:150.69,EGY:570.13,SLV:116.54,GNQ:591.84,ERI:631.58,EST:416.67,SWZ:172.41,ETH:24.64,EU:243.83,EUROPE:327.69,FLK:500,FRO:404.76,FJI:288.46,FIN:79.16,FRA:56.04,GUF:217.82,PYF:442.86,G20:482.92,G7:361.52,GAB:491.6,GMB:666.67,GEO:167.02,DEU:380.95,GHA:484,GRC:336.57,GRL:178.57,GRD:640,GLP:500,GUM:622.86,GTM:328.27,GIN:236.84,GNB:625,GUY:640.35,HTI:567.31,HND:282.27,HKG:699.5,HUN:204.19,ISL:27.68,IND:705.13,IDN:675.93,IRN:665.15,IRQ:688.81,IRL:290.81,ISR:582.93,ITA:330.72,JAM:555.56,JPN:512.81,JOR:540.92,KAZ:830.41,KEN:83.33,KIR:666.67,XKX:894.65,KWT:649.2,KGZ:147.29,LAO:265.51,"LATIN AMERICA AND CARIBBEAN":260.28,LVA:123.2,LBN:599.01,LSO:20,LBR:227.85,LBY:818.69,LTU:160.07,LUX:105.26,MAC:448.98,MDG:436.44,MWI:66.67,MYS:605.83,MDV:611.77,MLI:408,MLT:459.14,MTQ:523.18,MRT:464.71,MUS:632.48,MEX:475.36,"MIDDLE EAST":660.46,MDA:648.5,MNG:771.8,MNE:417.07,MSR:1e3,MAR:662.64,MOZ:135.65,MMR:483.57,NAM:59.26,NRU:750,NPL:24.44,NLD:267.62,NCL:660.58,NZL:110.89,NIC:265.12,NER:670.89,NGA:516.23,"NORTH AMERICA":356.01,PRK:389.59,MKD:565.35,NOR:30.08,OCEANIA:507.63,OECD:360.53,OMN:564.69,PAK:463.66,PSE:516.13,PAN:161.68,PNG:507.25,PRY:24.31,PER:251.74,POL:661.93,PRT:165.55,PRI:678.74,QAT:602.59,REU:572.82,ROU:240.58,RUS:436.28,RWA:316.33,KNA:636.36,LCA:666.67,SPM:600,VCT:529.41,WSM:473.68,STP:642.86,SAU:706.79,SEN:511.6,SRB:636.06,SYC:564.52,SLE:50,SGP:474,SVK:116.77,SVN:231.28,SLB:700,SOM:578.95,ZAF:729.67,KOR:441.65,SSD:629.03,ESP:174.05,LKA:509.78,SDN:263.16,SUR:349.28,SWE:40.7,CHE:34.84,SYR:701.66,TWN:639.53,TJK:116.86,TZA:339.25,THA:560.74,PHL:601.1,TGO:443.18,TON:625,TTO:681.53,TUN:564.62,TUR:464.59,TKM:1306.03,TCA:653.85,UGA:44.53,UKR:259.69,ARE:561.14,GBR:237.59,USA:385.98,URY:112.65,UZB:1167.6,VUT:571.43,VEN:185.8,VNM:409.8,VGB:647.06,VIR:632.35,WORLD:485.99,YEM:566.1,ZMB:111.97,ZWE:297.87},type:"average"};const r=n.data.WORLD,o=e=>parseFloat(e.toFixed(2));function i(e){var t,o,i,a,s,l;if("object"!=typeof e)throw new Error("Options must be an object");const u={};if(null==e?void 0:e.gridIntensity){u.gridIntensity={};const{device:d,dataCenter:c,network:g}=e.gridIntensity;(d||0===d)&&("object"==typeof d?(n.data[null==(t=d.country)?void 0:t.toUpperCase()]||(console.warn(`"${d.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.device={value:r}),u.gridIntensity.device={country:d.country,value:parseFloat(n.data[null==(o=d.country)?void 0:o.toUpperCase()])}):"number"==typeof d?u.gridIntensity.device={value:d}:(u.gridIntensity.device={value:r},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof d}. \nFalling back to global average grid intensity.`))),(c||0===c)&&("object"==typeof c?(n.data[null==(i=c.country)?void 0:i.toUpperCase()]||(console.warn(`"${c.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.dataCenter={value:r}),u.gridIntensity.dataCenter={country:c.country,value:parseFloat(n.data[null==(a=c.country)?void 0:a.toUpperCase()])}):"number"==typeof c?u.gridIntensity.dataCenter={value:c}:(u.gridIntensity.dataCenter={value:r},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof c}. \nFalling back to global average grid intensity.`))),(g||0===g)&&("object"==typeof g?(n.data[null==(s=g.country)?void 0:s.toUpperCase()]||(console.warn(`"${g.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \nFalling back to global average grid intensity.`),u.gridIntensity.network={value:r}),u.gridIntensity.network={country:g.country,value:parseFloat(n.data[null==(l=g.country)?void 0:l.toUpperCase()])}):"number"==typeof g?u.gridIntensity.network={value:g}:(u.gridIntensity.network={value:r},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof g}. \nFalling back to global average grid intensity.`)))}return((null==e?void 0:e.dataReloadRatio)||0===e.dataReloadRatio)&&("number"==typeof e.dataReloadRatio?e.dataReloadRatio>=0&&e.dataReloadRatio<=1?u.dataReloadRatio=e.dataReloadRatio:(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${e.dataReloadRatio}. \nFalling back to default value.`)):(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof e.dataReloadRatio}. \nFalling back to default value.`))),((null==e?void 0:e.firstVisitPercentage)||0===e.firstVisitPercentage)&&("number"==typeof e.firstVisitPercentage?e.firstVisitPercentage>=0&&e.firstVisitPercentage<=1?u.firstVisitPercentage=e.firstVisitPercentage:(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${e.firstVisitPercentage}. \nFalling back to default value.`)):(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof e.firstVisitPercentage}. \nFalling back to default value.`))),((null==e?void 0:e.returnVisitPercentage)||0===e.returnVisitPercentage)&&("number"==typeof e.returnVisitPercentage?e.returnVisitPercentage>=0&&e.returnVisitPercentage<=1?u.returnVisitPercentage=e.returnVisitPercentage:(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${e.returnVisitPercentage}. \nFalling back to default value.`)):(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof e.returnVisitPercentage}. \nFalling back to default value.`))),u}function a(e=""){return{"User-Agent":`co2js/0.15.0 ${e}`}}var s,l,u=Object.defineProperty,d=Object.defineProperties,c=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,v=(e,t,n)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))y.call(t,n)&&v(e,n,t[n]);if(g)for(var n of g(t))p.call(t,n)&&v(e,n,t[n]);return e},b=(e,t)=>d(e,c(t)),m=class{constructor(e){this.options=e}energyPerByteByComponent(e){const t=e/1e9*.81;return{consumerDeviceEnergy:.52*t,networkEnergy:.14*t,productionEnergy:.19*t,dataCenterEnergy:.15*t}}co2byComponent(e,t=r,n={}){let o=r,i=r,a=r,s=r;if(null==n?void 0:n.gridIntensity){const{device:e,network:t,dataCenter:r}=n.gridIntensity;((null==e?void 0:e.value)||0===(null==e?void 0:e.value))&&(o=e.value),((null==t?void 0:t.value)||0===(null==t?void 0:t.value))&&(i=t.value),((null==r?void 0:r.value)||0===(null==r?void 0:r.value))&&(a=r.value)}!0===t&&(a=50);const l={};for(const[t,n]of Object.entries(e))t.startsWith("dataCenterEnergy")?l[t.replace("Energy","CO2")]=n*a:t.startsWith("consumerDeviceEnergy")?l[t.replace("Energy","CO2")]=n*o:t.startsWith("networkEnergy")?l[t.replace("Energy","CO2")]=n*i:l[t.replace("Energy","CO2")]=n*s;return l}perByte(e,t=!1,n=!1,r={}){e<1&&(e=0);const o=this.energyPerByteByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}perVisit(e,t=!1,n=!1,r={}){const o=this.energyPerVisitByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}energyPerByte(e){const t=this.energyPerByteByComponent(e);return Object.values(t).reduce(((e,t)=>e+t))}energyPerVisitByComponent(e,t={},n=.75,r=.25,o=.02){(t.dataReloadRatio||0===t.dataReloadRatio)&&(o=t.dataReloadRatio),(t.firstVisitPercentage||0===t.firstVisitPercentage)&&(n=t.firstVisitPercentage),(t.returnVisitPercentage||0===t.returnVisitPercentage)&&(r=t.returnVisitPercentage);const i=this.energyPerByteByComponent(e),a={};Object.values(i);for(const[e,t]of Object.entries(i))a[`${e} - first`]=t*n,a[`${e} - subsequent`]=t*r*o;return a}energyPerVisit(e){let t=0,n=0;const r=Object.entries(this.energyPerVisitByComponent(e));for(const[e,n]of r)e.indexOf("first")>0&&(t+=n);for(const[e,t]of r)e.indexOf("subsequent")>0&&(n+=t);return t+n}emissionsPerVisitInGrams(e,t=r){return o(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:o(.52*e),networkEnergy:o(.14*e),dataCenterEnergy:o(.15*e),productionEnergy:o(.19*e)}}},h=class{constructor(e){if(this.model=new m,"1byte"===(null==e?void 0:e.model))this.model=new t;else if("swd"===(null==e?void 0:e.model))this.model=new m;else if(null==e?void 0:e.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment="segment"===(null==e?void 0:e.results)}perByte(e,t=!1){return this.model.perByte(e,t,this._segment)}perVisit(e,t=!1){var n;if(null==(n=this.model)?void 0:n.perVisit)return this.model.perVisit(e,t,this._segment);throw new Error("The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}perByteTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y;let p={};return n&&(p=i(n)),{co2:this.model.perByte(e,t,this._segment,p),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(s=null==(a=null==(o=null==p?void 0:p.gridIntensity)?void 0:o.network)?void 0:a.value)?s:r,dataCenter:t?50:null!=(d=null==(u=null==(l=null==p?void 0:p.gridIntensity)?void 0:l.dataCenter)?void 0:u.value)?d:r,production:r,device:null!=(y=null==(g=null==(c=null==p?void 0:p.gridIntensity)?void 0:c.device)?void 0:g.value)?y:r}}}}perVisitTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y,p,v,f,b;if(null==(o=this.model)?void 0:o.perVisit){let o={};return n&&(o=i(n)),{co2:this.model.perVisit(e,t,this._segment,o),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(l=null==(s=null==(a=null==o?void 0:o.gridIntensity)?void 0:a.network)?void 0:s.value)?l:r,dataCenter:t?50:null!=(c=null==(d=null==(u=null==o?void 0:o.gridIntensity)?void 0:u.dataCenter)?void 0:d.value)?c:r,production:r,device:null!=(p=null==(y=null==(g=null==o?void 0:o.gridIntensity)?void 0:g.device)?void 0:y.value)?p:r},dataReloadRatio:null!=(v=null==o?void 0:o.dataReloadRatio)?v:.02,firstVisitPercentage:null!=(f=null==o?void 0:o.firstVisitPercentage)?f:.75,returnVisitPercentage:null!=(b=null==o?void 0:o.returnVisitPercentage)?b:.25}}}throw new Error("The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}},R=Object.getOwnPropertyNames;const w=(s={"src/hosting-json.js"(e,t){function n(e,t){return t.indexOf(e)>-1?e:{url:e,green:!1}}t.exports={check:async function(e,t){return"string"==typeof e?function(e,t){return t.indexOf(e)>-1}(e,t):function(e,t){let n=[];for(let r of e)t.indexOf(r)>-1&&n.push(r);return n}(e,t)},greenDomainsFromResults:function(e){return Object.entries(e).filter((([e,t])=>t.green)).map((([e,t])=>t.url))},find:function(e,t){return"string"==typeof e?n(e,t):function(e,t){const r={};for(let o of e)r[o]=n(o,t);return r}(e,t)}}}},function(){return l||(0,s[R(s)[0]])((l={exports:{}}).exports,l),l.exports})();var P=function(e,t){const n="string"==typeof t?{userAgentIdentifier:t}:t;if((null==n?void 0:n.db)&&n.verbose)throw new Error("verbose mode cannot be used with a local lookup database");return"string"==typeof e?async function(e,t={}){const n=await fetch(`https://api.thegreenwebfoundation.org/greencheck/${e}`,{headers:a(t.userAgentIdentifier)});if(null==t?void 0:t.db)return w.check(e,t.db);const r=await n.json();return t.verbose?r:r.green}(e,n):async function(e,t={}){try{const r="https://api.thegreenwebfoundation.org/v2/greencheckmulti",o=JSON.stringify(e),i=await fetch(`${r}/${o}`,{headers:a(t.userAgentIdentifier)}),s=await i.json();return t.verbose?s:(n=s,Object.entries(n).filter((([e,t])=>t.green)).map((([e,t])=>t.url)))}catch(e){return t.verbose?{}:[]}var n}(e,n)},C=function(e,t){return P(e,t)};async function O(){console.log("reportEmissions called"),await async function(){return window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"}),E(2e3)}(),await E(2e3),console.log("getting emissions data");const e=await async function(){console.log("calculating...");const e=window.performance.getEntriesByType("resource").filter((e=>!(e.name||"").includes("resource-checker.js"))),t=function(e){return e.reduce(((e,t)=>e+t.transferSize),0)}(e),n=await C(window.location.hostname),r=new h({model:"swd"}).perVisitTrace(t,n);return{pageWeight:t,carbonRating:(o=r.co2,o<.095?"A+":o<.186?"A":o<.341?"B":o<.493?"C":o<.656?"D":o<.846?"E":"F"),emissions:r,resources:e};var o}();console.log("received emissions data");const t=document.createElement("div");t.setAttribute("data-testid","sustainabilityData"),t.textContent=JSON.stringify(e),document.body.appendChild(t)}function E(e){return new Promise((t=>setTimeout(t,e)))}export{O as reportEmissions}; No newline at end of file
const e=1.465e-9/3;var t=class{constructor(t){this.options=t,this.KWH_PER_BYTE_FOR_NETWORK=e}perByte(t,n){return t<1?0:n?72e-12*t*0+t*e*475:5.603333333333333e-10*t*519}},n={data:{AFG:132.53,AFRICA:559.42,ALB:24.29,DZA:634.61,ASM:611.11,AGO:174.73,ATG:611.11,ARG:394.62,ARM:264.54,ABW:561.22,ASEAN:554.5,ASIA:591.19,AUS:570.35,AUT:110.81,AZE:671.39,BHS:660.1,BHR:904.62,BGD:678.11,BRB:605.51,BLR:441.74,BEL:138.11,BLZ:225.81,BEN:584.07,BTN:23.33,BOL:489.14,BIH:600,BWA:847.91,BRA:105.51,BRN:893.91,BGR:335.33,BFA:467.53,BDI:250,CPV:558.14,KHM:417.71,CMR:305.42,CAN:161.43,CYM:642.86,CAF:0,TCD:628.57,CHL:353.52,CHN:585.82,COL:214.88,COM:642.86,COG:700,COD:24.46,COK:250,CRI:26.46,CIV:393.89,HRV:204.96,CUB:637.61,CYP:534.32,CZE:449.72,DNK:151.65,DJI:692.31,DMA:529.41,DOM:580.78,ECU:150.69,EGY:570.13,SLV:116.54,GNQ:591.84,ERI:631.58,EST:416.67,SWZ:172.41,ETH:24.64,EU:243.83,EUROPE:327.69,FLK:500,FRO:404.76,FJI:288.46,FIN:79.16,FRA:56.04,GUF:217.82,PYF:442.86,G20:482.92,G7:361.52,GAB:491.6,GMB:666.67,GEO:167.02,DEU:380.95,GHA:484,GRC:336.57,GRL:178.57,GRD:640,GLP:500,GUM:622.86,GTM:328.27,GIN:236.84,GNB:625,GUY:640.35,HTI:567.31,HND:282.27,HKG:699.5,HUN:204.19,ISL:27.68,IND:705.13,IDN:675.93,IRN:665.15,IRQ:688.81,IRL:290.81,ISR:582.93,ITA:330.72,JAM:555.56,JPN:512.81,JOR:540.92,KAZ:830.41,KEN:83.33,KIR:666.67,XKX:894.65,KWT:649.2,KGZ:147.29,LAO:265.51,"LATIN AMERICA AND CARIBBEAN":260.28,LVA:123.2,LBN:599.01,LSO:20,LBR:227.85,LBY:818.69,LTU:160.07,LUX:105.26,MAC:448.98,MDG:436.44,MWI:66.67,MYS:605.83,MDV:611.77,MLI:408,MLT:459.14,MTQ:523.18,MRT:464.71,MUS:632.48,MEX:475.36,"MIDDLE EAST":660.46,MDA:648.5,MNG:771.8,MNE:417.07,MSR:1e3,MAR:662.64,MOZ:135.65,MMR:483.57,NAM:59.26,NRU:750,NPL:24.44,NLD:267.62,NCL:660.58,NZL:110.89,NIC:265.12,NER:670.89,NGA:516.23,"NORTH AMERICA":356.01,PRK:389.59,MKD:565.35,NOR:30.08,OCEANIA:507.63,OECD:360.53,OMN:564.69,PAK:463.66,PSE:516.13,PAN:161.68,PNG:507.25,PRY:24.31,PER:251.74,POL:661.93,PRT:165.55,PRI:678.74,QAT:602.59,REU:572.82,ROU:240.58,RUS:436.28,RWA:316.33,KNA:636.36,LCA:666.67,SPM:600,VCT:529.41,WSM:473.68,STP:642.86,SAU:706.79,SEN:511.6,SRB:636.06,SYC:564.52,SLE:50,SGP:474,SVK:116.77,SVN:231.28,SLB:700,SOM:578.95,ZAF:729.67,KOR:441.65,SSD:629.03,ESP:174.05,LKA:509.78,SDN:263.16,SUR:349.28,SWE:40.7,CHE:34.84,SYR:701.66,TWN:639.53,TJK:116.86,TZA:339.25,THA:560.74,PHL:601.1,TGO:443.18,TON:625,TTO:681.53,TUN:564.62,TUR:464.59,TKM:1306.03,TCA:653.85,UGA:44.53,UKR:259.69,ARE:561.14,GBR:237.59,USA:385.98,URY:112.65,UZB:1167.6,VUT:571.43,VEN:185.8,VNM:409.8,VGB:647.06,VIR:632.35,WORLD:485.99,YEM:566.1,ZMB:111.97,ZWE:297.87},type:"average"};const r=n.data.WORLD,o=e=>parseFloat(e.toFixed(2));function i(e){var t,o,i,a,s,l;if("object"!=typeof e)throw new Error("Options must be an object");const u={};if(null==e?void 0:e.gridIntensity){u.gridIntensity={};const{device:d,dataCenter:c,network:g}=e.gridIntensity;(d||0===d)&&("object"==typeof d?(n.data[null==(t=d.country)?void 0:t.toUpperCase()]||(console.warn(`"${d.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.device={value:r}),u.gridIntensity.device={country:d.country,value:parseFloat(n.data[null==(o=d.country)?void 0:o.toUpperCase()])}):"number"==typeof d?u.gridIntensity.device={value:d}:(u.gridIntensity.device={value:r},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof d}. \nFalling back to global average grid intensity.`))),(c||0===c)&&("object"==typeof c?(n.data[null==(i=c.country)?void 0:i.toUpperCase()]||(console.warn(`"${c.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.dataCenter={value:r}),u.gridIntensity.dataCenter={country:c.country,value:parseFloat(n.data[null==(a=c.country)?void 0:a.toUpperCase()])}):"number"==typeof c?u.gridIntensity.dataCenter={value:c}:(u.gridIntensity.dataCenter={value:r},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof c}. \nFalling back to global average grid intensity.`))),(g||0===g)&&("object"==typeof g?(n.data[null==(s=g.country)?void 0:s.toUpperCase()]||(console.warn(`"${g.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \nFalling back to global average grid intensity.`),u.gridIntensity.network={value:r}),u.gridIntensity.network={country:g.country,value:parseFloat(n.data[null==(l=g.country)?void 0:l.toUpperCase()])}):"number"==typeof g?u.gridIntensity.network={value:g}:(u.gridIntensity.network={value:r},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof g}. \nFalling back to global average grid intensity.`)))}return((null==e?void 0:e.dataReloadRatio)||0===e.dataReloadRatio)&&("number"==typeof e.dataReloadRatio?e.dataReloadRatio>=0&&e.dataReloadRatio<=1?u.dataReloadRatio=e.dataReloadRatio:(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${e.dataReloadRatio}. \nFalling back to default value.`)):(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof e.dataReloadRatio}. \nFalling back to default value.`))),((null==e?void 0:e.firstVisitPercentage)||0===e.firstVisitPercentage)&&("number"==typeof e.firstVisitPercentage?e.firstVisitPercentage>=0&&e.firstVisitPercentage<=1?u.firstVisitPercentage=e.firstVisitPercentage:(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${e.firstVisitPercentage}. \nFalling back to default value.`)):(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof e.firstVisitPercentage}. \nFalling back to default value.`))),((null==e?void 0:e.returnVisitPercentage)||0===e.returnVisitPercentage)&&("number"==typeof e.returnVisitPercentage?e.returnVisitPercentage>=0&&e.returnVisitPercentage<=1?u.returnVisitPercentage=e.returnVisitPercentage:(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${e.returnVisitPercentage}. \nFalling back to default value.`)):(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof e.returnVisitPercentage}. \nFalling back to default value.`))),u}function a(e=""){return{"User-Agent":`co2js/0.15.0 ${e}`}}var s,l,u=Object.defineProperty,d=Object.defineProperties,c=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,v=(e,t,n)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))y.call(t,n)&&v(e,n,t[n]);if(g)for(var n of g(t))p.call(t,n)&&v(e,n,t[n]);return e},b=(e,t)=>d(e,c(t)),m=class{constructor(e){this.options=e}energyPerByteByComponent(e){const t=e/1e9*.81;return{consumerDeviceEnergy:.52*t,networkEnergy:.14*t,productionEnergy:.19*t,dataCenterEnergy:.15*t}}co2byComponent(e,t=r,n={}){let o=r,i=r,a=r,s=r;if(null==n?void 0:n.gridIntensity){const{device:e,network:t,dataCenter:r}=n.gridIntensity;((null==e?void 0:e.value)||0===(null==e?void 0:e.value))&&(o=e.value),((null==t?void 0:t.value)||0===(null==t?void 0:t.value))&&(i=t.value),((null==r?void 0:r.value)||0===(null==r?void 0:r.value))&&(a=r.value)}!0===t&&(a=50);const l={};for(const[t,n]of Object.entries(e))t.startsWith("dataCenterEnergy")?l[t.replace("Energy","CO2")]=n*a:t.startsWith("consumerDeviceEnergy")?l[t.replace("Energy","CO2")]=n*o:t.startsWith("networkEnergy")?l[t.replace("Energy","CO2")]=n*i:l[t.replace("Energy","CO2")]=n*s;return l}perByte(e,t=!1,n=!1,r={}){e<1&&(e=0);const o=this.energyPerByteByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}perVisit(e,t=!1,n=!1,r={}){const o=this.energyPerVisitByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}energyPerByte(e){const t=this.energyPerByteByComponent(e);return Object.values(t).reduce(((e,t)=>e+t))}energyPerVisitByComponent(e,t={},n=.75,r=.25,o=.02){(t.dataReloadRatio||0===t.dataReloadRatio)&&(o=t.dataReloadRatio),(t.firstVisitPercentage||0===t.firstVisitPercentage)&&(n=t.firstVisitPercentage),(t.returnVisitPercentage||0===t.returnVisitPercentage)&&(r=t.returnVisitPercentage);const i=this.energyPerByteByComponent(e),a={};Object.values(i);for(const[e,t]of Object.entries(i))a[`${e} - first`]=t*n,a[`${e} - subsequent`]=t*r*o;return a}energyPerVisit(e){let t=0,n=0;const r=Object.entries(this.energyPerVisitByComponent(e));for(const[e,n]of r)e.indexOf("first")>0&&(t+=n);for(const[e,t]of r)e.indexOf("subsequent")>0&&(n+=t);return t+n}emissionsPerVisitInGrams(e,t=r){return o(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:o(.52*e),networkEnergy:o(.14*e),dataCenterEnergy:o(.15*e),productionEnergy:o(.19*e)}}},h=class{constructor(e){if(this.model=new m,"1byte"===(null==e?void 0:e.model))this.model=new t;else if("swd"===(null==e?void 0:e.model))this.model=new m;else if(null==e?void 0:e.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment="segment"===(null==e?void 0:e.results)}perByte(e,t=!1){return this.model.perByte(e,t,this._segment)}perVisit(e,t=!1){var n;if(null==(n=this.model)?void 0:n.perVisit)return this.model.perVisit(e,t,this._segment);throw new Error("The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}perByteTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y;let p={};return n&&(p=i(n)),{co2:this.model.perByte(e,t,this._segment,p),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(s=null==(a=null==(o=null==p?void 0:p.gridIntensity)?void 0:o.network)?void 0:a.value)?s:r,dataCenter:t?50:null!=(d=null==(u=null==(l=null==p?void 0:p.gridIntensity)?void 0:l.dataCenter)?void 0:u.value)?d:r,production:r,device:null!=(y=null==(g=null==(c=null==p?void 0:p.gridIntensity)?void 0:c.device)?void 0:g.value)?y:r}}}}perVisitTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y,p,v,f,b;if(null==(o=this.model)?void 0:o.perVisit){let o={};return n&&(o=i(n)),{co2:this.model.perVisit(e,t,this._segment,o),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(l=null==(s=null==(a=null==o?void 0:o.gridIntensity)?void 0:a.network)?void 0:s.value)?l:r,dataCenter:t?50:null!=(c=null==(d=null==(u=null==o?void 0:o.gridIntensity)?void 0:u.dataCenter)?void 0:d.value)?c:r,production:r,device:null!=(p=null==(y=null==(g=null==o?void 0:o.gridIntensity)?void 0:g.device)?void 0:y.value)?p:r},dataReloadRatio:null!=(v=null==o?void 0:o.dataReloadRatio)?v:.02,firstVisitPercentage:null!=(f=null==o?void 0:o.firstVisitPercentage)?f:.75,returnVisitPercentage:null!=(b=null==o?void 0:o.returnVisitPercentage)?b:.25}}}throw new Error("The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}},R=Object.getOwnPropertyNames;const w=(s={"src/hosting-json.js"(e,t){function n(e,t){return t.indexOf(e)>-1?e:{url:e,green:!1}}t.exports={check:async function(e,t){return"string"==typeof e?function(e,t){return t.indexOf(e)>-1}(e,t):function(e,t){let n=[];for(let r of e)t.indexOf(r)>-1&&n.push(r);return n}(e,t)},greenDomainsFromResults:function(e){return Object.entries(e).filter((([e,t])=>t.green)).map((([e,t])=>t.url))},find:function(e,t){return"string"==typeof e?n(e,t):function(e,t){const r={};for(let o of e)r[o]=n(o,t);return r}(e,t)}}}},function(){return l||(0,s[R(s)[0]])((l={exports:{}}).exports,l),l.exports})();var P=function(e,t){const n="string"==typeof t?{userAgentIdentifier:t}:t;if((null==n?void 0:n.db)&&n.verbose)throw new Error("verbose mode cannot be used with a local lookup database");return"string"==typeof e?async function(e,t={}){const n=await fetch(`https://api.thegreenwebfoundation.org/greencheck/${e}`,{headers:a(t.userAgentIdentifier)});if(null==t?void 0:t.db)return w.check(e,t.db);const r=await n.json();return t.verbose?r:r.green}(e,n):async function(e,t={}){try{const r="https://api.thegreenwebfoundation.org/v2/greencheckmulti",o=JSON.stringify(e),i=await fetch(`${r}/${o}`,{headers:a(t.userAgentIdentifier)}),s=await i.json();return t.verbose?s:(n=s,Object.entries(n).filter((([e,t])=>t.green)).map((([e,t])=>t.url)))}catch(e){return t.verbose?{}:[]}var n}(e,n)},C=function(e,t){return P(e,t)};async function O(){console.log("reportEmissions called"),await async function(){return window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"}),E(2e3)}(),await E(2e3),console.log("getting emissions data");const e=await async function(){console.log("calculating...");const e=window.performance.getEntriesByType("resource").filter((e=>!(e.name||"").split("?")[0].endsWith("resource-checker.js"))),t=function(e){return e.reduce(((e,t)=>e+t.transferSize),0)}(e),n=await C(window.location.hostname),r=new h({model:"swd"}).perVisitTrace(t,n);return{pageWeight:t,carbonRating:(o=r.co2,o<.095?"A+":o<.186?"A":o<.341?"B":o<.493?"C":o<.656?"D":o<.846?"E":"F"),emissions:r,resources:e};var o}();console.log("received emissions data");const t=document.createElement("div");t.setAttribute("data-testid","sustainabilityData"),t.textContent=JSON.stringify(e),document.body.appendChild(t)}function E(e){return new Promise((t=>setTimeout(t,e)))}export{O as reportEmissions}; No newline at end of file
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

Variable 'n' is used before its declaration.

Suggested change
const e=1.465e-9/3;var t=class{constructor(t){this.options=t,this.KWH_PER_BYTE_FOR_NETWORK=e}perByte(t,n){return t<1?0:n?72e-12*t*0+t*e*475:5.603333333333333e-10*t*519}},n={data:{AFG:132.53,AFRICA:559.42,ALB:24.29,DZA:634.61,ASM:611.11,AGO:174.73,ATG:611.11,ARG:394.62,ARM:264.54,ABW:561.22,ASEAN:554.5,ASIA:591.19,AUS:570.35,AUT:110.81,AZE:671.39,BHS:660.1,BHR:904.62,BGD:678.11,BRB:605.51,BLR:441.74,BEL:138.11,BLZ:225.81,BEN:584.07,BTN:23.33,BOL:489.14,BIH:600,BWA:847.91,BRA:105.51,BRN:893.91,BGR:335.33,BFA:467.53,BDI:250,CPV:558.14,KHM:417.71,CMR:305.42,CAN:161.43,CYM:642.86,CAF:0,TCD:628.57,CHL:353.52,CHN:585.82,COL:214.88,COM:642.86,COG:700,COD:24.46,COK:250,CRI:26.46,CIV:393.89,HRV:204.96,CUB:637.61,CYP:534.32,CZE:449.72,DNK:151.65,DJI:692.31,DMA:529.41,DOM:580.78,ECU:150.69,EGY:570.13,SLV:116.54,GNQ:591.84,ERI:631.58,EST:416.67,SWZ:172.41,ETH:24.64,EU:243.83,EUROPE:327.69,FLK:500,FRO:404.76,FJI:288.46,FIN:79.16,FRA:56.04,GUF:217.82,PYF:442.86,G20:482.92,G7:361.52,GAB:491.6,GMB:666.67,GEO:167.02,DEU:380.95,GHA:484,GRC:336.57,GRL:178.57,GRD:640,GLP:500,GUM:622.86,GTM:328.27,GIN:236.84,GNB:625,GUY:640.35,HTI:567.31,HND:282.27,HKG:699.5,HUN:204.19,ISL:27.68,IND:705.13,IDN:675.93,IRN:665.15,IRQ:688.81,IRL:290.81,ISR:582.93,ITA:330.72,JAM:555.56,JPN:512.81,JOR:540.92,KAZ:830.41,KEN:83.33,KIR:666.67,XKX:894.65,KWT:649.2,KGZ:147.29,LAO:265.51,"LATIN AMERICA AND CARIBBEAN":260.28,LVA:123.2,LBN:599.01,LSO:20,LBR:227.85,LBY:818.69,LTU:160.07,LUX:105.26,MAC:448.98,MDG:436.44,MWI:66.67,MYS:605.83,MDV:611.77,MLI:408,MLT:459.14,MTQ:523.18,MRT:464.71,MUS:632.48,MEX:475.36,"MIDDLE EAST":660.46,MDA:648.5,MNG:771.8,MNE:417.07,MSR:1e3,MAR:662.64,MOZ:135.65,MMR:483.57,NAM:59.26,NRU:750,NPL:24.44,NLD:267.62,NCL:660.58,NZL:110.89,NIC:265.12,NER:670.89,NGA:516.23,"NORTH AMERICA":356.01,PRK:389.59,MKD:565.35,NOR:30.08,OCEANIA:507.63,OECD:360.53,OMN:564.69,PAK:463.66,PSE:516.13,PAN:161.68,PNG:507.25,PRY:24.31,PER:251.74,POL:661.93,PRT:165.55,PRI:678.74,QAT:602.59,REU:572.82,ROU:240.58,RUS:436.28,RWA:316.33,KNA:636.36,LCA:666.67,SPM:600,VCT:529.41,WSM:473.68,STP:642.86,SAU:706.79,SEN:511.6,SRB:636.06,SYC:564.52,SLE:50,SGP:474,SVK:116.77,SVN:231.28,SLB:700,SOM:578.95,ZAF:729.67,KOR:441.65,SSD:629.03,ESP:174.05,LKA:509.78,SDN:263.16,SUR:349.28,SWE:40.7,CHE:34.84,SYR:701.66,TWN:639.53,TJK:116.86,TZA:339.25,THA:560.74,PHL:601.1,TGO:443.18,TON:625,TTO:681.53,TUN:564.62,TUR:464.59,TKM:1306.03,TCA:653.85,UGA:44.53,UKR:259.69,ARE:561.14,GBR:237.59,USA:385.98,URY:112.65,UZB:1167.6,VUT:571.43,VEN:185.8,VNM:409.8,VGB:647.06,VIR:632.35,WORLD:485.99,YEM:566.1,ZMB:111.97,ZWE:297.87},type:"average"};const r=n.data.WORLD,o=e=>parseFloat(e.toFixed(2));function i(e){var t,o,i,a,s,l;if("object"!=typeof e)throw new Error("Options must be an object");const u={};if(null==e?void 0:e.gridIntensity){u.gridIntensity={};const{device:d,dataCenter:c,network:g}=e.gridIntensity;(d||0===d)&&("object"==typeof d?(n.data[null==(t=d.country)?void 0:t.toUpperCase()]||(console.warn(`"${d.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.device={value:r}),u.gridIntensity.device={country:d.country,value:parseFloat(n.data[null==(o=d.country)?void 0:o.toUpperCase()])}):"number"==typeof d?u.gridIntensity.device={value:d}:(u.gridIntensity.device={value:r},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof d}. \nFalling back to global average grid intensity.`))),(c||0===c)&&("object"==typeof c?(n.data[null==(i=c.country)?void 0:i.toUpperCase()]||(console.warn(`"${c.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.dataCenter={value:r}),u.gridIntensity.dataCenter={country:c.country,value:parseFloat(n.data[null==(a=c.country)?void 0:a.toUpperCase()])}):"number"==typeof c?u.gridIntensity.dataCenter={value:c}:(u.gridIntensity.dataCenter={value:r},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof c}. \nFalling back to global average grid intensity.`))),(g||0===g)&&("object"==typeof g?(n.data[null==(s=g.country)?void 0:s.toUpperCase()]||(console.warn(`"${g.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \nFalling back to global average grid intensity.`),u.gridIntensity.network={value:r}),u.gridIntensity.network={country:g.country,value:parseFloat(n.data[null==(l=g.country)?void 0:l.toUpperCase()])}):"number"==typeof g?u.gridIntensity.network={value:g}:(u.gridIntensity.network={value:r},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof g}. \nFalling back to global average grid intensity.`)))}return((null==e?void 0:e.dataReloadRatio)||0===e.dataReloadRatio)&&("number"==typeof e.dataReloadRatio?e.dataReloadRatio>=0&&e.dataReloadRatio<=1?u.dataReloadRatio=e.dataReloadRatio:(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${e.dataReloadRatio}. \nFalling back to default value.`)):(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof e.dataReloadRatio}. \nFalling back to default value.`))),((null==e?void 0:e.firstVisitPercentage)||0===e.firstVisitPercentage)&&("number"==typeof e.firstVisitPercentage?e.firstVisitPercentage>=0&&e.firstVisitPercentage<=1?u.firstVisitPercentage=e.firstVisitPercentage:(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${e.firstVisitPercentage}. \nFalling back to default value.`)):(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof e.firstVisitPercentage}. \nFalling back to default value.`))),((null==e?void 0:e.returnVisitPercentage)||0===e.returnVisitPercentage)&&("number"==typeof e.returnVisitPercentage?e.returnVisitPercentage>=0&&e.returnVisitPercentage<=1?u.returnVisitPercentage=e.returnVisitPercentage:(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${e.returnVisitPercentage}. \nFalling back to default value.`)):(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof e.returnVisitPercentage}. \nFalling back to default value.`))),u}function a(e=""){return{"User-Agent":`co2js/0.15.0 ${e}`}}var s,l,u=Object.defineProperty,d=Object.defineProperties,c=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,v=(e,t,n)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))y.call(t,n)&&v(e,n,t[n]);if(g)for(var n of g(t))p.call(t,n)&&v(e,n,t[n]);return e},b=(e,t)=>d(e,c(t)),m=class{constructor(e){this.options=e}energyPerByteByComponent(e){const t=e/1e9*.81;return{consumerDeviceEnergy:.52*t,networkEnergy:.14*t,productionEnergy:.19*t,dataCenterEnergy:.15*t}}co2byComponent(e,t=r,n={}){let o=r,i=r,a=r,s=r;if(null==n?void 0:n.gridIntensity){const{device:e,network:t,dataCenter:r}=n.gridIntensity;((null==e?void 0:e.value)||0===(null==e?void 0:e.value))&&(o=e.value),((null==t?void 0:t.value)||0===(null==t?void 0:t.value))&&(i=t.value),((null==r?void 0:r.value)||0===(null==r?void 0:r.value))&&(a=r.value)}!0===t&&(a=50);const l={};for(const[t,n]of Object.entries(e))t.startsWith("dataCenterEnergy")?l[t.replace("Energy","CO2")]=n*a:t.startsWith("consumerDeviceEnergy")?l[t.replace("Energy","CO2")]=n*o:t.startsWith("networkEnergy")?l[t.replace("Energy","CO2")]=n*i:l[t.replace("Energy","CO2")]=n*s;return l}perByte(e,t=!1,n=!1,r={}){e<1&&(e=0);const o=this.energyPerByteByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}perVisit(e,t=!1,n=!1,r={}){const o=this.energyPerVisitByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}energyPerByte(e){const t=this.energyPerByteByComponent(e);return Object.values(t).reduce(((e,t)=>e+t))}energyPerVisitByComponent(e,t={},n=.75,r=.25,o=.02){(t.dataReloadRatio||0===t.dataReloadRatio)&&(o=t.dataReloadRatio),(t.firstVisitPercentage||0===t.firstVisitPercentage)&&(n=t.firstVisitPercentage),(t.returnVisitPercentage||0===t.returnVisitPercentage)&&(r=t.returnVisitPercentage);const i=this.energyPerByteByComponent(e),a={};Object.values(i);for(const[e,t]of Object.entries(i))a[`${e} - first`]=t*n,a[`${e} - subsequent`]=t*r*o;return a}energyPerVisit(e){let t=0,n=0;const r=Object.entries(this.energyPerVisitByComponent(e));for(const[e,n]of r)e.indexOf("first")>0&&(t+=n);for(const[e,t]of r)e.indexOf("subsequent")>0&&(n+=t);return t+n}emissionsPerVisitInGrams(e,t=r){return o(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:o(.52*e),networkEnergy:o(.14*e),dataCenterEnergy:o(.15*e),productionEnergy:o(.19*e)}}},h=class{constructor(e){if(this.model=new m,"1byte"===(null==e?void 0:e.model))this.model=new t;else if("swd"===(null==e?void 0:e.model))this.model=new m;else if(null==e?void 0:e.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment="segment"===(null==e?void 0:e.results)}perByte(e,t=!1){return this.model.perByte(e,t,this._segment)}perVisit(e,t=!1){var n;if(null==(n=this.model)?void 0:n.perVisit)return this.model.perVisit(e,t,this._segment);throw new Error("The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}perByteTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y;let p={};return n&&(p=i(n)),{co2:this.model.perByte(e,t,this._segment,p),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(s=null==(a=null==(o=null==p?void 0:p.gridIntensity)?void 0:o.network)?void 0:a.value)?s:r,dataCenter:t?50:null!=(d=null==(u=null==(l=null==p?void 0:p.gridIntensity)?void 0:l.dataCenter)?void 0:u.value)?d:r,production:r,device:null!=(y=null==(g=null==(c=null==p?void 0:p.gridIntensity)?void 0:c.device)?void 0:g.value)?y:r}}}}perVisitTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y,p,v,f,b;if(null==(o=this.model)?void 0:o.perVisit){let o={};return n&&(o=i(n)),{co2:this.model.perVisit(e,t,this._segment,o),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(l=null==(s=null==(a=null==o?void 0:o.gridIntensity)?void 0:a.network)?void 0:s.value)?l:r,dataCenter:t?50:null!=(c=null==(d=null==(u=null==o?void 0:o.gridIntensity)?void 0:u.dataCenter)?void 0:d.value)?c:r,production:r,device:null!=(p=null==(y=null==(g=null==o?void 0:o.gridIntensity)?void 0:g.device)?void 0:y.value)?p:r},dataReloadRatio:null!=(v=null==o?void 0:o.dataReloadRatio)?v:.02,firstVisitPercentage:null!=(f=null==o?void 0:o.firstVisitPercentage)?f:.75,returnVisitPercentage:null!=(b=null==o?void 0:o.returnVisitPercentage)?b:.25}}}throw new Error("The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}},R=Object.getOwnPropertyNames;const w=(s={"src/hosting-json.js"(e,t){function n(e,t){return t.indexOf(e)>-1?e:{url:e,green:!1}}t.exports={check:async function(e,t){return"string"==typeof e?function(e,t){return t.indexOf(e)>-1}(e,t):function(e,t){let n=[];for(let r of e)t.indexOf(r)>-1&&n.push(r);return n}(e,t)},greenDomainsFromResults:function(e){return Object.entries(e).filter((([e,t])=>t.green)).map((([e,t])=>t.url))},find:function(e,t){return"string"==typeof e?n(e,t):function(e,t){const r={};for(let o of e)r[o]=n(o,t);return r}(e,t)}}}},function(){return l||(0,s[R(s)[0]])((l={exports:{}}).exports,l),l.exports})();var P=function(e,t){const n="string"==typeof t?{userAgentIdentifier:t}:t;if((null==n?void 0:n.db)&&n.verbose)throw new Error("verbose mode cannot be used with a local lookup database");return"string"==typeof e?async function(e,t={}){const n=await fetch(`https://api.thegreenwebfoundation.org/greencheck/${e}`,{headers:a(t.userAgentIdentifier)});if(null==t?void 0:t.db)return w.check(e,t.db);const r=await n.json();return t.verbose?r:r.green}(e,n):async function(e,t={}){try{const r="https://api.thegreenwebfoundation.org/v2/greencheckmulti",o=JSON.stringify(e),i=await fetch(`${r}/${o}`,{headers:a(t.userAgentIdentifier)}),s=await i.json();return t.verbose?s:(n=s,Object.entries(n).filter((([e,t])=>t.green)).map((([e,t])=>t.url)))}catch(e){return t.verbose?{}:[]}var n}(e,n)},C=function(e,t){return P(e,t)};async function O(){console.log("reportEmissions called"),await async function(){return window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"}),E(2e3)}(),await E(2e3),console.log("getting emissions data");const e=await async function(){console.log("calculating...");const e=window.performance.getEntriesByType("resource").filter((e=>!(e.name||"").split("?")[0].endsWith("resource-checker.js"))),t=function(e){return e.reduce(((e,t)=>e+t.transferSize),0)}(e),n=await C(window.location.hostname),r=new h({model:"swd"}).perVisitTrace(t,n);return{pageWeight:t,carbonRating:(o=r.co2,o<.095?"A+":o<.186?"A":o<.341?"B":o<.493?"C":o<.656?"D":o<.846?"E":"F"),emissions:r,resources:e};var o}();console.log("received emissions data");const t=document.createElement("div");t.setAttribute("data-testid","sustainabilityData"),t.textContent=JSON.stringify(e),document.body.appendChild(t)}function E(e){return new Promise((t=>setTimeout(t,e)))}export{O as reportEmissions};
const e=1.465e-9/3;var t=class{constructor(t){this.options=t,this.KWH_PER_BYTE_FOR_NETWORK=e}perByte(t,n){return t<1?0:n?72e-12*t*0+t*e*475:5.603333333333333e-10*t*519}},n={data:{AFG:132.53,AFRICA:559.42,ALB:24.29,DZA:634.61,ASM:611.11,AGO:174.73,ATG:611.11,ARG:394.62,ARM:264.54,ABW:561.22,ASEAN:554.5,ASIA:591.19,AUS:570.35,AUT:110.81,AZE:671.39,BHS:660.1,BHR:904.62,BGD:678.11,BRB:605.51,BLR:441.74,BEL:138.11,BLZ:225.81,BEN:584.07,BTN:23.33,BOL:489.14,BIH:600,BWA:847.91,BRA:105.51,BRN:893.91,BGR:335.33,BFA:467.53,BDI:250,CPV:558.14,KHM:417.71,CMR:305.42,CAN:161.43,CYM:642.86,CAF:0,TCD:628.57,CHL:353.52,CHN:585.82,COL:214.88,COM:642.86,COG:700,COD:24.46,COK:250,CRI:26.46,CIV:393.89,HRV:204.96,CUB:637.61,CYP:534.32,CZE:449.72,DNK:151.65,DJI:692.31,DMA:529.41,DOM:580.78,ECU:150.69,EGY:570.13,SLV:116.54,GNQ:591.84,ERI:631.58,EST:416.67,SWZ:172.41,ETH:24.64,EU:243.83,EUROPE:327.69,FLK:500,FRO:404.76,FJI:288.46,FIN:79.16,FRA:56.04,GUF:217.82,PYF:442.86,G20:482.92,G7:361.52,GAB:491.6,GMB:666.67,GEO:167.02,DEU:380.95,GHA:484,GRC:336.57,GRL:178.57,GRD:640,GLP:500,GUM:622.86,GTM:328.27,GIN:236.84,GNB:625,GUY:640.35,HTI:567.31,HND:282.27,HKG:699.5,HUN:204.19,ISL:27.68,IND:705.13,IDN:675.93,IRN:665.15,IRQ:688.81,IRL:290.81,ISR:582.93,ITA:330.72,JAM:555.56,JPN:512.81,JOR:540.92,KAZ:830.41,KEN:83.33,KIR:666.67,XKX:894.65,KWT:649.2,KGZ:147.29,LAO:265.51,"LATIN AMERICA AND CARIBBEAN":260.28,LVA:123.2,LBN:599.01,LSO:20,LBR:227.85,LBY:818.69,LTU:160.07,LUX:105.26,MAC:448.98,MDG:436.44,MWI:66.67,MYS:605.83,MDV:611.77,MLI:408,MLT:459.14,MTQ:523.18,MRT:464.71,MUS:632.48,MEX:475.36,"MIDDLE EAST":660.46,MDA:648.5,MNG:771.8,MNE:417.07,MSR:1e3,MAR:662.64,MOZ:135.65,MMR:483.57,NAM:59.26,NRU:750,NPL:24.44,NLD:267.62,NCL:660.58,NZL:110.89,NIC:265.12,NER:670.89,NGA:516.23,"NORTH AMERICA":356.01,PRK:389.59,MKD:565.35,NOR:30.08,OCEANIA:507.63,OECD:360.53,OMN:564.69,PAK:463.66,PSE:516.13,PAN:161.68,PNG:507.25,PRY:24.31,PER:251.74,POL:661.93,PRT:165.55,PRI:678.74,QAT:602.59,REU:572.82,ROU:240.58,RUS:436.28,RWA:316.33,KNA:636.36,LCA:666.67,SPM:600,VCT:529.41,WSM:473.68,STP:642.86,SAU:706.79,SEN:511.6,SRB:636.06,SYC:564.52,SLE:50,SGP:474,SVK:116.77,SVN:231.28,SLB:700,SOM:578.95,ZAF:729.67,KOR:441.65,SSD:629.03,ESP:174.05,LKA:509.78,SDN:263.16,SUR:349.28,SWE:40.7,CHE:34.84,SYR:701.66,TWN:639.53,TJK:116.86,TZA:339.25,THA:560.74,PHL:601.1,TGO:443.18,TON:625,TTO:681.53,TUN:564.62,TUR:464.59,TKM:1306.03,TCA:653.85,UGA:44.53,UKR:259.69,ARE:561.14,GBR:237.59,USA:385.98,URY:112.65,UZB:1167.6,VUT:571.43,VEN:185.8,VNM:409.8,VGB:647.06,VIR:632.35,WORLD:485.99,YEM:566.1,ZMB:111.97,ZWE:297.87},type:"average"};const r=n.data.WORLD,o=e=>parseFloat(e.toFixed(2));function i(e){var t,o,i,a,s,l;if("object"!=typeof e)throw new Error("Options must be an object");const u={};if(null==e?void 0:e.gridIntensity){u.gridIntensity={};const{device:d,dataCenter:c,network:g}=e.gridIntensity;(d||0===d)&&("object"==typeof d?(n.data[null==(t=d.country)?void 0:t.toUpperCase()]||(console.warn(`"${d.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.device={value:r}),u.gridIntensity.device={country:d.country,value:parseFloat(n.data[null==(o=d.country)?void 0:o.toUpperCase()])}):"number"==typeof d?u.gridIntensity.device={value:d}:(u.gridIntensity.device={value:r},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof d}. \nFalling back to global average grid intensity.`))),(c||0===c)&&("object"==typeof c?(n.data[null==(i=c.country)?void 0:i.toUpperCase()]||(console.warn(`"${c.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.dataCenter={value:r}),u.gridIntensity.dataCenter={country:c.country,value:parseFloat(n.data[null==(a=c.country)?void 0:a.toUpperCase()])}):"number"==typeof c?u.gridIntensity.dataCenter={value:c}:(u.gridIntensity.dataCenter={value:r},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof c}. \nFalling back to global average grid intensity.`))),(g||0===g)&&("object"==typeof g?(n.data[null==(s=g.country)?void 0:s.toUpperCase()]||(console.warn(`"${g.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \nFalling back to global average grid intensity.`),u.gridIntensity.network={value:r}),u.gridIntensity.network={country:g.country,value:parseFloat(n.data[null==(l=g.country)?void 0:l.toUpperCase()])}):"number"==typeof g?u.gridIntensity.network={value:g}:(u.gridIntensity.network={value:r},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof g}. \nFalling back to global average grid intensity.`)))}return((null==e?void 0:e.dataReloadRatio)||0===e.dataReloadRatio)&&("number"==typeof e.dataReloadRatio?e.dataReloadRatio>=0&&e.dataReloadRatio<=1?u.dataReloadRatio=e.dataReloadRatio:(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${e.dataReloadRatio}. \nFalling back to default value.`)):(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof e.dataReloadRatio}. \nFalling back to default value.`))),((null==e?void 0:e.firstVisitPercentage)||0===e.firstVisitPercentage)&&("number"==typeof e.firstVisitPercentage?e.firstVisitPercentage>=0&&e.firstVisitPercentage<=1?u.firstVisitPercentage=e.firstVisitPercentage:(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${e.firstVisitPercentage}. \nFalling back to default value.`)):(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof e.firstVisitPercentage}. \nFalling back to default value.`))),((null==e?void 0:e.returnVisitPercentage)||0===e.returnVisitPercentage)&&("number"==typeof e.returnVisitPercentage?e.returnVisitPercentage>=0&&e.returnVisitPercentage<=1?u.returnVisitPercentage=e.returnVisitPercentage:(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${e.returnVisitPercentage}. \nFalling back to default value.`)):(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof e.returnVisitPercentage}. \nFalling back to default value.`))),u}function a(e=""){return{"User-Agent":`co2js/0.15.0 ${e}`}}var s,l,u=Object.defineProperty,d=Object.defineProperties,c=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,v=(e,t,n)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))y.call(t,n)&&v(e,n,t[n]);if(g)for(var n of g(t))p.call(t,n)&&v(e,n,t[n]);return e},b=(e,t)=>d(e,c(t)),m=class{constructor(e){this.options=e}energyPerByteByComponent(e){const t=e/1e9*.81;return{consumerDeviceEnergy:.52*t,networkEnergy:.14*t,productionEnergy:.19*t,dataCenterEnergy:.15*t}}co2byComponent(e,t=r,n={}){let o=r,i=r,a=r,s=r;if(null==n?void 0:n.gridIntensity){const{device:e,network:t,dataCenter:r}=n.gridIntensity;((null==e?void 0:e.value)||0===(null==e?void 0:e.value))&&(o=e.value),((null==t?void 0:t.value)||0===(null==t?void 0:t.value))&&(i=t.value),((null==r?void 0:r.value)||0===(null==r?void 0:r.value))&&(a=r.value)}!0===t&&(a=50);const l={};for(const[t,n]of Object.entries(e))t.startsWith("dataCenterEnergy")?l[t.replace("Energy","CO2")]=n*a:t.startsWith("consumerDeviceEnergy")?l[t.replace("Energy","CO2")]=n*o:t.startsWith("networkEnergy")?l[t.replace("Energy","CO2")]=n*i:l[t.replace("Energy","CO2")]=n*s;return l}perByte(e,t=!1,n=!1,r={}){e<1&&(e=0);const o=this.energyPerByteByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}perVisit(e,t=!1,n=!1,r={}){const o=this.energyPerVisitByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}energyPerByte(e){const t=this.energyPerByteByComponent(e);return Object.values(t).reduce(((e,t)=>e+t))}energyPerVisitByComponent(e,t={},n=.75,r=.25,o=.02){(t.dataReloadRatio||0===t.dataReloadRatio)&&(o=t.dataReloadRatio),(t.firstVisitPercentage||0===t.firstVisitPercentage)&&(n=t.firstVisitPercentage),(t.returnVisitPercentage||0===t.returnVisitPercentage)&&(r=t.returnVisitPercentage);const i=this.energyPerByteByComponent(e),a={};Object.values(i);for(const[e,t]of Object.entries(i))a[`${e} - first`]=t*n,a[`${e} - subsequent`]=t*r*o;return a}energyPerVisit(e){let t=0,n=0;const r=Object.entries(this.energyPerVisitByComponent(e));for(const[e,n]of r)e.indexOf("first")>0&&(t+=n);for(const[e,t]of r)e.indexOf("subsequent")>0&&(n+=t);return t+n}emissionsPerVisitInGrams(e,t=r){return o(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:o(.52*e),networkEnergy:o(.14*e),dataCenterEnergy:o(.15*e),productionEnergy:o(.19*e)}}},h=class{constructor(e){if(this.model=new m,"1byte"===(null==e?void 0:e.model))this.model=new t;else if("swd"===(null==e?void 0:e.model))this.model=new m;else if(null==e?void 0:e.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment="segment"===(null==e?void 0:e.results)}perByte(e,t=!1){return this.model.perByte(e,t,this._segment)}perVisit(e,t=!1){var n;if(null==(n=this.model)?void 0:n.perVisit)return this.model.perVisit(e,t,this._segment);throw new Error("The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}perByteTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y;let p={};return n&&(p=i(n)),{co2:this.model.perByte(e,t,this._segment,p),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(s=null==(a=null==(o=null==p?void 0:p.gridIntensity)?void 0:o.network)?void 0:a.value)?s:r,dataCenter:t?50:null!=(d=null==(u=null==(l=null==p?void 0:p.gridIntensity)?void 0:l.dataCenter)?void 0:u.value)?d:r,production:r,device:null!=(y=null==(g=null==(c=null==p?void 0:p.gridIntensity)?void 0:c.device)?void 0:g.value)?y:r}}}}perVisitTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y,p,v,f,b;if(null==(o=this.model)?void 0:o.perVisit){let o={};return n&&(o=i(n)),{co2:this.model.perVisit(e,t,this._segment,o),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(l=null==(s=null==(a=null==o?void 0:o.gridIntensity)?void 0:a.network)?void 0:s.value)?l:r,dataCenter:t?50:null!=(c=null==(d=null==(u=null==o?void 0:o.gridIntensity)?void 0:u.dataCenter)?void 0:d.value)?c:r,production:r,device:null!=(p=null==(y=null==(g=null==o?void 0:o.gridIntensity)?void 0:g.device)?void 0:y.value)?p:r},dataReloadRatio:null!=(v=null==o?void 0:o.dataReloadRatio)?v:.02,firstVisitPercentage:null!=(f=null==o?void 0:o.firstVisitPercentage)?f:.75,returnVisitPercentage:null!=(b=null==o?void 0:o.returnVisitPercentage)?b:.25}}}throw new Error("The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}},R=Object.getOwnPropertyNames;const w=(s={"src/hosting-json.js"(e,t){function n(e,t){return t.indexOf(e)>-1?e:{url:e,green:!1}}t.exports={check:async function(e,t){return"string"==typeof e?function(e,t){return t.indexOf(e)>-1}(e,t):function(e,t){let n=[];for(let r of e)t.indexOf(r)>-1&&n.push(r);return n}(e,t)},greenDomainsFromResults:function(e){return Object.entries(e).filter((([e,t])=>t.green)).map((([e,t])=>t.url))},find:function(e,t){return"string"==typeof e?n(e,t):function(e,t){const r={};for(let o of e)r[o]=n(o,t);return r}(e,t)}}}},function(){return l||(0,s[R(s)[0]])((l={exports:{}}).exports,l),l.exports})();var P=function(e,t){const n="string"==typeof t?{userAgentIdentifier:t}:t;if((null==n?void 0:n.db)&&n.verbose)throw new Error("verbose mode cannot be used with a local lookup database");return"string"==typeof e?async function(e,t={}){const n=await fetch(`https://api.thegreenwebfoundation.org/greencheck/${e}`,{headers:a(t.userAgentIdentifier)});if(null==t?void 0:t.db)return w.check(e,t.db);const r=await n.json();return t.verbose?r:r.green}(e,n):async function(e,t={}){var n;try{const r="https://api.thegreenwebfoundation.org/v2/greencheckmulti",o=JSON.stringify(e),i=await fetch(`${r}/${o}`,{headers:a(t.userAgentIdentifier)}),s=await i.json();return t.verbose?s:(n=s,Object.entries(n).filter((([e,t])=>t.green)).map((([e,t])=>t.url)))}catch(e){return t.verbose?{}:[]} }(e,n)},C=function(e,t){return P(e,t)};async function O(){console.log("reportEmissions called"),await async function(){return window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"}),E(2e3)}(),await E(2e3),console.log("getting emissions data");const e=await async function(){console.log("calculating...");const e=window.performance.getEntriesByType("resource").filter((e=>!(e.name||"").split("?")[0].endsWith("resource-checker.js"))),t=function(e){return e.reduce(((e,t)=>e+t.transferSize),0)}(e),n=await C(window.location.hostname),r=new h({model:"swd"}).perVisitTrace(t,n);return{pageWeight:t,carbonRating:(o=r.co2,o<.095?"A+":o<.186?"A":o<.341?"B":o<.493?"C":o<.656?"D":o<.846?"E":"F"),emissions:r,resources:e};var o}();console.log("received emissions data");const t=document.createElement("div");t.setAttribute("data-testid","sustainabilityData"),t.textContent=JSON.stringify(e),document.body.appendChild(t)}function E(e){return new Promise((t=>setTimeout(t,e)))}export{O as reportEmissions};

Copilot uses AI. Check for mistakes.
@@ -1 +1 @@
const e=1.465e-9/3;var t=class{constructor(t){this.options=t,this.KWH_PER_BYTE_FOR_NETWORK=e}perByte(t,n){return t<1?0:n?72e-12*t*0+t*e*475:5.603333333333333e-10*t*519}},n={data:{AFG:132.53,AFRICA:559.42,ALB:24.29,DZA:634.61,ASM:611.11,AGO:174.73,ATG:611.11,ARG:394.62,ARM:264.54,ABW:561.22,ASEAN:554.5,ASIA:591.19,AUS:570.35,AUT:110.81,AZE:671.39,BHS:660.1,BHR:904.62,BGD:678.11,BRB:605.51,BLR:441.74,BEL:138.11,BLZ:225.81,BEN:584.07,BTN:23.33,BOL:489.14,BIH:600,BWA:847.91,BRA:105.51,BRN:893.91,BGR:335.33,BFA:467.53,BDI:250,CPV:558.14,KHM:417.71,CMR:305.42,CAN:161.43,CYM:642.86,CAF:0,TCD:628.57,CHL:353.52,CHN:585.82,COL:214.88,COM:642.86,COG:700,COD:24.46,COK:250,CRI:26.46,CIV:393.89,HRV:204.96,CUB:637.61,CYP:534.32,CZE:449.72,DNK:151.65,DJI:692.31,DMA:529.41,DOM:580.78,ECU:150.69,EGY:570.13,SLV:116.54,GNQ:591.84,ERI:631.58,EST:416.67,SWZ:172.41,ETH:24.64,EU:243.83,EUROPE:327.69,FLK:500,FRO:404.76,FJI:288.46,FIN:79.16,FRA:56.04,GUF:217.82,PYF:442.86,G20:482.92,G7:361.52,GAB:491.6,GMB:666.67,GEO:167.02,DEU:380.95,GHA:484,GRC:336.57,GRL:178.57,GRD:640,GLP:500,GUM:622.86,GTM:328.27,GIN:236.84,GNB:625,GUY:640.35,HTI:567.31,HND:282.27,HKG:699.5,HUN:204.19,ISL:27.68,IND:705.13,IDN:675.93,IRN:665.15,IRQ:688.81,IRL:290.81,ISR:582.93,ITA:330.72,JAM:555.56,JPN:512.81,JOR:540.92,KAZ:830.41,KEN:83.33,KIR:666.67,XKX:894.65,KWT:649.2,KGZ:147.29,LAO:265.51,"LATIN AMERICA AND CARIBBEAN":260.28,LVA:123.2,LBN:599.01,LSO:20,LBR:227.85,LBY:818.69,LTU:160.07,LUX:105.26,MAC:448.98,MDG:436.44,MWI:66.67,MYS:605.83,MDV:611.77,MLI:408,MLT:459.14,MTQ:523.18,MRT:464.71,MUS:632.48,MEX:475.36,"MIDDLE EAST":660.46,MDA:648.5,MNG:771.8,MNE:417.07,MSR:1e3,MAR:662.64,MOZ:135.65,MMR:483.57,NAM:59.26,NRU:750,NPL:24.44,NLD:267.62,NCL:660.58,NZL:110.89,NIC:265.12,NER:670.89,NGA:516.23,"NORTH AMERICA":356.01,PRK:389.59,MKD:565.35,NOR:30.08,OCEANIA:507.63,OECD:360.53,OMN:564.69,PAK:463.66,PSE:516.13,PAN:161.68,PNG:507.25,PRY:24.31,PER:251.74,POL:661.93,PRT:165.55,PRI:678.74,QAT:602.59,REU:572.82,ROU:240.58,RUS:436.28,RWA:316.33,KNA:636.36,LCA:666.67,SPM:600,VCT:529.41,WSM:473.68,STP:642.86,SAU:706.79,SEN:511.6,SRB:636.06,SYC:564.52,SLE:50,SGP:474,SVK:116.77,SVN:231.28,SLB:700,SOM:578.95,ZAF:729.67,KOR:441.65,SSD:629.03,ESP:174.05,LKA:509.78,SDN:263.16,SUR:349.28,SWE:40.7,CHE:34.84,SYR:701.66,TWN:639.53,TJK:116.86,TZA:339.25,THA:560.74,PHL:601.1,TGO:443.18,TON:625,TTO:681.53,TUN:564.62,TUR:464.59,TKM:1306.03,TCA:653.85,UGA:44.53,UKR:259.69,ARE:561.14,GBR:237.59,USA:385.98,URY:112.65,UZB:1167.6,VUT:571.43,VEN:185.8,VNM:409.8,VGB:647.06,VIR:632.35,WORLD:485.99,YEM:566.1,ZMB:111.97,ZWE:297.87},type:"average"};const r=n.data.WORLD,o=e=>parseFloat(e.toFixed(2));function i(e){var t,o,i,a,s,l;if("object"!=typeof e)throw new Error("Options must be an object");const u={};if(null==e?void 0:e.gridIntensity){u.gridIntensity={};const{device:d,dataCenter:c,network:g}=e.gridIntensity;(d||0===d)&&("object"==typeof d?(n.data[null==(t=d.country)?void 0:t.toUpperCase()]||(console.warn(`"${d.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.device={value:r}),u.gridIntensity.device={country:d.country,value:parseFloat(n.data[null==(o=d.country)?void 0:o.toUpperCase()])}):"number"==typeof d?u.gridIntensity.device={value:d}:(u.gridIntensity.device={value:r},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof d}. \nFalling back to global average grid intensity.`))),(c||0===c)&&("object"==typeof c?(n.data[null==(i=c.country)?void 0:i.toUpperCase()]||(console.warn(`"${c.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.dataCenter={value:r}),u.gridIntensity.dataCenter={country:c.country,value:parseFloat(n.data[null==(a=c.country)?void 0:a.toUpperCase()])}):"number"==typeof c?u.gridIntensity.dataCenter={value:c}:(u.gridIntensity.dataCenter={value:r},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof c}. \nFalling back to global average grid intensity.`))),(g||0===g)&&("object"==typeof g?(n.data[null==(s=g.country)?void 0:s.toUpperCase()]||(console.warn(`"${g.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \nFalling back to global average grid intensity.`),u.gridIntensity.network={value:r}),u.gridIntensity.network={country:g.country,value:parseFloat(n.data[null==(l=g.country)?void 0:l.toUpperCase()])}):"number"==typeof g?u.gridIntensity.network={value:g}:(u.gridIntensity.network={value:r},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof g}. \nFalling back to global average grid intensity.`)))}return((null==e?void 0:e.dataReloadRatio)||0===e.dataReloadRatio)&&("number"==typeof e.dataReloadRatio?e.dataReloadRatio>=0&&e.dataReloadRatio<=1?u.dataReloadRatio=e.dataReloadRatio:(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${e.dataReloadRatio}. \nFalling back to default value.`)):(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof e.dataReloadRatio}. \nFalling back to default value.`))),((null==e?void 0:e.firstVisitPercentage)||0===e.firstVisitPercentage)&&("number"==typeof e.firstVisitPercentage?e.firstVisitPercentage>=0&&e.firstVisitPercentage<=1?u.firstVisitPercentage=e.firstVisitPercentage:(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${e.firstVisitPercentage}. \nFalling back to default value.`)):(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof e.firstVisitPercentage}. \nFalling back to default value.`))),((null==e?void 0:e.returnVisitPercentage)||0===e.returnVisitPercentage)&&("number"==typeof e.returnVisitPercentage?e.returnVisitPercentage>=0&&e.returnVisitPercentage<=1?u.returnVisitPercentage=e.returnVisitPercentage:(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${e.returnVisitPercentage}. \nFalling back to default value.`)):(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof e.returnVisitPercentage}. \nFalling back to default value.`))),u}function a(e=""){return{"User-Agent":`co2js/0.15.0 ${e}`}}var s,l,u=Object.defineProperty,d=Object.defineProperties,c=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,v=(e,t,n)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))y.call(t,n)&&v(e,n,t[n]);if(g)for(var n of g(t))p.call(t,n)&&v(e,n,t[n]);return e},b=(e,t)=>d(e,c(t)),m=class{constructor(e){this.options=e}energyPerByteByComponent(e){const t=e/1e9*.81;return{consumerDeviceEnergy:.52*t,networkEnergy:.14*t,productionEnergy:.19*t,dataCenterEnergy:.15*t}}co2byComponent(e,t=r,n={}){let o=r,i=r,a=r,s=r;if(null==n?void 0:n.gridIntensity){const{device:e,network:t,dataCenter:r}=n.gridIntensity;((null==e?void 0:e.value)||0===(null==e?void 0:e.value))&&(o=e.value),((null==t?void 0:t.value)||0===(null==t?void 0:t.value))&&(i=t.value),((null==r?void 0:r.value)||0===(null==r?void 0:r.value))&&(a=r.value)}!0===t&&(a=50);const l={};for(const[t,n]of Object.entries(e))t.startsWith("dataCenterEnergy")?l[t.replace("Energy","CO2")]=n*a:t.startsWith("consumerDeviceEnergy")?l[t.replace("Energy","CO2")]=n*o:t.startsWith("networkEnergy")?l[t.replace("Energy","CO2")]=n*i:l[t.replace("Energy","CO2")]=n*s;return l}perByte(e,t=!1,n=!1,r={}){e<1&&(e=0);const o=this.energyPerByteByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}perVisit(e,t=!1,n=!1,r={}){const o=this.energyPerVisitByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}energyPerByte(e){const t=this.energyPerByteByComponent(e);return Object.values(t).reduce(((e,t)=>e+t))}energyPerVisitByComponent(e,t={},n=.75,r=.25,o=.02){(t.dataReloadRatio||0===t.dataReloadRatio)&&(o=t.dataReloadRatio),(t.firstVisitPercentage||0===t.firstVisitPercentage)&&(n=t.firstVisitPercentage),(t.returnVisitPercentage||0===t.returnVisitPercentage)&&(r=t.returnVisitPercentage);const i=this.energyPerByteByComponent(e),a={};Object.values(i);for(const[e,t]of Object.entries(i))a[`${e} - first`]=t*n,a[`${e} - subsequent`]=t*r*o;return a}energyPerVisit(e){let t=0,n=0;const r=Object.entries(this.energyPerVisitByComponent(e));for(const[e,n]of r)e.indexOf("first")>0&&(t+=n);for(const[e,t]of r)e.indexOf("subsequent")>0&&(n+=t);return t+n}emissionsPerVisitInGrams(e,t=r){return o(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:o(.52*e),networkEnergy:o(.14*e),dataCenterEnergy:o(.15*e),productionEnergy:o(.19*e)}}},h=class{constructor(e){if(this.model=new m,"1byte"===(null==e?void 0:e.model))this.model=new t;else if("swd"===(null==e?void 0:e.model))this.model=new m;else if(null==e?void 0:e.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment="segment"===(null==e?void 0:e.results)}perByte(e,t=!1){return this.model.perByte(e,t,this._segment)}perVisit(e,t=!1){var n;if(null==(n=this.model)?void 0:n.perVisit)return this.model.perVisit(e,t,this._segment);throw new Error("The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}perByteTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y;let p={};return n&&(p=i(n)),{co2:this.model.perByte(e,t,this._segment,p),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(s=null==(a=null==(o=null==p?void 0:p.gridIntensity)?void 0:o.network)?void 0:a.value)?s:r,dataCenter:t?50:null!=(d=null==(u=null==(l=null==p?void 0:p.gridIntensity)?void 0:l.dataCenter)?void 0:u.value)?d:r,production:r,device:null!=(y=null==(g=null==(c=null==p?void 0:p.gridIntensity)?void 0:c.device)?void 0:g.value)?y:r}}}}perVisitTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y,p,v,f,b;if(null==(o=this.model)?void 0:o.perVisit){let o={};return n&&(o=i(n)),{co2:this.model.perVisit(e,t,this._segment,o),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(l=null==(s=null==(a=null==o?void 0:o.gridIntensity)?void 0:a.network)?void 0:s.value)?l:r,dataCenter:t?50:null!=(c=null==(d=null==(u=null==o?void 0:o.gridIntensity)?void 0:u.dataCenter)?void 0:d.value)?c:r,production:r,device:null!=(p=null==(y=null==(g=null==o?void 0:o.gridIntensity)?void 0:g.device)?void 0:y.value)?p:r},dataReloadRatio:null!=(v=null==o?void 0:o.dataReloadRatio)?v:.02,firstVisitPercentage:null!=(f=null==o?void 0:o.firstVisitPercentage)?f:.75,returnVisitPercentage:null!=(b=null==o?void 0:o.returnVisitPercentage)?b:.25}}}throw new Error("The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}},R=Object.getOwnPropertyNames;const w=(s={"src/hosting-json.js"(e,t){function n(e,t){return t.indexOf(e)>-1?e:{url:e,green:!1}}t.exports={check:async function(e,t){return"string"==typeof e?function(e,t){return t.indexOf(e)>-1}(e,t):function(e,t){let n=[];for(let r of e)t.indexOf(r)>-1&&n.push(r);return n}(e,t)},greenDomainsFromResults:function(e){return Object.entries(e).filter((([e,t])=>t.green)).map((([e,t])=>t.url))},find:function(e,t){return"string"==typeof e?n(e,t):function(e,t){const r={};for(let o of e)r[o]=n(o,t);return r}(e,t)}}}},function(){return l||(0,s[R(s)[0]])((l={exports:{}}).exports,l),l.exports})();var P=function(e,t){const n="string"==typeof t?{userAgentIdentifier:t}:t;if((null==n?void 0:n.db)&&n.verbose)throw new Error("verbose mode cannot be used with a local lookup database");return"string"==typeof e?async function(e,t={}){const n=await fetch(`https://api.thegreenwebfoundation.org/greencheck/${e}`,{headers:a(t.userAgentIdentifier)});if(null==t?void 0:t.db)return w.check(e,t.db);const r=await n.json();return t.verbose?r:r.green}(e,n):async function(e,t={}){try{const r="https://api.thegreenwebfoundation.org/v2/greencheckmulti",o=JSON.stringify(e),i=await fetch(`${r}/${o}`,{headers:a(t.userAgentIdentifier)}),s=await i.json();return t.verbose?s:(n=s,Object.entries(n).filter((([e,t])=>t.green)).map((([e,t])=>t.url)))}catch(e){return t.verbose?{}:[]}var n}(e,n)},C=function(e,t){return P(e,t)};async function O(){console.log("reportEmissions called"),await async function(){return window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"}),E(2e3)}(),await E(2e3),console.log("getting emissions data");const e=await async function(){console.log("calculating...");const e=window.performance.getEntriesByType("resource").filter((e=>!(e.name||"").includes("resource-checker.js"))),t=function(e){return e.reduce(((e,t)=>e+t.transferSize),0)}(e),n=await C(window.location.hostname),r=new h({model:"swd"}).perVisitTrace(t,n);return{pageWeight:t,carbonRating:(o=r.co2,o<.095?"A+":o<.186?"A":o<.341?"B":o<.493?"C":o<.656?"D":o<.846?"E":"F"),emissions:r,resources:e};var o}();console.log("received emissions data");const t=document.createElement("div");t.setAttribute("data-testid","sustainabilityData"),t.textContent=JSON.stringify(e),document.body.appendChild(t)}function E(e){return new Promise((t=>setTimeout(t,e)))}export{O as reportEmissions}; No newline at end of file
const e=1.465e-9/3;var t=class{constructor(t){this.options=t,this.KWH_PER_BYTE_FOR_NETWORK=e}perByte(t,n){return t<1?0:n?72e-12*t*0+t*e*475:5.603333333333333e-10*t*519}},n={data:{AFG:132.53,AFRICA:559.42,ALB:24.29,DZA:634.61,ASM:611.11,AGO:174.73,ATG:611.11,ARG:394.62,ARM:264.54,ABW:561.22,ASEAN:554.5,ASIA:591.19,AUS:570.35,AUT:110.81,AZE:671.39,BHS:660.1,BHR:904.62,BGD:678.11,BRB:605.51,BLR:441.74,BEL:138.11,BLZ:225.81,BEN:584.07,BTN:23.33,BOL:489.14,BIH:600,BWA:847.91,BRA:105.51,BRN:893.91,BGR:335.33,BFA:467.53,BDI:250,CPV:558.14,KHM:417.71,CMR:305.42,CAN:161.43,CYM:642.86,CAF:0,TCD:628.57,CHL:353.52,CHN:585.82,COL:214.88,COM:642.86,COG:700,COD:24.46,COK:250,CRI:26.46,CIV:393.89,HRV:204.96,CUB:637.61,CYP:534.32,CZE:449.72,DNK:151.65,DJI:692.31,DMA:529.41,DOM:580.78,ECU:150.69,EGY:570.13,SLV:116.54,GNQ:591.84,ERI:631.58,EST:416.67,SWZ:172.41,ETH:24.64,EU:243.83,EUROPE:327.69,FLK:500,FRO:404.76,FJI:288.46,FIN:79.16,FRA:56.04,GUF:217.82,PYF:442.86,G20:482.92,G7:361.52,GAB:491.6,GMB:666.67,GEO:167.02,DEU:380.95,GHA:484,GRC:336.57,GRL:178.57,GRD:640,GLP:500,GUM:622.86,GTM:328.27,GIN:236.84,GNB:625,GUY:640.35,HTI:567.31,HND:282.27,HKG:699.5,HUN:204.19,ISL:27.68,IND:705.13,IDN:675.93,IRN:665.15,IRQ:688.81,IRL:290.81,ISR:582.93,ITA:330.72,JAM:555.56,JPN:512.81,JOR:540.92,KAZ:830.41,KEN:83.33,KIR:666.67,XKX:894.65,KWT:649.2,KGZ:147.29,LAO:265.51,"LATIN AMERICA AND CARIBBEAN":260.28,LVA:123.2,LBN:599.01,LSO:20,LBR:227.85,LBY:818.69,LTU:160.07,LUX:105.26,MAC:448.98,MDG:436.44,MWI:66.67,MYS:605.83,MDV:611.77,MLI:408,MLT:459.14,MTQ:523.18,MRT:464.71,MUS:632.48,MEX:475.36,"MIDDLE EAST":660.46,MDA:648.5,MNG:771.8,MNE:417.07,MSR:1e3,MAR:662.64,MOZ:135.65,MMR:483.57,NAM:59.26,NRU:750,NPL:24.44,NLD:267.62,NCL:660.58,NZL:110.89,NIC:265.12,NER:670.89,NGA:516.23,"NORTH AMERICA":356.01,PRK:389.59,MKD:565.35,NOR:30.08,OCEANIA:507.63,OECD:360.53,OMN:564.69,PAK:463.66,PSE:516.13,PAN:161.68,PNG:507.25,PRY:24.31,PER:251.74,POL:661.93,PRT:165.55,PRI:678.74,QAT:602.59,REU:572.82,ROU:240.58,RUS:436.28,RWA:316.33,KNA:636.36,LCA:666.67,SPM:600,VCT:529.41,WSM:473.68,STP:642.86,SAU:706.79,SEN:511.6,SRB:636.06,SYC:564.52,SLE:50,SGP:474,SVK:116.77,SVN:231.28,SLB:700,SOM:578.95,ZAF:729.67,KOR:441.65,SSD:629.03,ESP:174.05,LKA:509.78,SDN:263.16,SUR:349.28,SWE:40.7,CHE:34.84,SYR:701.66,TWN:639.53,TJK:116.86,TZA:339.25,THA:560.74,PHL:601.1,TGO:443.18,TON:625,TTO:681.53,TUN:564.62,TUR:464.59,TKM:1306.03,TCA:653.85,UGA:44.53,UKR:259.69,ARE:561.14,GBR:237.59,USA:385.98,URY:112.65,UZB:1167.6,VUT:571.43,VEN:185.8,VNM:409.8,VGB:647.06,VIR:632.35,WORLD:485.99,YEM:566.1,ZMB:111.97,ZWE:297.87},type:"average"};const r=n.data.WORLD,o=e=>parseFloat(e.toFixed(2));function i(e){var t,o,i,a,s,l;if("object"!=typeof e)throw new Error("Options must be an object");const u={};if(null==e?void 0:e.gridIntensity){u.gridIntensity={};const{device:d,dataCenter:c,network:g}=e.gridIntensity;(d||0===d)&&("object"==typeof d?(n.data[null==(t=d.country)?void 0:t.toUpperCase()]||(console.warn(`"${d.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.device={value:r}),u.gridIntensity.device={country:d.country,value:parseFloat(n.data[null==(o=d.country)?void 0:o.toUpperCase()])}):"number"==typeof d?u.gridIntensity.device={value:d}:(u.gridIntensity.device={value:r},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof d}. \nFalling back to global average grid intensity.`))),(c||0===c)&&("object"==typeof c?(n.data[null==(i=c.country)?void 0:i.toUpperCase()]||(console.warn(`"${c.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.dataCenter={value:r}),u.gridIntensity.dataCenter={country:c.country,value:parseFloat(n.data[null==(a=c.country)?void 0:a.toUpperCase()])}):"number"==typeof c?u.gridIntensity.dataCenter={value:c}:(u.gridIntensity.dataCenter={value:r},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof c}. \nFalling back to global average grid intensity.`))),(g||0===g)&&("object"==typeof g?(n.data[null==(s=g.country)?void 0:s.toUpperCase()]||(console.warn(`"${g.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \nFalling back to global average grid intensity.`),u.gridIntensity.network={value:r}),u.gridIntensity.network={country:g.country,value:parseFloat(n.data[null==(l=g.country)?void 0:l.toUpperCase()])}):"number"==typeof g?u.gridIntensity.network={value:g}:(u.gridIntensity.network={value:r},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof g}. \nFalling back to global average grid intensity.`)))}return((null==e?void 0:e.dataReloadRatio)||0===e.dataReloadRatio)&&("number"==typeof e.dataReloadRatio?e.dataReloadRatio>=0&&e.dataReloadRatio<=1?u.dataReloadRatio=e.dataReloadRatio:(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${e.dataReloadRatio}. \nFalling back to default value.`)):(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof e.dataReloadRatio}. \nFalling back to default value.`))),((null==e?void 0:e.firstVisitPercentage)||0===e.firstVisitPercentage)&&("number"==typeof e.firstVisitPercentage?e.firstVisitPercentage>=0&&e.firstVisitPercentage<=1?u.firstVisitPercentage=e.firstVisitPercentage:(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${e.firstVisitPercentage}. \nFalling back to default value.`)):(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof e.firstVisitPercentage}. \nFalling back to default value.`))),((null==e?void 0:e.returnVisitPercentage)||0===e.returnVisitPercentage)&&("number"==typeof e.returnVisitPercentage?e.returnVisitPercentage>=0&&e.returnVisitPercentage<=1?u.returnVisitPercentage=e.returnVisitPercentage:(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${e.returnVisitPercentage}. \nFalling back to default value.`)):(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof e.returnVisitPercentage}. \nFalling back to default value.`))),u}function a(e=""){return{"User-Agent":`co2js/0.15.0 ${e}`}}var s,l,u=Object.defineProperty,d=Object.defineProperties,c=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,v=(e,t,n)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))y.call(t,n)&&v(e,n,t[n]);if(g)for(var n of g(t))p.call(t,n)&&v(e,n,t[n]);return e},b=(e,t)=>d(e,c(t)),m=class{constructor(e){this.options=e}energyPerByteByComponent(e){const t=e/1e9*.81;return{consumerDeviceEnergy:.52*t,networkEnergy:.14*t,productionEnergy:.19*t,dataCenterEnergy:.15*t}}co2byComponent(e,t=r,n={}){let o=r,i=r,a=r,s=r;if(null==n?void 0:n.gridIntensity){const{device:e,network:t,dataCenter:r}=n.gridIntensity;((null==e?void 0:e.value)||0===(null==e?void 0:e.value))&&(o=e.value),((null==t?void 0:t.value)||0===(null==t?void 0:t.value))&&(i=t.value),((null==r?void 0:r.value)||0===(null==r?void 0:r.value))&&(a=r.value)}!0===t&&(a=50);const l={};for(const[t,n]of Object.entries(e))t.startsWith("dataCenterEnergy")?l[t.replace("Energy","CO2")]=n*a:t.startsWith("consumerDeviceEnergy")?l[t.replace("Energy","CO2")]=n*o:t.startsWith("networkEnergy")?l[t.replace("Energy","CO2")]=n*i:l[t.replace("Energy","CO2")]=n*s;return l}perByte(e,t=!1,n=!1,r={}){e<1&&(e=0);const o=this.energyPerByteByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}perVisit(e,t=!1,n=!1,r={}){const o=this.energyPerVisitByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}energyPerByte(e){const t=this.energyPerByteByComponent(e);return Object.values(t).reduce(((e,t)=>e+t))}energyPerVisitByComponent(e,t={},n=.75,r=.25,o=.02){(t.dataReloadRatio||0===t.dataReloadRatio)&&(o=t.dataReloadRatio),(t.firstVisitPercentage||0===t.firstVisitPercentage)&&(n=t.firstVisitPercentage),(t.returnVisitPercentage||0===t.returnVisitPercentage)&&(r=t.returnVisitPercentage);const i=this.energyPerByteByComponent(e),a={};Object.values(i);for(const[e,t]of Object.entries(i))a[`${e} - first`]=t*n,a[`${e} - subsequent`]=t*r*o;return a}energyPerVisit(e){let t=0,n=0;const r=Object.entries(this.energyPerVisitByComponent(e));for(const[e,n]of r)e.indexOf("first")>0&&(t+=n);for(const[e,t]of r)e.indexOf("subsequent")>0&&(n+=t);return t+n}emissionsPerVisitInGrams(e,t=r){return o(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:o(.52*e),networkEnergy:o(.14*e),dataCenterEnergy:o(.15*e),productionEnergy:o(.19*e)}}},h=class{constructor(e){if(this.model=new m,"1byte"===(null==e?void 0:e.model))this.model=new t;else if("swd"===(null==e?void 0:e.model))this.model=new m;else if(null==e?void 0:e.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment="segment"===(null==e?void 0:e.results)}perByte(e,t=!1){return this.model.perByte(e,t,this._segment)}perVisit(e,t=!1){var n;if(null==(n=this.model)?void 0:n.perVisit)return this.model.perVisit(e,t,this._segment);throw new Error("The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}perByteTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y;let p={};return n&&(p=i(n)),{co2:this.model.perByte(e,t,this._segment,p),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(s=null==(a=null==(o=null==p?void 0:p.gridIntensity)?void 0:o.network)?void 0:a.value)?s:r,dataCenter:t?50:null!=(d=null==(u=null==(l=null==p?void 0:p.gridIntensity)?void 0:l.dataCenter)?void 0:u.value)?d:r,production:r,device:null!=(y=null==(g=null==(c=null==p?void 0:p.gridIntensity)?void 0:c.device)?void 0:g.value)?y:r}}}}perVisitTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y,p,v,f,b;if(null==(o=this.model)?void 0:o.perVisit){let o={};return n&&(o=i(n)),{co2:this.model.perVisit(e,t,this._segment,o),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(l=null==(s=null==(a=null==o?void 0:o.gridIntensity)?void 0:a.network)?void 0:s.value)?l:r,dataCenter:t?50:null!=(c=null==(d=null==(u=null==o?void 0:o.gridIntensity)?void 0:u.dataCenter)?void 0:d.value)?c:r,production:r,device:null!=(p=null==(y=null==(g=null==o?void 0:o.gridIntensity)?void 0:g.device)?void 0:y.value)?p:r},dataReloadRatio:null!=(v=null==o?void 0:o.dataReloadRatio)?v:.02,firstVisitPercentage:null!=(f=null==o?void 0:o.firstVisitPercentage)?f:.75,returnVisitPercentage:null!=(b=null==o?void 0:o.returnVisitPercentage)?b:.25}}}throw new Error("The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}},R=Object.getOwnPropertyNames;const w=(s={"src/hosting-json.js"(e,t){function n(e,t){return t.indexOf(e)>-1?e:{url:e,green:!1}}t.exports={check:async function(e,t){return"string"==typeof e?function(e,t){return t.indexOf(e)>-1}(e,t):function(e,t){let n=[];for(let r of e)t.indexOf(r)>-1&&n.push(r);return n}(e,t)},greenDomainsFromResults:function(e){return Object.entries(e).filter((([e,t])=>t.green)).map((([e,t])=>t.url))},find:function(e,t){return"string"==typeof e?n(e,t):function(e,t){const r={};for(let o of e)r[o]=n(o,t);return r}(e,t)}}}},function(){return l||(0,s[R(s)[0]])((l={exports:{}}).exports,l),l.exports})();var P=function(e,t){const n="string"==typeof t?{userAgentIdentifier:t}:t;if((null==n?void 0:n.db)&&n.verbose)throw new Error("verbose mode cannot be used with a local lookup database");return"string"==typeof e?async function(e,t={}){const n=await fetch(`https://api.thegreenwebfoundation.org/greencheck/${e}`,{headers:a(t.userAgentIdentifier)});if(null==t?void 0:t.db)return w.check(e,t.db);const r=await n.json();return t.verbose?r:r.green}(e,n):async function(e,t={}){try{const r="https://api.thegreenwebfoundation.org/v2/greencheckmulti",o=JSON.stringify(e),i=await fetch(`${r}/${o}`,{headers:a(t.userAgentIdentifier)}),s=await i.json();return t.verbose?s:(n=s,Object.entries(n).filter((([e,t])=>t.green)).map((([e,t])=>t.url)))}catch(e){return t.verbose?{}:[]}var n}(e,n)},C=function(e,t){return P(e,t)};async function O(){console.log("reportEmissions called"),await async function(){return window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"}),E(2e3)}(),await E(2e3),console.log("getting emissions data");const e=await async function(){console.log("calculating...");const e=window.performance.getEntriesByType("resource").filter((e=>!(e.name||"").split("?")[0].endsWith("resource-checker.js"))),t=function(e){return e.reduce(((e,t)=>e+t.transferSize),0)}(e),n=await C(window.location.hostname),r=new h({model:"swd"}).perVisitTrace(t,n);return{pageWeight:t,carbonRating:(o=r.co2,o<.095?"A+":o<.186?"A":o<.341?"B":o<.493?"C":o<.656?"D":o<.846?"E":"F"),emissions:r,resources:e};var o}();console.log("received emissions data");const t=document.createElement("div");t.setAttribute("data-testid","sustainabilityData"),t.textContent=JSON.stringify(e),document.body.appendChild(t)}function E(e){return new Promise((t=>setTimeout(t,e)))}export{O as reportEmissions}; No newline at end of file
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

Variable 'o' is used before its declaration.

Copilot uses AI. Check for mistakes.
@@ -1 +1 @@
const e=1.465e-9/3;var t=class{constructor(t){this.options=t,this.KWH_PER_BYTE_FOR_NETWORK=e}perByte(t,n){return t<1?0:n?72e-12*t*0+t*e*475:5.603333333333333e-10*t*519}},n={data:{AFG:132.53,AFRICA:559.42,ALB:24.29,DZA:634.61,ASM:611.11,AGO:174.73,ATG:611.11,ARG:394.62,ARM:264.54,ABW:561.22,ASEAN:554.5,ASIA:591.19,AUS:570.35,AUT:110.81,AZE:671.39,BHS:660.1,BHR:904.62,BGD:678.11,BRB:605.51,BLR:441.74,BEL:138.11,BLZ:225.81,BEN:584.07,BTN:23.33,BOL:489.14,BIH:600,BWA:847.91,BRA:105.51,BRN:893.91,BGR:335.33,BFA:467.53,BDI:250,CPV:558.14,KHM:417.71,CMR:305.42,CAN:161.43,CYM:642.86,CAF:0,TCD:628.57,CHL:353.52,CHN:585.82,COL:214.88,COM:642.86,COG:700,COD:24.46,COK:250,CRI:26.46,CIV:393.89,HRV:204.96,CUB:637.61,CYP:534.32,CZE:449.72,DNK:151.65,DJI:692.31,DMA:529.41,DOM:580.78,ECU:150.69,EGY:570.13,SLV:116.54,GNQ:591.84,ERI:631.58,EST:416.67,SWZ:172.41,ETH:24.64,EU:243.83,EUROPE:327.69,FLK:500,FRO:404.76,FJI:288.46,FIN:79.16,FRA:56.04,GUF:217.82,PYF:442.86,G20:482.92,G7:361.52,GAB:491.6,GMB:666.67,GEO:167.02,DEU:380.95,GHA:484,GRC:336.57,GRL:178.57,GRD:640,GLP:500,GUM:622.86,GTM:328.27,GIN:236.84,GNB:625,GUY:640.35,HTI:567.31,HND:282.27,HKG:699.5,HUN:204.19,ISL:27.68,IND:705.13,IDN:675.93,IRN:665.15,IRQ:688.81,IRL:290.81,ISR:582.93,ITA:330.72,JAM:555.56,JPN:512.81,JOR:540.92,KAZ:830.41,KEN:83.33,KIR:666.67,XKX:894.65,KWT:649.2,KGZ:147.29,LAO:265.51,"LATIN AMERICA AND CARIBBEAN":260.28,LVA:123.2,LBN:599.01,LSO:20,LBR:227.85,LBY:818.69,LTU:160.07,LUX:105.26,MAC:448.98,MDG:436.44,MWI:66.67,MYS:605.83,MDV:611.77,MLI:408,MLT:459.14,MTQ:523.18,MRT:464.71,MUS:632.48,MEX:475.36,"MIDDLE EAST":660.46,MDA:648.5,MNG:771.8,MNE:417.07,MSR:1e3,MAR:662.64,MOZ:135.65,MMR:483.57,NAM:59.26,NRU:750,NPL:24.44,NLD:267.62,NCL:660.58,NZL:110.89,NIC:265.12,NER:670.89,NGA:516.23,"NORTH AMERICA":356.01,PRK:389.59,MKD:565.35,NOR:30.08,OCEANIA:507.63,OECD:360.53,OMN:564.69,PAK:463.66,PSE:516.13,PAN:161.68,PNG:507.25,PRY:24.31,PER:251.74,POL:661.93,PRT:165.55,PRI:678.74,QAT:602.59,REU:572.82,ROU:240.58,RUS:436.28,RWA:316.33,KNA:636.36,LCA:666.67,SPM:600,VCT:529.41,WSM:473.68,STP:642.86,SAU:706.79,SEN:511.6,SRB:636.06,SYC:564.52,SLE:50,SGP:474,SVK:116.77,SVN:231.28,SLB:700,SOM:578.95,ZAF:729.67,KOR:441.65,SSD:629.03,ESP:174.05,LKA:509.78,SDN:263.16,SUR:349.28,SWE:40.7,CHE:34.84,SYR:701.66,TWN:639.53,TJK:116.86,TZA:339.25,THA:560.74,PHL:601.1,TGO:443.18,TON:625,TTO:681.53,TUN:564.62,TUR:464.59,TKM:1306.03,TCA:653.85,UGA:44.53,UKR:259.69,ARE:561.14,GBR:237.59,USA:385.98,URY:112.65,UZB:1167.6,VUT:571.43,VEN:185.8,VNM:409.8,VGB:647.06,VIR:632.35,WORLD:485.99,YEM:566.1,ZMB:111.97,ZWE:297.87},type:"average"};const r=n.data.WORLD,o=e=>parseFloat(e.toFixed(2));function i(e){var t,o,i,a,s,l;if("object"!=typeof e)throw new Error("Options must be an object");const u={};if(null==e?void 0:e.gridIntensity){u.gridIntensity={};const{device:d,dataCenter:c,network:g}=e.gridIntensity;(d||0===d)&&("object"==typeof d?(n.data[null==(t=d.country)?void 0:t.toUpperCase()]||(console.warn(`"${d.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.device={value:r}),u.gridIntensity.device={country:d.country,value:parseFloat(n.data[null==(o=d.country)?void 0:o.toUpperCase()])}):"number"==typeof d?u.gridIntensity.device={value:d}:(u.gridIntensity.device={value:r},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof d}. \nFalling back to global average grid intensity.`))),(c||0===c)&&("object"==typeof c?(n.data[null==(i=c.country)?void 0:i.toUpperCase()]||(console.warn(`"${c.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.dataCenter={value:r}),u.gridIntensity.dataCenter={country:c.country,value:parseFloat(n.data[null==(a=c.country)?void 0:a.toUpperCase()])}):"number"==typeof c?u.gridIntensity.dataCenter={value:c}:(u.gridIntensity.dataCenter={value:r},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof c}. \nFalling back to global average grid intensity.`))),(g||0===g)&&("object"==typeof g?(n.data[null==(s=g.country)?void 0:s.toUpperCase()]||(console.warn(`"${g.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \nFalling back to global average grid intensity.`),u.gridIntensity.network={value:r}),u.gridIntensity.network={country:g.country,value:parseFloat(n.data[null==(l=g.country)?void 0:l.toUpperCase()])}):"number"==typeof g?u.gridIntensity.network={value:g}:(u.gridIntensity.network={value:r},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof g}. \nFalling back to global average grid intensity.`)))}return((null==e?void 0:e.dataReloadRatio)||0===e.dataReloadRatio)&&("number"==typeof e.dataReloadRatio?e.dataReloadRatio>=0&&e.dataReloadRatio<=1?u.dataReloadRatio=e.dataReloadRatio:(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${e.dataReloadRatio}. \nFalling back to default value.`)):(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof e.dataReloadRatio}. \nFalling back to default value.`))),((null==e?void 0:e.firstVisitPercentage)||0===e.firstVisitPercentage)&&("number"==typeof e.firstVisitPercentage?e.firstVisitPercentage>=0&&e.firstVisitPercentage<=1?u.firstVisitPercentage=e.firstVisitPercentage:(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${e.firstVisitPercentage}. \nFalling back to default value.`)):(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof e.firstVisitPercentage}. \nFalling back to default value.`))),((null==e?void 0:e.returnVisitPercentage)||0===e.returnVisitPercentage)&&("number"==typeof e.returnVisitPercentage?e.returnVisitPercentage>=0&&e.returnVisitPercentage<=1?u.returnVisitPercentage=e.returnVisitPercentage:(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${e.returnVisitPercentage}. \nFalling back to default value.`)):(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof e.returnVisitPercentage}. \nFalling back to default value.`))),u}function a(e=""){return{"User-Agent":`co2js/0.15.0 ${e}`}}var s,l,u=Object.defineProperty,d=Object.defineProperties,c=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,v=(e,t,n)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))y.call(t,n)&&v(e,n,t[n]);if(g)for(var n of g(t))p.call(t,n)&&v(e,n,t[n]);return e},b=(e,t)=>d(e,c(t)),m=class{constructor(e){this.options=e}energyPerByteByComponent(e){const t=e/1e9*.81;return{consumerDeviceEnergy:.52*t,networkEnergy:.14*t,productionEnergy:.19*t,dataCenterEnergy:.15*t}}co2byComponent(e,t=r,n={}){let o=r,i=r,a=r,s=r;if(null==n?void 0:n.gridIntensity){const{device:e,network:t,dataCenter:r}=n.gridIntensity;((null==e?void 0:e.value)||0===(null==e?void 0:e.value))&&(o=e.value),((null==t?void 0:t.value)||0===(null==t?void 0:t.value))&&(i=t.value),((null==r?void 0:r.value)||0===(null==r?void 0:r.value))&&(a=r.value)}!0===t&&(a=50);const l={};for(const[t,n]of Object.entries(e))t.startsWith("dataCenterEnergy")?l[t.replace("Energy","CO2")]=n*a:t.startsWith("consumerDeviceEnergy")?l[t.replace("Energy","CO2")]=n*o:t.startsWith("networkEnergy")?l[t.replace("Energy","CO2")]=n*i:l[t.replace("Energy","CO2")]=n*s;return l}perByte(e,t=!1,n=!1,r={}){e<1&&(e=0);const o=this.energyPerByteByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}perVisit(e,t=!1,n=!1,r={}){const o=this.energyPerVisitByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}energyPerByte(e){const t=this.energyPerByteByComponent(e);return Object.values(t).reduce(((e,t)=>e+t))}energyPerVisitByComponent(e,t={},n=.75,r=.25,o=.02){(t.dataReloadRatio||0===t.dataReloadRatio)&&(o=t.dataReloadRatio),(t.firstVisitPercentage||0===t.firstVisitPercentage)&&(n=t.firstVisitPercentage),(t.returnVisitPercentage||0===t.returnVisitPercentage)&&(r=t.returnVisitPercentage);const i=this.energyPerByteByComponent(e),a={};Object.values(i);for(const[e,t]of Object.entries(i))a[`${e} - first`]=t*n,a[`${e} - subsequent`]=t*r*o;return a}energyPerVisit(e){let t=0,n=0;const r=Object.entries(this.energyPerVisitByComponent(e));for(const[e,n]of r)e.indexOf("first")>0&&(t+=n);for(const[e,t]of r)e.indexOf("subsequent")>0&&(n+=t);return t+n}emissionsPerVisitInGrams(e,t=r){return o(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:o(.52*e),networkEnergy:o(.14*e),dataCenterEnergy:o(.15*e),productionEnergy:o(.19*e)}}},h=class{constructor(e){if(this.model=new m,"1byte"===(null==e?void 0:e.model))this.model=new t;else if("swd"===(null==e?void 0:e.model))this.model=new m;else if(null==e?void 0:e.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment="segment"===(null==e?void 0:e.results)}perByte(e,t=!1){return this.model.perByte(e,t,this._segment)}perVisit(e,t=!1){var n;if(null==(n=this.model)?void 0:n.perVisit)return this.model.perVisit(e,t,this._segment);throw new Error("The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}perByteTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y;let p={};return n&&(p=i(n)),{co2:this.model.perByte(e,t,this._segment,p),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(s=null==(a=null==(o=null==p?void 0:p.gridIntensity)?void 0:o.network)?void 0:a.value)?s:r,dataCenter:t?50:null!=(d=null==(u=null==(l=null==p?void 0:p.gridIntensity)?void 0:l.dataCenter)?void 0:u.value)?d:r,production:r,device:null!=(y=null==(g=null==(c=null==p?void 0:p.gridIntensity)?void 0:c.device)?void 0:g.value)?y:r}}}}perVisitTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y,p,v,f,b;if(null==(o=this.model)?void 0:o.perVisit){let o={};return n&&(o=i(n)),{co2:this.model.perVisit(e,t,this._segment,o),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(l=null==(s=null==(a=null==o?void 0:o.gridIntensity)?void 0:a.network)?void 0:s.value)?l:r,dataCenter:t?50:null!=(c=null==(d=null==(u=null==o?void 0:o.gridIntensity)?void 0:u.dataCenter)?void 0:d.value)?c:r,production:r,device:null!=(p=null==(y=null==(g=null==o?void 0:o.gridIntensity)?void 0:g.device)?void 0:y.value)?p:r},dataReloadRatio:null!=(v=null==o?void 0:o.dataReloadRatio)?v:.02,firstVisitPercentage:null!=(f=null==o?void 0:o.firstVisitPercentage)?f:.75,returnVisitPercentage:null!=(b=null==o?void 0:o.returnVisitPercentage)?b:.25}}}throw new Error("The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}},R=Object.getOwnPropertyNames;const w=(s={"src/hosting-json.js"(e,t){function n(e,t){return t.indexOf(e)>-1?e:{url:e,green:!1}}t.exports={check:async function(e,t){return"string"==typeof e?function(e,t){return t.indexOf(e)>-1}(e,t):function(e,t){let n=[];for(let r of e)t.indexOf(r)>-1&&n.push(r);return n}(e,t)},greenDomainsFromResults:function(e){return Object.entries(e).filter((([e,t])=>t.green)).map((([e,t])=>t.url))},find:function(e,t){return"string"==typeof e?n(e,t):function(e,t){const r={};for(let o of e)r[o]=n(o,t);return r}(e,t)}}}},function(){return l||(0,s[R(s)[0]])((l={exports:{}}).exports,l),l.exports})();var P=function(e,t){const n="string"==typeof t?{userAgentIdentifier:t}:t;if((null==n?void 0:n.db)&&n.verbose)throw new Error("verbose mode cannot be used with a local lookup database");return"string"==typeof e?async function(e,t={}){const n=await fetch(`https://api.thegreenwebfoundation.org/greencheck/${e}`,{headers:a(t.userAgentIdentifier)});if(null==t?void 0:t.db)return w.check(e,t.db);const r=await n.json();return t.verbose?r:r.green}(e,n):async function(e,t={}){try{const r="https://api.thegreenwebfoundation.org/v2/greencheckmulti",o=JSON.stringify(e),i=await fetch(`${r}/${o}`,{headers:a(t.userAgentIdentifier)}),s=await i.json();return t.verbose?s:(n=s,Object.entries(n).filter((([e,t])=>t.green)).map((([e,t])=>t.url)))}catch(e){return t.verbose?{}:[]}var n}(e,n)},C=function(e,t){return P(e,t)};async function O(){console.log("reportEmissions called"),await async function(){return window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"}),E(2e3)}(),await E(2e3),console.log("getting emissions data");const e=await async function(){console.log("calculating...");const e=window.performance.getEntriesByType("resource").filter((e=>!(e.name||"").includes("resource-checker.js"))),t=function(e){return e.reduce(((e,t)=>e+t.transferSize),0)}(e),n=await C(window.location.hostname),r=new h({model:"swd"}).perVisitTrace(t,n);return{pageWeight:t,carbonRating:(o=r.co2,o<.095?"A+":o<.186?"A":o<.341?"B":o<.493?"C":o<.656?"D":o<.846?"E":"F"),emissions:r,resources:e};var o}();console.log("received emissions data");const t=document.createElement("div");t.setAttribute("data-testid","sustainabilityData"),t.textContent=JSON.stringify(e),document.body.appendChild(t)}function E(e){return new Promise((t=>setTimeout(t,e)))}export{O as reportEmissions}; No newline at end of file
const e=1.465e-9/3;var t=class{constructor(t){this.options=t,this.KWH_PER_BYTE_FOR_NETWORK=e}perByte(t,n){return t<1?0:n?72e-12*t*0+t*e*475:5.603333333333333e-10*t*519}},n={data:{AFG:132.53,AFRICA:559.42,ALB:24.29,DZA:634.61,ASM:611.11,AGO:174.73,ATG:611.11,ARG:394.62,ARM:264.54,ABW:561.22,ASEAN:554.5,ASIA:591.19,AUS:570.35,AUT:110.81,AZE:671.39,BHS:660.1,BHR:904.62,BGD:678.11,BRB:605.51,BLR:441.74,BEL:138.11,BLZ:225.81,BEN:584.07,BTN:23.33,BOL:489.14,BIH:600,BWA:847.91,BRA:105.51,BRN:893.91,BGR:335.33,BFA:467.53,BDI:250,CPV:558.14,KHM:417.71,CMR:305.42,CAN:161.43,CYM:642.86,CAF:0,TCD:628.57,CHL:353.52,CHN:585.82,COL:214.88,COM:642.86,COG:700,COD:24.46,COK:250,CRI:26.46,CIV:393.89,HRV:204.96,CUB:637.61,CYP:534.32,CZE:449.72,DNK:151.65,DJI:692.31,DMA:529.41,DOM:580.78,ECU:150.69,EGY:570.13,SLV:116.54,GNQ:591.84,ERI:631.58,EST:416.67,SWZ:172.41,ETH:24.64,EU:243.83,EUROPE:327.69,FLK:500,FRO:404.76,FJI:288.46,FIN:79.16,FRA:56.04,GUF:217.82,PYF:442.86,G20:482.92,G7:361.52,GAB:491.6,GMB:666.67,GEO:167.02,DEU:380.95,GHA:484,GRC:336.57,GRL:178.57,GRD:640,GLP:500,GUM:622.86,GTM:328.27,GIN:236.84,GNB:625,GUY:640.35,HTI:567.31,HND:282.27,HKG:699.5,HUN:204.19,ISL:27.68,IND:705.13,IDN:675.93,IRN:665.15,IRQ:688.81,IRL:290.81,ISR:582.93,ITA:330.72,JAM:555.56,JPN:512.81,JOR:540.92,KAZ:830.41,KEN:83.33,KIR:666.67,XKX:894.65,KWT:649.2,KGZ:147.29,LAO:265.51,"LATIN AMERICA AND CARIBBEAN":260.28,LVA:123.2,LBN:599.01,LSO:20,LBR:227.85,LBY:818.69,LTU:160.07,LUX:105.26,MAC:448.98,MDG:436.44,MWI:66.67,MYS:605.83,MDV:611.77,MLI:408,MLT:459.14,MTQ:523.18,MRT:464.71,MUS:632.48,MEX:475.36,"MIDDLE EAST":660.46,MDA:648.5,MNG:771.8,MNE:417.07,MSR:1e3,MAR:662.64,MOZ:135.65,MMR:483.57,NAM:59.26,NRU:750,NPL:24.44,NLD:267.62,NCL:660.58,NZL:110.89,NIC:265.12,NER:670.89,NGA:516.23,"NORTH AMERICA":356.01,PRK:389.59,MKD:565.35,NOR:30.08,OCEANIA:507.63,OECD:360.53,OMN:564.69,PAK:463.66,PSE:516.13,PAN:161.68,PNG:507.25,PRY:24.31,PER:251.74,POL:661.93,PRT:165.55,PRI:678.74,QAT:602.59,REU:572.82,ROU:240.58,RUS:436.28,RWA:316.33,KNA:636.36,LCA:666.67,SPM:600,VCT:529.41,WSM:473.68,STP:642.86,SAU:706.79,SEN:511.6,SRB:636.06,SYC:564.52,SLE:50,SGP:474,SVK:116.77,SVN:231.28,SLB:700,SOM:578.95,ZAF:729.67,KOR:441.65,SSD:629.03,ESP:174.05,LKA:509.78,SDN:263.16,SUR:349.28,SWE:40.7,CHE:34.84,SYR:701.66,TWN:639.53,TJK:116.86,TZA:339.25,THA:560.74,PHL:601.1,TGO:443.18,TON:625,TTO:681.53,TUN:564.62,TUR:464.59,TKM:1306.03,TCA:653.85,UGA:44.53,UKR:259.69,ARE:561.14,GBR:237.59,USA:385.98,URY:112.65,UZB:1167.6,VUT:571.43,VEN:185.8,VNM:409.8,VGB:647.06,VIR:632.35,WORLD:485.99,YEM:566.1,ZMB:111.97,ZWE:297.87},type:"average"};const r=n.data.WORLD,o=e=>parseFloat(e.toFixed(2));function i(e){var t,o,i,a,s,l;if("object"!=typeof e)throw new Error("Options must be an object");const u={};if(null==e?void 0:e.gridIntensity){u.gridIntensity={};const{device:d,dataCenter:c,network:g}=e.gridIntensity;(d||0===d)&&("object"==typeof d?(n.data[null==(t=d.country)?void 0:t.toUpperCase()]||(console.warn(`"${d.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.device={value:r}),u.gridIntensity.device={country:d.country,value:parseFloat(n.data[null==(o=d.country)?void 0:o.toUpperCase()])}):"number"==typeof d?u.gridIntensity.device={value:d}:(u.gridIntensity.device={value:r},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof d}. \nFalling back to global average grid intensity.`))),(c||0===c)&&("object"==typeof c?(n.data[null==(i=c.country)?void 0:i.toUpperCase()]||(console.warn(`"${c.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.dataCenter={value:r}),u.gridIntensity.dataCenter={country:c.country,value:parseFloat(n.data[null==(a=c.country)?void 0:a.toUpperCase()])}):"number"==typeof c?u.gridIntensity.dataCenter={value:c}:(u.gridIntensity.dataCenter={value:r},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof c}. \nFalling back to global average grid intensity.`))),(g||0===g)&&("object"==typeof g?(n.data[null==(s=g.country)?void 0:s.toUpperCase()]||(console.warn(`"${g.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \nFalling back to global average grid intensity.`),u.gridIntensity.network={value:r}),u.gridIntensity.network={country:g.country,value:parseFloat(n.data[null==(l=g.country)?void 0:l.toUpperCase()])}):"number"==typeof g?u.gridIntensity.network={value:g}:(u.gridIntensity.network={value:r},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof g}. \nFalling back to global average grid intensity.`)))}return((null==e?void 0:e.dataReloadRatio)||0===e.dataReloadRatio)&&("number"==typeof e.dataReloadRatio?e.dataReloadRatio>=0&&e.dataReloadRatio<=1?u.dataReloadRatio=e.dataReloadRatio:(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${e.dataReloadRatio}. \nFalling back to default value.`)):(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof e.dataReloadRatio}. \nFalling back to default value.`))),((null==e?void 0:e.firstVisitPercentage)||0===e.firstVisitPercentage)&&("number"==typeof e.firstVisitPercentage?e.firstVisitPercentage>=0&&e.firstVisitPercentage<=1?u.firstVisitPercentage=e.firstVisitPercentage:(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${e.firstVisitPercentage}. \nFalling back to default value.`)):(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof e.firstVisitPercentage}. \nFalling back to default value.`))),((null==e?void 0:e.returnVisitPercentage)||0===e.returnVisitPercentage)&&("number"==typeof e.returnVisitPercentage?e.returnVisitPercentage>=0&&e.returnVisitPercentage<=1?u.returnVisitPercentage=e.returnVisitPercentage:(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${e.returnVisitPercentage}. \nFalling back to default value.`)):(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof e.returnVisitPercentage}. \nFalling back to default value.`))),u}function a(e=""){return{"User-Agent":`co2js/0.15.0 ${e}`}}var s,l,u=Object.defineProperty,d=Object.defineProperties,c=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,v=(e,t,n)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))y.call(t,n)&&v(e,n,t[n]);if(g)for(var n of g(t))p.call(t,n)&&v(e,n,t[n]);return e},b=(e,t)=>d(e,c(t)),m=class{constructor(e){this.options=e}energyPerByteByComponent(e){const t=e/1e9*.81;return{consumerDeviceEnergy:.52*t,networkEnergy:.14*t,productionEnergy:.19*t,dataCenterEnergy:.15*t}}co2byComponent(e,t=r,n={}){let o=r,i=r,a=r,s=r;if(null==n?void 0:n.gridIntensity){const{device:e,network:t,dataCenter:r}=n.gridIntensity;((null==e?void 0:e.value)||0===(null==e?void 0:e.value))&&(o=e.value),((null==t?void 0:t.value)||0===(null==t?void 0:t.value))&&(i=t.value),((null==r?void 0:r.value)||0===(null==r?void 0:r.value))&&(a=r.value)}!0===t&&(a=50);const l={};for(const[t,n]of Object.entries(e))t.startsWith("dataCenterEnergy")?l[t.replace("Energy","CO2")]=n*a:t.startsWith("consumerDeviceEnergy")?l[t.replace("Energy","CO2")]=n*o:t.startsWith("networkEnergy")?l[t.replace("Energy","CO2")]=n*i:l[t.replace("Energy","CO2")]=n*s;return l}perByte(e,t=!1,n=!1,r={}){e<1&&(e=0);const o=this.energyPerByteByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}perVisit(e,t=!1,n=!1,r={}){const o=this.energyPerVisitByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}energyPerByte(e){const t=this.energyPerByteByComponent(e);return Object.values(t).reduce(((e,t)=>e+t))}energyPerVisitByComponent(e,t={},n=.75,r=.25,o=.02){(t.dataReloadRatio||0===t.dataReloadRatio)&&(o=t.dataReloadRatio),(t.firstVisitPercentage||0===t.firstVisitPercentage)&&(n=t.firstVisitPercentage),(t.returnVisitPercentage||0===t.returnVisitPercentage)&&(r=t.returnVisitPercentage);const i=this.energyPerByteByComponent(e),a={};Object.values(i);for(const[e,t]of Object.entries(i))a[`${e} - first`]=t*n,a[`${e} - subsequent`]=t*r*o;return a}energyPerVisit(e){let t=0,n=0;const r=Object.entries(this.energyPerVisitByComponent(e));for(const[e,n]of r)e.indexOf("first")>0&&(t+=n);for(const[e,t]of r)e.indexOf("subsequent")>0&&(n+=t);return t+n}emissionsPerVisitInGrams(e,t=r){return o(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:o(.52*e),networkEnergy:o(.14*e),dataCenterEnergy:o(.15*e),productionEnergy:o(.19*e)}}},h=class{constructor(e){if(this.model=new m,"1byte"===(null==e?void 0:e.model))this.model=new t;else if("swd"===(null==e?void 0:e.model))this.model=new m;else if(null==e?void 0:e.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment="segment"===(null==e?void 0:e.results)}perByte(e,t=!1){return this.model.perByte(e,t,this._segment)}perVisit(e,t=!1){var n;if(null==(n=this.model)?void 0:n.perVisit)return this.model.perVisit(e,t,this._segment);throw new Error("The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}perByteTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y;let p={};return n&&(p=i(n)),{co2:this.model.perByte(e,t,this._segment,p),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(s=null==(a=null==(o=null==p?void 0:p.gridIntensity)?void 0:o.network)?void 0:a.value)?s:r,dataCenter:t?50:null!=(d=null==(u=null==(l=null==p?void 0:p.gridIntensity)?void 0:l.dataCenter)?void 0:u.value)?d:r,production:r,device:null!=(y=null==(g=null==(c=null==p?void 0:p.gridIntensity)?void 0:c.device)?void 0:g.value)?y:r}}}}perVisitTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y,p,v,f,b;if(null==(o=this.model)?void 0:o.perVisit){let o={};return n&&(o=i(n)),{co2:this.model.perVisit(e,t,this._segment,o),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(l=null==(s=null==(a=null==o?void 0:o.gridIntensity)?void 0:a.network)?void 0:s.value)?l:r,dataCenter:t?50:null!=(c=null==(d=null==(u=null==o?void 0:o.gridIntensity)?void 0:u.dataCenter)?void 0:d.value)?c:r,production:r,device:null!=(p=null==(y=null==(g=null==o?void 0:o.gridIntensity)?void 0:g.device)?void 0:y.value)?p:r},dataReloadRatio:null!=(v=null==o?void 0:o.dataReloadRatio)?v:.02,firstVisitPercentage:null!=(f=null==o?void 0:o.firstVisitPercentage)?f:.75,returnVisitPercentage:null!=(b=null==o?void 0:o.returnVisitPercentage)?b:.25}}}throw new Error("The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}},R=Object.getOwnPropertyNames;const w=(s={"src/hosting-json.js"(e,t){function n(e,t){return t.indexOf(e)>-1?e:{url:e,green:!1}}t.exports={check:async function(e,t){return"string"==typeof e?function(e,t){return t.indexOf(e)>-1}(e,t):function(e,t){let n=[];for(let r of e)t.indexOf(r)>-1&&n.push(r);return n}(e,t)},greenDomainsFromResults:function(e){return Object.entries(e).filter((([e,t])=>t.green)).map((([e,t])=>t.url))},find:function(e,t){return"string"==typeof e?n(e,t):function(e,t){const r={};for(let o of e)r[o]=n(o,t);return r}(e,t)}}}},function(){return l||(0,s[R(s)[0]])((l={exports:{}}).exports,l),l.exports})();var P=function(e,t){const n="string"==typeof t?{userAgentIdentifier:t}:t;if((null==n?void 0:n.db)&&n.verbose)throw new Error("verbose mode cannot be used with a local lookup database");return"string"==typeof e?async function(e,t={}){const n=await fetch(`https://api.thegreenwebfoundation.org/greencheck/${e}`,{headers:a(t.userAgentIdentifier)});if(null==t?void 0:t.db)return w.check(e,t.db);const r=await n.json();return t.verbose?r:r.green}(e,n):async function(e,t={}){try{const r="https://api.thegreenwebfoundation.org/v2/greencheckmulti",o=JSON.stringify(e),i=await fetch(`${r}/${o}`,{headers:a(t.userAgentIdentifier)}),s=await i.json();return t.verbose?s:(n=s,Object.entries(n).filter((([e,t])=>t.green)).map((([e,t])=>t.url)))}catch(e){return t.verbose?{}:[]}var n}(e,n)},C=function(e,t){return P(e,t)};async function O(){console.log("reportEmissions called"),await async function(){return window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"}),E(2e3)}(),await E(2e3),console.log("getting emissions data");const e=await async function(){console.log("calculating...");const e=window.performance.getEntriesByType("resource").filter((e=>!(e.name||"").split("?")[0].endsWith("resource-checker.js"))),t=function(e){return e.reduce(((e,t)=>e+t.transferSize),0)}(e),n=await C(window.location.hostname),r=new h({model:"swd"}).perVisitTrace(t,n);return{pageWeight:t,carbonRating:(o=r.co2,o<.095?"A+":o<.186?"A":o<.341?"B":o<.493?"C":o<.656?"D":o<.846?"E":"F"),emissions:r,resources:e};var o}();console.log("received emissions data");const t=document.createElement("div");t.setAttribute("data-testid","sustainabilityData"),t.textContent=JSON.stringify(e),document.body.appendChild(t)}function E(e){return new Promise((t=>setTimeout(t,e)))}export{O as reportEmissions}; No newline at end of file
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

This statement is unreachable.

Copilot uses AI. Check for mistakes.
@@ -1 +1 @@
const e=1.465e-9/3;var t=class{constructor(t){this.options=t,this.KWH_PER_BYTE_FOR_NETWORK=e}perByte(t,n){return t<1?0:n?72e-12*t*0+t*e*475:5.603333333333333e-10*t*519}},n={data:{AFG:132.53,AFRICA:559.42,ALB:24.29,DZA:634.61,ASM:611.11,AGO:174.73,ATG:611.11,ARG:394.62,ARM:264.54,ABW:561.22,ASEAN:554.5,ASIA:591.19,AUS:570.35,AUT:110.81,AZE:671.39,BHS:660.1,BHR:904.62,BGD:678.11,BRB:605.51,BLR:441.74,BEL:138.11,BLZ:225.81,BEN:584.07,BTN:23.33,BOL:489.14,BIH:600,BWA:847.91,BRA:105.51,BRN:893.91,BGR:335.33,BFA:467.53,BDI:250,CPV:558.14,KHM:417.71,CMR:305.42,CAN:161.43,CYM:642.86,CAF:0,TCD:628.57,CHL:353.52,CHN:585.82,COL:214.88,COM:642.86,COG:700,COD:24.46,COK:250,CRI:26.46,CIV:393.89,HRV:204.96,CUB:637.61,CYP:534.32,CZE:449.72,DNK:151.65,DJI:692.31,DMA:529.41,DOM:580.78,ECU:150.69,EGY:570.13,SLV:116.54,GNQ:591.84,ERI:631.58,EST:416.67,SWZ:172.41,ETH:24.64,EU:243.83,EUROPE:327.69,FLK:500,FRO:404.76,FJI:288.46,FIN:79.16,FRA:56.04,GUF:217.82,PYF:442.86,G20:482.92,G7:361.52,GAB:491.6,GMB:666.67,GEO:167.02,DEU:380.95,GHA:484,GRC:336.57,GRL:178.57,GRD:640,GLP:500,GUM:622.86,GTM:328.27,GIN:236.84,GNB:625,GUY:640.35,HTI:567.31,HND:282.27,HKG:699.5,HUN:204.19,ISL:27.68,IND:705.13,IDN:675.93,IRN:665.15,IRQ:688.81,IRL:290.81,ISR:582.93,ITA:330.72,JAM:555.56,JPN:512.81,JOR:540.92,KAZ:830.41,KEN:83.33,KIR:666.67,XKX:894.65,KWT:649.2,KGZ:147.29,LAO:265.51,"LATIN AMERICA AND CARIBBEAN":260.28,LVA:123.2,LBN:599.01,LSO:20,LBR:227.85,LBY:818.69,LTU:160.07,LUX:105.26,MAC:448.98,MDG:436.44,MWI:66.67,MYS:605.83,MDV:611.77,MLI:408,MLT:459.14,MTQ:523.18,MRT:464.71,MUS:632.48,MEX:475.36,"MIDDLE EAST":660.46,MDA:648.5,MNG:771.8,MNE:417.07,MSR:1e3,MAR:662.64,MOZ:135.65,MMR:483.57,NAM:59.26,NRU:750,NPL:24.44,NLD:267.62,NCL:660.58,NZL:110.89,NIC:265.12,NER:670.89,NGA:516.23,"NORTH AMERICA":356.01,PRK:389.59,MKD:565.35,NOR:30.08,OCEANIA:507.63,OECD:360.53,OMN:564.69,PAK:463.66,PSE:516.13,PAN:161.68,PNG:507.25,PRY:24.31,PER:251.74,POL:661.93,PRT:165.55,PRI:678.74,QAT:602.59,REU:572.82,ROU:240.58,RUS:436.28,RWA:316.33,KNA:636.36,LCA:666.67,SPM:600,VCT:529.41,WSM:473.68,STP:642.86,SAU:706.79,SEN:511.6,SRB:636.06,SYC:564.52,SLE:50,SGP:474,SVK:116.77,SVN:231.28,SLB:700,SOM:578.95,ZAF:729.67,KOR:441.65,SSD:629.03,ESP:174.05,LKA:509.78,SDN:263.16,SUR:349.28,SWE:40.7,CHE:34.84,SYR:701.66,TWN:639.53,TJK:116.86,TZA:339.25,THA:560.74,PHL:601.1,TGO:443.18,TON:625,TTO:681.53,TUN:564.62,TUR:464.59,TKM:1306.03,TCA:653.85,UGA:44.53,UKR:259.69,ARE:561.14,GBR:237.59,USA:385.98,URY:112.65,UZB:1167.6,VUT:571.43,VEN:185.8,VNM:409.8,VGB:647.06,VIR:632.35,WORLD:485.99,YEM:566.1,ZMB:111.97,ZWE:297.87},type:"average"};const r=n.data.WORLD,o=e=>parseFloat(e.toFixed(2));function i(e){var t,o,i,a,s,l;if("object"!=typeof e)throw new Error("Options must be an object");const u={};if(null==e?void 0:e.gridIntensity){u.gridIntensity={};const{device:d,dataCenter:c,network:g}=e.gridIntensity;(d||0===d)&&("object"==typeof d?(n.data[null==(t=d.country)?void 0:t.toUpperCase()]||(console.warn(`"${d.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.device={value:r}),u.gridIntensity.device={country:d.country,value:parseFloat(n.data[null==(o=d.country)?void 0:o.toUpperCase()])}):"number"==typeof d?u.gridIntensity.device={value:d}:(u.gridIntensity.device={value:r},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof d}. \nFalling back to global average grid intensity.`))),(c||0===c)&&("object"==typeof c?(n.data[null==(i=c.country)?void 0:i.toUpperCase()]||(console.warn(`"${c.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.dataCenter={value:r}),u.gridIntensity.dataCenter={country:c.country,value:parseFloat(n.data[null==(a=c.country)?void 0:a.toUpperCase()])}):"number"==typeof c?u.gridIntensity.dataCenter={value:c}:(u.gridIntensity.dataCenter={value:r},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof c}. \nFalling back to global average grid intensity.`))),(g||0===g)&&("object"==typeof g?(n.data[null==(s=g.country)?void 0:s.toUpperCase()]||(console.warn(`"${g.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \nFalling back to global average grid intensity.`),u.gridIntensity.network={value:r}),u.gridIntensity.network={country:g.country,value:parseFloat(n.data[null==(l=g.country)?void 0:l.toUpperCase()])}):"number"==typeof g?u.gridIntensity.network={value:g}:(u.gridIntensity.network={value:r},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof g}. \nFalling back to global average grid intensity.`)))}return((null==e?void 0:e.dataReloadRatio)||0===e.dataReloadRatio)&&("number"==typeof e.dataReloadRatio?e.dataReloadRatio>=0&&e.dataReloadRatio<=1?u.dataReloadRatio=e.dataReloadRatio:(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${e.dataReloadRatio}. \nFalling back to default value.`)):(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof e.dataReloadRatio}. \nFalling back to default value.`))),((null==e?void 0:e.firstVisitPercentage)||0===e.firstVisitPercentage)&&("number"==typeof e.firstVisitPercentage?e.firstVisitPercentage>=0&&e.firstVisitPercentage<=1?u.firstVisitPercentage=e.firstVisitPercentage:(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${e.firstVisitPercentage}. \nFalling back to default value.`)):(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof e.firstVisitPercentage}. \nFalling back to default value.`))),((null==e?void 0:e.returnVisitPercentage)||0===e.returnVisitPercentage)&&("number"==typeof e.returnVisitPercentage?e.returnVisitPercentage>=0&&e.returnVisitPercentage<=1?u.returnVisitPercentage=e.returnVisitPercentage:(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${e.returnVisitPercentage}. \nFalling back to default value.`)):(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof e.returnVisitPercentage}. \nFalling back to default value.`))),u}function a(e=""){return{"User-Agent":`co2js/0.15.0 ${e}`}}var s,l,u=Object.defineProperty,d=Object.defineProperties,c=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,v=(e,t,n)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))y.call(t,n)&&v(e,n,t[n]);if(g)for(var n of g(t))p.call(t,n)&&v(e,n,t[n]);return e},b=(e,t)=>d(e,c(t)),m=class{constructor(e){this.options=e}energyPerByteByComponent(e){const t=e/1e9*.81;return{consumerDeviceEnergy:.52*t,networkEnergy:.14*t,productionEnergy:.19*t,dataCenterEnergy:.15*t}}co2byComponent(e,t=r,n={}){let o=r,i=r,a=r,s=r;if(null==n?void 0:n.gridIntensity){const{device:e,network:t,dataCenter:r}=n.gridIntensity;((null==e?void 0:e.value)||0===(null==e?void 0:e.value))&&(o=e.value),((null==t?void 0:t.value)||0===(null==t?void 0:t.value))&&(i=t.value),((null==r?void 0:r.value)||0===(null==r?void 0:r.value))&&(a=r.value)}!0===t&&(a=50);const l={};for(const[t,n]of Object.entries(e))t.startsWith("dataCenterEnergy")?l[t.replace("Energy","CO2")]=n*a:t.startsWith("consumerDeviceEnergy")?l[t.replace("Energy","CO2")]=n*o:t.startsWith("networkEnergy")?l[t.replace("Energy","CO2")]=n*i:l[t.replace("Energy","CO2")]=n*s;return l}perByte(e,t=!1,n=!1,r={}){e<1&&(e=0);const o=this.energyPerByteByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}perVisit(e,t=!1,n=!1,r={}){const o=this.energyPerVisitByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}energyPerByte(e){const t=this.energyPerByteByComponent(e);return Object.values(t).reduce(((e,t)=>e+t))}energyPerVisitByComponent(e,t={},n=.75,r=.25,o=.02){(t.dataReloadRatio||0===t.dataReloadRatio)&&(o=t.dataReloadRatio),(t.firstVisitPercentage||0===t.firstVisitPercentage)&&(n=t.firstVisitPercentage),(t.returnVisitPercentage||0===t.returnVisitPercentage)&&(r=t.returnVisitPercentage);const i=this.energyPerByteByComponent(e),a={};Object.values(i);for(const[e,t]of Object.entries(i))a[`${e} - first`]=t*n,a[`${e} - subsequent`]=t*r*o;return a}energyPerVisit(e){let t=0,n=0;const r=Object.entries(this.energyPerVisitByComponent(e));for(const[e,n]of r)e.indexOf("first")>0&&(t+=n);for(const[e,t]of r)e.indexOf("subsequent")>0&&(n+=t);return t+n}emissionsPerVisitInGrams(e,t=r){return o(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:o(.52*e),networkEnergy:o(.14*e),dataCenterEnergy:o(.15*e),productionEnergy:o(.19*e)}}},h=class{constructor(e){if(this.model=new m,"1byte"===(null==e?void 0:e.model))this.model=new t;else if("swd"===(null==e?void 0:e.model))this.model=new m;else if(null==e?void 0:e.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment="segment"===(null==e?void 0:e.results)}perByte(e,t=!1){return this.model.perByte(e,t,this._segment)}perVisit(e,t=!1){var n;if(null==(n=this.model)?void 0:n.perVisit)return this.model.perVisit(e,t,this._segment);throw new Error("The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}perByteTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y;let p={};return n&&(p=i(n)),{co2:this.model.perByte(e,t,this._segment,p),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(s=null==(a=null==(o=null==p?void 0:p.gridIntensity)?void 0:o.network)?void 0:a.value)?s:r,dataCenter:t?50:null!=(d=null==(u=null==(l=null==p?void 0:p.gridIntensity)?void 0:l.dataCenter)?void 0:u.value)?d:r,production:r,device:null!=(y=null==(g=null==(c=null==p?void 0:p.gridIntensity)?void 0:c.device)?void 0:g.value)?y:r}}}}perVisitTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y,p,v,f,b;if(null==(o=this.model)?void 0:o.perVisit){let o={};return n&&(o=i(n)),{co2:this.model.perVisit(e,t,this._segment,o),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(l=null==(s=null==(a=null==o?void 0:o.gridIntensity)?void 0:a.network)?void 0:s.value)?l:r,dataCenter:t?50:null!=(c=null==(d=null==(u=null==o?void 0:o.gridIntensity)?void 0:u.dataCenter)?void 0:d.value)?c:r,production:r,device:null!=(p=null==(y=null==(g=null==o?void 0:o.gridIntensity)?void 0:g.device)?void 0:y.value)?p:r},dataReloadRatio:null!=(v=null==o?void 0:o.dataReloadRatio)?v:.02,firstVisitPercentage:null!=(f=null==o?void 0:o.firstVisitPercentage)?f:.75,returnVisitPercentage:null!=(b=null==o?void 0:o.returnVisitPercentage)?b:.25}}}throw new Error("The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}},R=Object.getOwnPropertyNames;const w=(s={"src/hosting-json.js"(e,t){function n(e,t){return t.indexOf(e)>-1?e:{url:e,green:!1}}t.exports={check:async function(e,t){return"string"==typeof e?function(e,t){return t.indexOf(e)>-1}(e,t):function(e,t){let n=[];for(let r of e)t.indexOf(r)>-1&&n.push(r);return n}(e,t)},greenDomainsFromResults:function(e){return Object.entries(e).filter((([e,t])=>t.green)).map((([e,t])=>t.url))},find:function(e,t){return"string"==typeof e?n(e,t):function(e,t){const r={};for(let o of e)r[o]=n(o,t);return r}(e,t)}}}},function(){return l||(0,s[R(s)[0]])((l={exports:{}}).exports,l),l.exports})();var P=function(e,t){const n="string"==typeof t?{userAgentIdentifier:t}:t;if((null==n?void 0:n.db)&&n.verbose)throw new Error("verbose mode cannot be used with a local lookup database");return"string"==typeof e?async function(e,t={}){const n=await fetch(`https://api.thegreenwebfoundation.org/greencheck/${e}`,{headers:a(t.userAgentIdentifier)});if(null==t?void 0:t.db)return w.check(e,t.db);const r=await n.json();return t.verbose?r:r.green}(e,n):async function(e,t={}){try{const r="https://api.thegreenwebfoundation.org/v2/greencheckmulti",o=JSON.stringify(e),i=await fetch(`${r}/${o}`,{headers:a(t.userAgentIdentifier)}),s=await i.json();return t.verbose?s:(n=s,Object.entries(n).filter((([e,t])=>t.green)).map((([e,t])=>t.url)))}catch(e){return t.verbose?{}:[]}var n}(e,n)},C=function(e,t){return P(e,t)};async function O(){console.log("reportEmissions called"),await async function(){return window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"}),E(2e3)}(),await E(2e3),console.log("getting emissions data");const e=await async function(){console.log("calculating...");const e=window.performance.getEntriesByType("resource").filter((e=>!(e.name||"").includes("resource-checker.js"))),t=function(e){return e.reduce(((e,t)=>e+t.transferSize),0)}(e),n=await C(window.location.hostname),r=new h({model:"swd"}).perVisitTrace(t,n);return{pageWeight:t,carbonRating:(o=r.co2,o<.095?"A+":o<.186?"A":o<.341?"B":o<.493?"C":o<.656?"D":o<.846?"E":"F"),emissions:r,resources:e};var o}();console.log("received emissions data");const t=document.createElement("div");t.setAttribute("data-testid","sustainabilityData"),t.textContent=JSON.stringify(e),document.body.appendChild(t)}function E(e){return new Promise((t=>setTimeout(t,e)))}export{O as reportEmissions}; No newline at end of file
const e=1.465e-9/3;var t=class{constructor(t){this.options=t,this.KWH_PER_BYTE_FOR_NETWORK=e}perByte(t,n){return t<1?0:n?72e-12*t*0+t*e*475:5.603333333333333e-10*t*519}},n={data:{AFG:132.53,AFRICA:559.42,ALB:24.29,DZA:634.61,ASM:611.11,AGO:174.73,ATG:611.11,ARG:394.62,ARM:264.54,ABW:561.22,ASEAN:554.5,ASIA:591.19,AUS:570.35,AUT:110.81,AZE:671.39,BHS:660.1,BHR:904.62,BGD:678.11,BRB:605.51,BLR:441.74,BEL:138.11,BLZ:225.81,BEN:584.07,BTN:23.33,BOL:489.14,BIH:600,BWA:847.91,BRA:105.51,BRN:893.91,BGR:335.33,BFA:467.53,BDI:250,CPV:558.14,KHM:417.71,CMR:305.42,CAN:161.43,CYM:642.86,CAF:0,TCD:628.57,CHL:353.52,CHN:585.82,COL:214.88,COM:642.86,COG:700,COD:24.46,COK:250,CRI:26.46,CIV:393.89,HRV:204.96,CUB:637.61,CYP:534.32,CZE:449.72,DNK:151.65,DJI:692.31,DMA:529.41,DOM:580.78,ECU:150.69,EGY:570.13,SLV:116.54,GNQ:591.84,ERI:631.58,EST:416.67,SWZ:172.41,ETH:24.64,EU:243.83,EUROPE:327.69,FLK:500,FRO:404.76,FJI:288.46,FIN:79.16,FRA:56.04,GUF:217.82,PYF:442.86,G20:482.92,G7:361.52,GAB:491.6,GMB:666.67,GEO:167.02,DEU:380.95,GHA:484,GRC:336.57,GRL:178.57,GRD:640,GLP:500,GUM:622.86,GTM:328.27,GIN:236.84,GNB:625,GUY:640.35,HTI:567.31,HND:282.27,HKG:699.5,HUN:204.19,ISL:27.68,IND:705.13,IDN:675.93,IRN:665.15,IRQ:688.81,IRL:290.81,ISR:582.93,ITA:330.72,JAM:555.56,JPN:512.81,JOR:540.92,KAZ:830.41,KEN:83.33,KIR:666.67,XKX:894.65,KWT:649.2,KGZ:147.29,LAO:265.51,"LATIN AMERICA AND CARIBBEAN":260.28,LVA:123.2,LBN:599.01,LSO:20,LBR:227.85,LBY:818.69,LTU:160.07,LUX:105.26,MAC:448.98,MDG:436.44,MWI:66.67,MYS:605.83,MDV:611.77,MLI:408,MLT:459.14,MTQ:523.18,MRT:464.71,MUS:632.48,MEX:475.36,"MIDDLE EAST":660.46,MDA:648.5,MNG:771.8,MNE:417.07,MSR:1e3,MAR:662.64,MOZ:135.65,MMR:483.57,NAM:59.26,NRU:750,NPL:24.44,NLD:267.62,NCL:660.58,NZL:110.89,NIC:265.12,NER:670.89,NGA:516.23,"NORTH AMERICA":356.01,PRK:389.59,MKD:565.35,NOR:30.08,OCEANIA:507.63,OECD:360.53,OMN:564.69,PAK:463.66,PSE:516.13,PAN:161.68,PNG:507.25,PRY:24.31,PER:251.74,POL:661.93,PRT:165.55,PRI:678.74,QAT:602.59,REU:572.82,ROU:240.58,RUS:436.28,RWA:316.33,KNA:636.36,LCA:666.67,SPM:600,VCT:529.41,WSM:473.68,STP:642.86,SAU:706.79,SEN:511.6,SRB:636.06,SYC:564.52,SLE:50,SGP:474,SVK:116.77,SVN:231.28,SLB:700,SOM:578.95,ZAF:729.67,KOR:441.65,SSD:629.03,ESP:174.05,LKA:509.78,SDN:263.16,SUR:349.28,SWE:40.7,CHE:34.84,SYR:701.66,TWN:639.53,TJK:116.86,TZA:339.25,THA:560.74,PHL:601.1,TGO:443.18,TON:625,TTO:681.53,TUN:564.62,TUR:464.59,TKM:1306.03,TCA:653.85,UGA:44.53,UKR:259.69,ARE:561.14,GBR:237.59,USA:385.98,URY:112.65,UZB:1167.6,VUT:571.43,VEN:185.8,VNM:409.8,VGB:647.06,VIR:632.35,WORLD:485.99,YEM:566.1,ZMB:111.97,ZWE:297.87},type:"average"};const r=n.data.WORLD,o=e=>parseFloat(e.toFixed(2));function i(e){var t,o,i,a,s,l;if("object"!=typeof e)throw new Error("Options must be an object");const u={};if(null==e?void 0:e.gridIntensity){u.gridIntensity={};const{device:d,dataCenter:c,network:g}=e.gridIntensity;(d||0===d)&&("object"==typeof d?(n.data[null==(t=d.country)?void 0:t.toUpperCase()]||(console.warn(`"${d.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.device={value:r}),u.gridIntensity.device={country:d.country,value:parseFloat(n.data[null==(o=d.country)?void 0:o.toUpperCase()])}):"number"==typeof d?u.gridIntensity.device={value:d}:(u.gridIntensity.device={value:r},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof d}. \nFalling back to global average grid intensity.`))),(c||0===c)&&("object"==typeof c?(n.data[null==(i=c.country)?void 0:i.toUpperCase()]||(console.warn(`"${c.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \nFalling back to global average grid intensity.`),u.gridIntensity.dataCenter={value:r}),u.gridIntensity.dataCenter={country:c.country,value:parseFloat(n.data[null==(a=c.country)?void 0:a.toUpperCase()])}):"number"==typeof c?u.gridIntensity.dataCenter={value:c}:(u.gridIntensity.dataCenter={value:r},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof c}. \nFalling back to global average grid intensity.`))),(g||0===g)&&("object"==typeof g?(n.data[null==(s=g.country)?void 0:s.toUpperCase()]||(console.warn(`"${g.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \nFalling back to global average grid intensity.`),u.gridIntensity.network={value:r}),u.gridIntensity.network={country:g.country,value:parseFloat(n.data[null==(l=g.country)?void 0:l.toUpperCase()])}):"number"==typeof g?u.gridIntensity.network={value:g}:(u.gridIntensity.network={value:r},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof g}. \nFalling back to global average grid intensity.`)))}return((null==e?void 0:e.dataReloadRatio)||0===e.dataReloadRatio)&&("number"==typeof e.dataReloadRatio?e.dataReloadRatio>=0&&e.dataReloadRatio<=1?u.dataReloadRatio=e.dataReloadRatio:(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${e.dataReloadRatio}. \nFalling back to default value.`)):(u.dataReloadRatio=.02,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof e.dataReloadRatio}. \nFalling back to default value.`))),((null==e?void 0:e.firstVisitPercentage)||0===e.firstVisitPercentage)&&("number"==typeof e.firstVisitPercentage?e.firstVisitPercentage>=0&&e.firstVisitPercentage<=1?u.firstVisitPercentage=e.firstVisitPercentage:(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${e.firstVisitPercentage}. \nFalling back to default value.`)):(u.firstVisitPercentage=.75,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof e.firstVisitPercentage}. \nFalling back to default value.`))),((null==e?void 0:e.returnVisitPercentage)||0===e.returnVisitPercentage)&&("number"==typeof e.returnVisitPercentage?e.returnVisitPercentage>=0&&e.returnVisitPercentage<=1?u.returnVisitPercentage=e.returnVisitPercentage:(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${e.returnVisitPercentage}. \nFalling back to default value.`)):(u.returnVisitPercentage=.25,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof e.returnVisitPercentage}. \nFalling back to default value.`))),u}function a(e=""){return{"User-Agent":`co2js/0.15.0 ${e}`}}var s,l,u=Object.defineProperty,d=Object.defineProperties,c=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,v=(e,t,n)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))y.call(t,n)&&v(e,n,t[n]);if(g)for(var n of g(t))p.call(t,n)&&v(e,n,t[n]);return e},b=(e,t)=>d(e,c(t)),m=class{constructor(e){this.options=e}energyPerByteByComponent(e){const t=e/1e9*.81;return{consumerDeviceEnergy:.52*t,networkEnergy:.14*t,productionEnergy:.19*t,dataCenterEnergy:.15*t}}co2byComponent(e,t=r,n={}){let o=r,i=r,a=r,s=r;if(null==n?void 0:n.gridIntensity){const{device:e,network:t,dataCenter:r}=n.gridIntensity;((null==e?void 0:e.value)||0===(null==e?void 0:e.value))&&(o=e.value),((null==t?void 0:t.value)||0===(null==t?void 0:t.value))&&(i=t.value),((null==r?void 0:r.value)||0===(null==r?void 0:r.value))&&(a=r.value)}!0===t&&(a=50);const l={};for(const[t,n]of Object.entries(e))t.startsWith("dataCenterEnergy")?l[t.replace("Energy","CO2")]=n*a:t.startsWith("consumerDeviceEnergy")?l[t.replace("Energy","CO2")]=n*o:t.startsWith("networkEnergy")?l[t.replace("Energy","CO2")]=n*i:l[t.replace("Energy","CO2")]=n*s;return l}perByte(e,t=!1,n=!1,r={}){e<1&&(e=0);const o=this.energyPerByteByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}perVisit(e,t=!1,n=!1,r={}){const o=this.energyPerVisitByComponent(e,r);if("boolean"!=typeof t)throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);const i=this.co2byComponent(o,t,r),a=Object.values(i).reduce(((e,t)=>e+t));return n?b(f({},i),{total:a}):a}energyPerByte(e){const t=this.energyPerByteByComponent(e);return Object.values(t).reduce(((e,t)=>e+t))}energyPerVisitByComponent(e,t={},n=.75,r=.25,o=.02){(t.dataReloadRatio||0===t.dataReloadRatio)&&(o=t.dataReloadRatio),(t.firstVisitPercentage||0===t.firstVisitPercentage)&&(n=t.firstVisitPercentage),(t.returnVisitPercentage||0===t.returnVisitPercentage)&&(r=t.returnVisitPercentage);const i=this.energyPerByteByComponent(e),a={};Object.values(i);for(const[e,t]of Object.entries(i))a[`${e} - first`]=t*n,a[`${e} - subsequent`]=t*r*o;return a}energyPerVisit(e){let t=0,n=0;const r=Object.entries(this.energyPerVisitByComponent(e));for(const[e,n]of r)e.indexOf("first")>0&&(t+=n);for(const[e,t]of r)e.indexOf("subsequent")>0&&(n+=t);return t+n}emissionsPerVisitInGrams(e,t=r){return o(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:o(.52*e),networkEnergy:o(.14*e),dataCenterEnergy:o(.15*e),productionEnergy:o(.19*e)}}},h=class{constructor(e){if(this.model=new m,"1byte"===(null==e?void 0:e.model))this.model=new t;else if("swd"===(null==e?void 0:e.model))this.model=new m;else if(null==e?void 0:e.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment="segment"===(null==e?void 0:e.results)}perByte(e,t=!1){return this.model.perByte(e,t,this._segment)}perVisit(e,t=!1){var n;if(null==(n=this.model)?void 0:n.perVisit)return this.model.perVisit(e,t,this._segment);throw new Error("The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}perByteTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y;let p={};return n&&(p=i(n)),{co2:this.model.perByte(e,t,this._segment,p),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(s=null==(a=null==(o=null==p?void 0:p.gridIntensity)?void 0:o.network)?void 0:a.value)?s:r,dataCenter:t?50:null!=(d=null==(u=null==(l=null==p?void 0:p.gridIntensity)?void 0:l.dataCenter)?void 0:u.value)?d:r,production:r,device:null!=(y=null==(g=null==(c=null==p?void 0:p.gridIntensity)?void 0:c.device)?void 0:g.value)?y:r}}}}perVisitTrace(e,t=!1,n={}){var o,a,s,l,u,d,c,g,y,p,v,f,b;if(null==(o=this.model)?void 0:o.perVisit){let o={};return n&&(o=i(n)),{co2:this.model.perVisit(e,t,this._segment,o),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:null!=(l=null==(s=null==(a=null==o?void 0:o.gridIntensity)?void 0:a.network)?void 0:s.value)?l:r,dataCenter:t?50:null!=(c=null==(d=null==(u=null==o?void 0:o.gridIntensity)?void 0:u.dataCenter)?void 0:d.value)?c:r,production:r,device:null!=(p=null==(y=null==(g=null==o?void 0:o.gridIntensity)?void 0:g.device)?void 0:y.value)?p:r},dataReloadRatio:null!=(v=null==o?void 0:o.dataReloadRatio)?v:.02,firstVisitPercentage:null!=(f=null==o?void 0:o.firstVisitPercentage)?f:.75,returnVisitPercentage:null!=(b=null==o?void 0:o.returnVisitPercentage)?b:.25}}}throw new Error("The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.")}},R=Object.getOwnPropertyNames;const w=(s={"src/hosting-json.js"(e,t){function n(e,t){return t.indexOf(e)>-1?e:{url:e,green:!1}}t.exports={check:async function(e,t){return"string"==typeof e?function(e,t){return t.indexOf(e)>-1}(e,t):function(e,t){let n=[];for(let r of e)t.indexOf(r)>-1&&n.push(r);return n}(e,t)},greenDomainsFromResults:function(e){return Object.entries(e).filter((([e,t])=>t.green)).map((([e,t])=>t.url))},find:function(e,t){return"string"==typeof e?n(e,t):function(e,t){const r={};for(let o of e)r[o]=n(o,t);return r}(e,t)}}}},function(){return l||(0,s[R(s)[0]])((l={exports:{}}).exports,l),l.exports})();var P=function(e,t){const n="string"==typeof t?{userAgentIdentifier:t}:t;if((null==n?void 0:n.db)&&n.verbose)throw new Error("verbose mode cannot be used with a local lookup database");return"string"==typeof e?async function(e,t={}){const n=await fetch(`https://api.thegreenwebfoundation.org/greencheck/${e}`,{headers:a(t.userAgentIdentifier)});if(null==t?void 0:t.db)return w.check(e,t.db);const r=await n.json();return t.verbose?r:r.green}(e,n):async function(e,t={}){try{const r="https://api.thegreenwebfoundation.org/v2/greencheckmulti",o=JSON.stringify(e),i=await fetch(`${r}/${o}`,{headers:a(t.userAgentIdentifier)}),s=await i.json();return t.verbose?s:(n=s,Object.entries(n).filter((([e,t])=>t.green)).map((([e,t])=>t.url)))}catch(e){return t.verbose?{}:[]}var n}(e,n)},C=function(e,t){return P(e,t)};async function O(){console.log("reportEmissions called"),await async function(){return window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"}),E(2e3)}(),await E(2e3),console.log("getting emissions data");const e=await async function(){console.log("calculating...");const e=window.performance.getEntriesByType("resource").filter((e=>!(e.name||"").split("?")[0].endsWith("resource-checker.js"))),t=function(e){return e.reduce(((e,t)=>e+t.transferSize),0)}(e),n=await C(window.location.hostname),r=new h({model:"swd"}).perVisitTrace(t,n);return{pageWeight:t,carbonRating:(o=r.co2,o<.095?"A+":o<.186?"A":o<.341?"B":o<.493?"C":o<.656?"D":o<.846?"E":"F"),emissions:r,resources:e};var o}();console.log("received emissions data");const t=document.createElement("div");t.setAttribute("data-testid","sustainabilityData"),t.textContent=JSON.stringify(e),document.body.appendChild(t)}function E(e){return new Promise((t=>setTimeout(t,e)))}export{O as reportEmissions}; No newline at end of file
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

This statement is unreachable.

Copilot uses AI. Check for mistakes.
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.

The filter logic may not correctly exclude the resource-checker.js file

2 participants