Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE html>
<script src="/scroll-to-text-fragment/stash.js"></script>
<!-- This test is navigated to with the fragment #:~:text=foo -->
<div id=parentid>
<div id=childid hidden=until-found>foo</div>
</div>
<script>
(async () => {
const results = {
beforematchFiredOnChild: false,
beforematchFiredOnParent: false
};
let beforematchResolver = null;
const beforematchPromise = new Promise(resolve => {
beforematchResolver = resolve;
});
childid.addEventListener('beforematch', () => {
results.beforematchFiredOnChild = true;
beforematchResolver();
});
parentid.addEventListener('beforematch', () => {
results.beforematchFiredOnParent = true;
});
await beforematchPromise;
await new Promise(requestAnimationFrame);
await new Promise(requestAnimationFrame);
const params = new URLSearchParams(window.location.search);
stashResultsThenClose(params.get('key'), results);
})();
</script>