mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-03 17:58:55 +02:00
Before this patch, the first call to `Document::ScrollToRef()` would attempt to find all text directives in the document, and, if found, highlight + scroll to them. Then, it would clear the list of uninvoked directives. However, `ScrollToRef()` is called multiple times during a page load, and the DOM can change (e.g. if `DOMContentLoaded` does some changes). This patch fixes this by only removing the text directives which were found in the document from the list of uninvoked directives. This way, subsequent calls to `ScrollToRef()` would ensure that all text directives are highlighted, and the first text directive is scrolled to. Additionally, all remaining uninvoked text directives at the end of a page load (ie. text directives that are not on the page) are cleared. A test was added as well. Differential Revision: https://phabricator.services.mozilla.com/D211260
25 lines
659 B
HTML
25 lines
659 B
HTML
<!DOCTYPE html>
|
|
<title>
|
|
Navigating to a text fragment which is only available after `DOMContentLoaded`
|
|
</title>
|
|
<script src="stash.js"></script>
|
|
<script>
|
|
function checkScroll() {
|
|
const results = {hasScrolled: window.scrollY != 0};
|
|
let key = (new URL(document.location)).searchParams.get("key");
|
|
stashResultsThenClose(key, results);
|
|
};
|
|
window.onload = () => {
|
|
window.requestAnimationFrame(function() {
|
|
window.requestAnimationFrame(checkScroll);
|
|
})
|
|
}
|
|
</script>
|
|
<body>
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
document.body.innerHTML = `<div style="margin-top: 200vh">After DOMContentLoaded</div>`;
|
|
});
|
|
|
|
</script>
|
|
</body>
|