hidden-until-found-text-fragment.html (1358B)
1 <!DOCTYPE html> 2 <script src="/scroll-to-text-fragment/stash.js"></script> 3 4 <!-- This test is navigated to with the fragment #:~:text=foo --> 5 6 <body> 7 <div style="height: 4000px;">spacer</div> 8 <div id=target hidden=until-found>foo</div> 9 <script> 10 // scroll-to-text-fragment may delay scrolling for an 11 // arbitrary amount of time for security reasons. 12 // This test would time out if beforematch is not fired, but since the 13 // test file only has one test, this is not shadowing other test results. 14 target.onbeforematch = () => { 15 // Adding two additional requestAnimationFrames ensures 16 // that scrolling has happened after beforematch has fired. 17 requestAnimationFrame(() => { 18 requestAnimationFrame(() => { 19 const results = {}; 20 // This should be false. The hidden=until-found attribute should be 21 // removed in response to ScrollToTextFragment. 22 results.targetHasHiddenAttribute = document.getElementById('target').hasAttribute('hidden'); 23 // This should be greater than zero. The page should be scrolled down 24 // to foo. 25 results.pageYOffsetAfterRaf = window.pageYOffset; 26 27 params = new URLSearchParams(window.location.search); 28 stashResultsThenClose(params.get('key'), results); 29 30 }); 31 }); 32 }; 33 </script> 34 </body>