iframe-loading-lazy-history-replaceState.html (1378B)
1 <!DOCTYPE html> 2 <title>History state change for iframe loading='lazy' before it is loaded: history.replaceState</title> 3 <iframe data-src="about:blank#replace" src="support/blank.htm?src" loading="lazy" hidden></iframe> 4 <script> 5 const iframe = document.querySelector('iframe'); 6 const iframeLoaded = new Promise(resolve => { 7 iframe.onload = resolve; 8 }); 9 let replaceStateSuccess = true; 10 try { 11 // Should have no effect on lazy-loading. 12 // Per https://html.spec.whatwg.org/C#can-have-its-url-rewritten 13 // only the fragment can be changed for about: URLs. 14 iframe.contentWindow.history.replaceState(null, "", iframe.dataset.src); 15 } catch(ex) { 16 replaceStateSuccess = false; 17 } 18 const locationAfterReplaceState = iframe.contentWindow.location.href; 19 iframe.hidden = false; 20 </script> 21 <!-- Loading testharness.js here is intentional to reproduce a bug in WebKit. --> 22 <script src="/resources/testharness.js"></script> 23 <script src="/resources/testharnessreport.js"></script> 24 <script> 25 setup({single_test: true}); 26 assert_true(replaceStateSuccess); 27 assert_equals(locationAfterReplaceState, new URL("about:blank#replace", location.href).href); 28 iframeLoaded.then(() => { 29 // No timeout needed in this test because history.replaceState() doesn't navigate. 30 assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?src", location.href).href); 31 done(); 32 }); 33 </script>