Was the page navigated to using back or forward button?
window.performance.getEntriesByType("navigation")[0].type === "back_forward";
This is how to detect if a page was loaded because the user navigated via back or forward buttons.
Possible values:
back_forward
if the navigation happened because of a back or forward navigationnavigate
if the navigation happened because of a regular navigation event (like clicking a link).reload
after reloading the pageprerender
if the navigation has happened during a prerender hint