I'm trying to reload a page on safari if the user presses the browser back button and if the event is persisted. My code works on safai version 15.6. But when I try on safari version 14.1, it never enters the if block, which means the event.persisted is always set to false. I've tried every possible solution I could find. Any help will be much appreciated. Here's my code:
if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) {
window.addEventListener('pageshow', function (event) {
//PREVIOUS VERSIONS DON'T PASS THE IF CHECK HERE
if (event.persisted || performance.getEntriesByType("navigation")[0].type === 'back_forward') {
location.reload();
alert("HI");
}
},false);
}