You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`TimeoutMilliseconds`: Timeout in milliseconds for waiting for sustainability data to be collected. Default: 60000 (60 seconds)
181
+
-`EnableBrowserConsoleLogging`: Enable browser console logging to Kentico Event Log for debugging. Default: false. When enabled, all console messages from the headless browser (including those from resource-checker.js) are logged to the Event Log with source "SustainabilityService" and event code "BrowserConsole"
166
182
167
183
### Service Registration (Program.cs)
168
184
@@ -175,6 +191,43 @@ This registers:
175
191
-`ISustainabilityModuleInstaller` as Singleton
176
192
- Binds `SustainabilityOptions` from configuration
177
193
194
+
## Data Models
195
+
196
+
### SustainabilityData (from JavaScript)
197
+
198
+
The JavaScript returns data with a nested `Co2Result` structure:
199
+
200
+
```json
201
+
{
202
+
"pageWeight": 1234567,
203
+
"carbonRating": "B",
204
+
"greenHostingStatus": "Green",
205
+
"emissions": {
206
+
"co2": {
207
+
"total": 0.123,
208
+
"rating": "B"
209
+
},
210
+
"green": true
211
+
},
212
+
"resources": [...]
213
+
}
214
+
```
215
+
216
+
### Backend Models
217
+
218
+
**SustainabilityData.cs**:
219
+
-`PageWeight` (int) - Total bytes transferred
220
+
-`CarbonRating` (string) - Letter grade from JavaScript
221
+
-`GreenHostingStatus` (string) - Green, NotGreen, or Unknown
-`@tgwf/co2` (v0.16.9) - Bundled locally via webpack (no external CDN)
255
305
256
306
## Common Tasks
257
307
@@ -264,7 +314,11 @@ npm run build
264
314
265
315
### Modifying Carbon Rating Thresholds
266
316
267
-
Edit `resource-checker.js` line 56-64 (grades) and update React component's `ratingDescriptions` (SustainabilityTabTemplate.tsx:41-49).
317
+
**Note**: Carbon ratings now come from the built-in `@tgwf/co2` library using SWDM v4 official thresholds. The library automatically assigns ratings based on grams CO₂ per page view.
318
+
319
+
If you need to customize rating descriptions or UI display:
- Update `getHostingStatusDisplay()` helper for hosting status colors and text
268
322
269
323
### Changing Resource Categories
270
324
@@ -278,8 +332,10 @@ Update `ResourceGroupType` enum (ExternalResourceGroup.cs:43-55) and `GetInitiat
278
332
279
333
## Debugging Tips
280
334
281
-
1.**Playwright issues**: Check event log in Kentico admin for logged errors
282
-
2.**Script not loading**: Verify `/_content/XperienceCommunity.Sustainability/scripts/resource-checker.js` is accessible
283
-
3.**Timeout errors**: Increase timeout in SustainabilityService.cs:60 or check if page loads slowly
284
-
4.**CSP errors**: Ensure `BypassCSP = true` is set (line 45)
285
-
5.**Browser not found**: Playwright requires browser installation (`playwright install chromium`)
335
+
1.**Enable console logging**: Set `EnableBrowserConsoleLogging: true` in appsettings.json to log all browser console messages to Kentico Event Log. View logs in Admin → System → Event log (source: `SustainabilityService`, event code: `BrowserConsole`)
336
+
2.**Playwright issues**: Check event log in Kentico admin for logged errors
337
+
3.**Script not loading**: Verify `/_content/XperienceCommunity.Sustainability/scripts/resource-checker.js` is accessible
338
+
4.**Timeout errors**: Increase `TimeoutMilliseconds` in appsettings.json or check if page loads slowly
339
+
5.**CSP errors**: Ensure `BypassCSP = true` is set in SustainabilityService.cs
340
+
6.**Browser not found**: Playwright requires browser installation (`playwright install chromium`)
341
+
7.**Hosting status Unknown**: Check Event Log with console logging enabled to see if Green Web Foundation API is accessible
> **Note**: Playwright browsers (Chromium) are automatically installed on first application startup. The installation path defaults to `App_Data/playwright` unless you're hosting on a UNC path.
57
57
58
+
## Features
59
+
60
+
### Carbon Emissions Calculation
61
+
62
+
The package uses the **Sustainable Web Design Model v4 (SWDM v4)** from [The Green Web Foundation](https://www.thegreenwebfoundation.org/) to calculate carbon emissions. Carbon ratings (A+ through F) follow the [official Digital Carbon Ratings](https://sustainablewebdesign.org/digital-carbon-ratings/) methodology.
63
+
64
+
### Green Hosting Detection
65
+
66
+
The package automatically checks if your website is hosted on a green energy provider using The Green Web Foundation's database. This affects the carbon calculation:
67
+
68
+
-**Green hosting**: Uses renewable energy intensity values (lower emissions)
69
+
-**Standard hosting**: Uses global grid intensity values
70
+
-**Unknown**: When verification fails, conservative estimates are used
71
+
72
+
The hosting status is displayed in the Sustainability report with three possible states:
73
+
74
+
- ● **Green hosting** - Site uses renewable/green energy
75
+
- ● **Standard hosting** - Site uses standard grid energy
76
+
- ● **Unknown hosting** - Unable to verify hosting provider
77
+
78
+
### Sustainability Report
79
+
80
+
Each report includes:
81
+
82
+
-**Carbon Rating**: Letter grade (A+ through F) based on grams CO₂ per page view
83
+
-**CO₂ Emissions**: Total carbon emissions with hosting status indicator
84
+
-**Page Weight**: Total size of all resources loaded
85
+
-**Resource Breakdown**: Categorized by type (Images, Scripts, CSS, etc.) with individual file sizes
86
+
-**Optimization Tips**: Xperience-specific recommendations for reducing page weight
87
+
58
88
## Configuration
59
89
60
90
The package can be configured using the `Sustainability` section in your `appsettings.json` file.
@@ -63,7 +93,8 @@ The package can be configured using the `Sustainability` section in your `appset
@@ -74,6 +105,7 @@ The package can be configured using the `Sustainability` section in your `appset
74
105
| ------ | ----------- | ------- |
75
106
|`TimeoutMilliseconds`| Timeout in milliseconds for waiting for sustainability data to be collected from the page. |`60000` (60 seconds) |
76
107
|`PlaywrightBrowserPath`| Custom path where Playwright browsers should be installed. **Only required when hosting on UNC paths (network shares starting with `\\`)**. For standard hosting, browsers are automatically installed in `App_Data/playwright`. |`null`|
108
+
|`EnableBrowserConsoleLogging`| Enable browser console logging to Kentico Event Log for debugging purposes. When enabled, all console messages from the headless browser are logged to help troubleshoot issues. |`false`|
77
109
78
110
> **Note on UNC Hosting**: When hosting on UNC paths (network shares), you **must** configure `PlaywrightBrowserPath` or the application will throw an error during startup. This setting is ignored for standard hosting scenarios.
0 commit comments