Automatic update from web-platform-tests Reland "[text-fragment] Attempt search for dynamic content" Reland note: iframes.sub.html was timing out because it contains several sub-tests, each of which now wait 2s which, in total, exhausted the 6s timeout. Reland marks this test as timeout=long to use the extended timeout. Previously landed CL is first patchset. Text fragments currently perform up to two searches, one when document parsing completes and a second attempt when document load completes (if load wasn't completed at parse complete time). However, pages, often load content after document load, when content is "dynamically loaded". One popular example is Mobile Wikipedia, which adds `hidden=until-found` on collapsed sections in idle tasks after load. This meant text-fragments couldn't target pages like these. This CL attempts to make text fragments work on dynamically loaded pages by performing a third attempt, if needed. If all directives haven't matched at load time, a delayed task is scheduled for 500ms that will request attachment on unmatched directives. TextFragmentAnchor listens for relevant changes in the DOM and reschedules this task each time a change is made. At 3000ms it gives up and performs the search to avoid waiting forever. At a high level, this CL tries to separate the state tracking of actions performed for the first matching directive from the state tracking for running multiple searches. This is done by introducing a new iteration_ enum tracking the latter. Bug: 963045 Change-Id: Ied3f9c610c348eeeca23ace50864f0cc2ff2b233 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4629864 Commit-Queue: Vladimir Levin <vmpstr@chromium.org> Commit-Queue: David Bokan <bokan@chromium.org> Reviewed-by: Vladimir Levin <vmpstr@chromium.org> Auto-Submit: David Bokan <bokan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1160827} -- wpt-commits: 95d67cd661417e9c44440cba14dcce147e2768bf wpt-pr: 40654
50 lines
1.3 KiB
HTML
50 lines
1.3 KiB
HTML
<!doctype html>
|
|
<title>Inner document for use in iframes.sub.html test</title>
|
|
<script>
|
|
function isInView(element) {
|
|
let rect = element.getBoundingClientRect();
|
|
return rect.top >= 0 && rect.top <= window.innerHeight
|
|
&& rect.left >= 0 && rect.left <= window.innerWidth;
|
|
}
|
|
|
|
function postResult() {
|
|
let position = 'unknown';
|
|
if (window.scrollY == 0)
|
|
position = 'top';
|
|
else if (isInView(document.getElementById('target')))
|
|
position = 'target';
|
|
else if (isInView(document.getElementById('elementid')))
|
|
position = 'elementid';
|
|
|
|
let results = {
|
|
scrollPosition: position,
|
|
href: window.location.href,
|
|
};
|
|
|
|
window.top.postMessage(results, "*");
|
|
}
|
|
|
|
window.addEventListener('message', (e) => {
|
|
if (e.data == 'getResult') {
|
|
// Use a timeout to get results - in the elementId fallback case, the
|
|
// browser may retry the text fragment search a few times before giving
|
|
// up and trying the elementid.
|
|
setTimeout(postResult, 2000);
|
|
} else if (e.data == 'reset') {
|
|
window.location.hash = '';
|
|
window.scrollTo(0, 0);
|
|
window.top.postMessage('', "*");
|
|
}
|
|
});
|
|
</script>
|
|
<style>
|
|
p {
|
|
margin-top: 400vh;
|
|
margin-bottom: 400vh;
|
|
}
|
|
</style>
|
|
<body>
|
|
<p id="target">Target Text</p>
|
|
<div id="elementid">DIV</div>
|
|
</body>
|