Skip to content

Commit

Permalink
feat: add experimental support for soft navigations
Browse files Browse the repository at this point in the history
Summary:

Recent versions of Chromium have added support for tracking web vitals metrics
across soft navigations. This change adds support for tracking these metrics in
the extension.

TODO:

- [ ] document the new `reportSoftNavs` option in the README
- [ ] document how to build the extension with the `soft-navs` branch of the
  `web-vitals` package
- [ ] Hide the option in the options page if one of the following is false:
  1. The browser supports the `soft-navigation` entry type
  2. The `web-vitals` package has been built with the `soft-navs` branch
  • Loading branch information
vegerot committed Aug 16, 2024
1 parent 5c638ab commit fe9c7a0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/browser_action/vitals.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
let latestCLS = {};
let enableLogging = localStorage.getItem('web-vitals-extension-debug')=='TRUE';
let enableUserTiming = localStorage.getItem('web-vitals-extension-user-timing')=='TRUE';
let reportSoftNavs = (await chrome.storage.sync.get('reportSoftNavs')).reportSoftNavs ?? false;
let tabLoadedInBackground;

const COLOR_GOOD = '#0CCE6A';
Expand Down Expand Up @@ -514,15 +515,15 @@
// debounce the broadcast of the metric.
latestCLS = metric;
debouncedCLSBroadcast();
}, { reportAllChanges: true });
}, { reportAllChanges: true, reportSoftNavs });

webVitals.onLCP(broadcastMetricsUpdates, { reportAllChanges: true });
webVitals.onFID(broadcastMetricsUpdates, { reportAllChanges: true });
webVitals.onLCP(broadcastMetricsUpdates, { reportAllChanges: true, reportSoftNavs: reportSoftNavs });
webVitals.onFID(broadcastMetricsUpdates, { reportAllChanges: true, reportSoftNavs: reportSoftNavs });
webVitals.onINP((metric) => {
broadcastMetricsUpdates(metric)
}, { reportAllChanges: true });
webVitals.onFCP(broadcastMetricsUpdates, { reportAllChanges: true });
webVitals.onTTFB(broadcastMetricsUpdates, { reportAllChanges: true });
}, { reportAllChanges: true, reportSoftNavs: true });
webVitals.onFCP(broadcastMetricsUpdates, { reportAllChanges: true, reportSoftNavs: reportSoftNavs });
webVitals.onTTFB(broadcastMetricsUpdates, { reportAllChanges: true, reportSoftNavs: reportSoftNavs });

if (enableLogging) {
onEachInteraction((metric) => {
Expand Down
Loading

0 comments on commit fe9c7a0

Please sign in to comment.