GoogleChrome / web-vitals-extension

A Chrome extension to measure essential metrics for a healthy site
https://chrome.google.com/webstore/detail/web-vitals/ahfhijdlegdabablpippeagghigmibma?hl=en
Apache License 2.0
2.35k stars 105 forks source link

Persist metrics across page visibility changes #102

Closed rviscomi closed 2 years ago

rviscomi commented 2 years ago

Fixes #101

rviscomi commented 2 years ago

This PR writes the metrics state to local storage every time web-vitals.js reports a change. When the script is reinitialized, it attempts to read the persisted state from local storage. To distinguish from page reloads in the same tab, the state includes the navigationStart time, which is ~unique for each tab+navigation.

I assume the local storage is temporary until the tab is closed, otherwise I'll need to add more code to delete state from storage. (can anyone confirm?)

addyosmani commented 2 years ago

LGTM