Checking page refresh In JavaScript (Code Snippet)

const pageWasAccessedViaReload = (
(window.performance.navigation
&& window.performance.navigation.type === 1)
|| window.performance
.getEntriesByType("navigation")
.map(nav => nav.type)
.includes("reload")
);
Recently I needed to know in an application if the user had got to the current page by performing a browser refresh. Here is a snippet of code you can use in JavaScript to check this. It uses the user timing api and as you can see the coverage is well apart from Opera Mini as always.
