TRIGGER BROWSER INSTANCE NOT SWAP - go to x.com
This link uses click event with preventDefault and window.location.replace. It goes to https://x.com.
On the back button, we get bfcache not restored reason as: BrowsingInstanceNotSwapped in Application Tab.
addEventListener('click', function(e){ e.preventDefault(); window.location.hash = "test"; window.location.replace(e.target.getAttribute('href')); });
TRIGGER UNKNOWN - go to www.google.com
This link uses click event with preventDefault and window.location.replace. It goes to https://www.google.com.
On the back button, we get bfcache not restored reason as: Unknown in Application Tab.
addEventListener('click', function(e){ e.preventDefault(); window.location.hash = "test"; window.location.replace(e.target.getAttribute('href')); });
The two examples above return a masked not restored reason from javascript API. It's shown above them.
---------------------------------------------------------------------------------------------------------
NOT PREVENT BfCache
This link uses click event with preventDefault and force click on newly added element to DOM. The link goes to https://www.google.com.
On the back button, we get success of BFCache.
addEventListener('click', function(e){ e.preventDefault(); document.body.insertAdjacentHTML('beforeend', '<a class="clicker" href="' + e.target.getAttribute('href') + '"></a>'); const clickEvent = new MouseEvent('click', { bubbles: false, cancelable: false }); document.body.querySelector('.clicker').dispatchEvent(clickEvent); });