Lightpanda: the headless browser designed for AI and automation
`IntersectionObserver`: a document without a frame doesn't render
nikneym891b959dc40d
diff --git a/src/browser/tests/intersection_observer/basic.html b/src/browser/tests/intersection_observer/basic.htmlindex 06c713ae7..fdba924c1 100644--- a/src/browser/tests/intersection_observer/basic.html+++ b/src/browser/tests/intersection_observer/basic.html@@ -77,3 +77,29 @@});}</script>++<script id=detached_document type=module>+ // connected to a document that never renders, reported once adopted into+ // this one (WPT intersection-observer/target-in-detached-document.html)+ const state = await testing.async();+ // WPT's waitForNotification: two frames, then a task+ const nextFrame = () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(resolve))));++ const seen = [];+ const doc = document.implementation.createHTMLDocument('');+ const div = doc.body.appendChild(doc.createElement('div'));+ new IntersectionObserver((entries) => {+ for (const entry of entries) seen.push(entry.isIntersecting);+ }).observe(div);++ await nextFrame();+ const before = seen.slice();+ document.body.appendChild(div);+ await nextFrame();++ state.resolve();+ await state.done(() => {+ testing.expectEqual([], before);+ testing.expectEqual([true], seen);+ });+</script>diff --git a/src/browser/webapi/IntersectionObserver.zig b/src/browser/webapi/IntersectionObserver.zigindex 90988f232..b07f6c31e 100644--- a/src/browser/webapi/IntersectionObserver.zig+++ b/src/browser/webapi/IntersectionObserver.zig@@ -253,7 +253,9 @@ fn checkIntersection(self: *IntersectionObserver, target: *Element, frame: *Framreturn;};- const connected = target.asNode().isConnected();+ // Frameless documents (DOMParser, createHTMLDocument) aren't rendered.+ const node = target.asNode();+ const connected = node.ownerFrame(frame) != null and node.isConnected();const is_now_intersecting = connected and self.meetsThreshold(1.0);if (!is_now_intersecting) {// Not intersecting yet (e.g. observed while still detached) — keep