iframe-loading-lazy-history-pushState.html (1348B)
1 <!DOCTYPE html> 2 <title>History state change for iframe loading='lazy' before it is loaded: history.pushState</title> 3 <iframe data-src="about:blank#push" 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 pushStateSuccess = 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.pushState(null, "", iframe.dataset.src); 15 } catch(ex) { 16 pushStateSuccess = false; 17 } 18 const locationAfterPushState = 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(pushStateSuccess); 27 assert_equals(locationAfterPushState, new URL("about:blank#push", location.href).href); 28 iframeLoaded.then(() => { 29 // No timeout needed in this test because history.pushState() doesn't navigate. 30 assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?src", location.href).href); 31 done(); 32 }); 33 </script>