The headless browser for AI agents and web scraping
Merge remote-tracking branch 'origin/main' into pr471-push
SGavrl0df158ec9d23
diff --cc build.logindex 00000000,00000000..f7a5ee50new file mode 100644--- /dev/null+++ b/build.log@@@ -1,0 -1,0 +1,283 @@@++ Compiling proc-macro2 v1.0.106++ Compiling quote v1.0.45++ Compiling unicode-ident v1.0.24++ Compiling libc v0.2.186++ Compiling cfg-if v1.0.4++ Compiling parking_lot_core v0.9.12++ Compiling serde_core v1.0.228++ Compiling serde v1.0.228++ Compiling smallvec v1.15.2++ Compiling icu_properties_data v2.2.0++ Compiling icu_normalizer_data v2.2.0++ Compiling stable_deref_trait v1.2.1++ Compiling pin-project-lite v0.2.17++ Compiling version_check v0.9.5++ Compiling scopeguard v1.2.0++ Compiling itoa v1.0.18++ Compiling memchr v2.8.2++ Compiling typenum v1.20.1++ Compiling lock_api v0.4.14++ Compiling bytes v1.11.1++ Compiling crc32fast v1.5.0++ Compiling zmij v1.0.21++ Compiling generic-array v0.14.7++ Compiling rand_core v0.6.4++ Compiling thiserror v2.0.18++ Compiling rand v0.8.6++ Compiling serde_json v1.0.150++ Compiling subtle v2.6.1++ Compiling futures-core v0.3.32++ Compiling syn v2.0.117++ Compiling glob v0.3.3++ Compiling litemap v0.8.2++ Compiling writeable v0.6.3++ Compiling utf8_iter v1.0.4++ Compiling prettyplease v0.2.37++ Compiling clang-sys v1.8.1++ Compiling siphasher v1.0.3++ Compiling getrandom v0.2.17++ Compiling errno v0.3.14++ Compiling mio v1.2.1++ Compiling socket2 v0.6.4++ Compiling signal-hook-registry v1.4.8++ Compiling autocfg v1.5.1++ Compiling parking_lot v0.12.5++ Compiling futures-sink v0.3.32++ Compiling phf_shared v0.11.3++ Compiling crypto-common v0.1.7++ Compiling rustix v0.38.44++ Compiling regex-syntax v0.8.11++ Compiling percent-encoding v2.3.2++ Compiling num-traits v0.2.19++ Compiling either v1.16.0++ Compiling bitflags v2.13.0++ Compiling minimal-lexical v0.2.1++ Compiling phf_generator v0.11.3++ Compiling futures-channel v0.3.32++ Compiling nom v7.1.3++ Compiling libloading v0.8.9++ Compiling linux-raw-sys v0.4.15++ Compiling bindgen v0.71.1++ Compiling rustc-hash v2.1.2++ Compiling itertools v0.13.0++ Compiling log v0.4.32++ Compiling futures-io v0.3.32++ Compiling shlex v1.3.0++ Compiling adler2 v2.0.1++ Compiling home v0.5.12++ Compiling once_cell v1.21.4++ Compiling hashbrown v0.17.1++ Compiling regex-automata v0.4.14++ Compiling equivalent v1.0.2++ Compiling radium v0.7.0++ Compiling slab v0.4.12++ Compiling futures-task v0.3.32++ Compiling indexmap v2.14.0++ Compiling cexpr v0.6.0++ Compiling miniz_oxide v0.8.9++ Compiling gzip-header v1.1.0++ Compiling form_urlencoded v1.2.2++ Compiling fslock v0.2.1++ Compiling find-msvc-tools v0.1.9++ Compiling shlex v2.0.1++ Compiling cc v1.2.64++ Compiling which v6.0.3++ Compiling http v1.4.2++ Compiling paste v1.0.15++ Compiling synstructure v0.13.2++ Compiling regex v1.12.4++ Compiling heck v0.5.0++ Compiling httparse v1.10.1++ Compiling ring v0.17.14++ Compiling tracing-core v0.1.36++ Compiling phf_codegen v0.11.3++ Compiling block-buffer v0.10.4++ Compiling alloc-no-stdlib v2.0.4++ Compiling zerofrom-derive v0.1.7++ Compiling yoke-derive v0.8.2++ Compiling zerovec-derive v0.11.3++ Compiling displaydoc v0.2.6++ Compiling serde_derive v1.0.228++ Compiling tokio-macros v2.7.0++ Compiling futures-macro v0.3.32++ Compiling thiserror-impl v2.0.18++ Compiling deno_error_macro v0.6.1++ Compiling sys_traits_macros v0.1.0++ Compiling zerofrom v0.1.8++ Compiling yoke v0.8.3++ Compiling tokio v1.52.3++ Compiling zerotrie v0.2.4++ Compiling zerovec v0.11.6++ Compiling futures-util v0.3.32++ Compiling tinystr v0.8.3++ Compiling potential_utf v0.1.5++ Compiling icu_locale_core v2.2.0++ Compiling icu_collections v2.2.0++ Compiling cpufeatures v0.2.17++ Compiling zeroize v1.9.0++ Compiling anyhow v1.0.102++ Compiling icu_provider v2.2.0++ Compiling getrandom v0.4.2++ Compiling icu_properties v2.2.0++ Compiling icu_normalizer v2.2.0++ Compiling idna_adapter v1.2.2++ Compiling idna v1.1.0++ Compiling rustls-pki-types v1.14.1++ Compiling url v2.5.8++ Compiling v8 v137.3.0++ Compiling alloc-stdlib v0.2.2++ Compiling tracing-attributes v0.1.31++ Compiling digest v0.10.7++ Compiling http-body v1.0.1++ Compiling new_debug_unreachable v1.0.6++ Compiling simd-adler32 v0.3.9++ Compiling untrusted v0.9.0++ Compiling proc-macro-rules-macros v0.4.0++ Compiling tracing v0.1.44++ Compiling deno_error v0.6.1++ Compiling brotli-decompressor v5.0.1++ Compiling phf_macros v0.11.3++ Compiling strum_macros v0.27.2++ Compiling capacity_builder_macros v0.3.0++ Compiling pin-project-internal v1.1.13++ Compiling block-padding v0.3.3++ Compiling tap v1.0.1++ Compiling rustls v0.23.40++ Compiling tower-service v0.3.3++ Compiling try-lock v0.2.5++ Compiling utf-8 v0.7.6++ Compiling wyz v0.5.1++ Compiling want v0.3.1++ Compiling brotli v8.0.3++ Compiling inout v0.1.4++ Compiling phf v0.11.3++ Compiling num-integer v0.1.46++ Compiling flate2 v1.1.9++ Compiling rustls-webpki v0.103.13++ Compiling proc-macro-rules v0.4.0++ Compiling string_cache_codegen v0.5.4++ Compiling stringcase v0.4.0++ Compiling funty v2.0.0++ Compiling compression-core v0.4.32++ Compiling uuid v1.23.3++ Compiling atomic-waker v1.1.2++ Compiling mac v0.1.1++ Compiling outref v0.5.2++ Compiling precomputed-hash v0.1.1++ Compiling vsimd v0.8.0++ Compiling futf v0.1.5++ Compiling hyper v1.10.1++ Compiling debugid v0.8.0++ Compiling bitvec v1.0.1++ Compiling markup5ever v0.14.1++ Compiling strum v0.27.2++ Compiling base64-simd v0.8.0++ Compiling deno_ops v0.226.0++ Compiling futures-executor v0.3.32++ Compiling compression-codecs v0.4.38++ Compiling num-bigint v0.4.6++ Compiling cipher v0.4.4++ Compiling sys_traits v0.1.28++ Compiling sync_wrapper v1.0.2++ Compiling tower-layer v0.3.3++ Compiling ipnet v2.12.0++ Compiling dtoa v1.0.11++ Compiling unicode-id-start v1.4.0++ Compiling data-encoding v2.11.0++ Compiling bit-vec v0.8.0++ Compiling base64 v0.22.1++ Compiling if_chain v1.0.3++ Compiling zerocopy v0.8.52++ Compiling rustix v1.1.4++ Compiling getrandom v0.3.4++ Compiling serde_v8 v0.259.0++ Compiling hyper-util v0.1.20++ Compiling bit-set v0.8.0++ Compiling sourcemap v9.3.2++ Compiling dtoa-short v0.3.5++ Compiling tower v0.5.3++ Compiling deno_path_util v0.4.0++ Compiling tokio-rustls v0.26.4++ Compiling async-compression v0.4.42++ Compiling futures v0.3.32++ Compiling tendril v0.4.3++ Compiling string_cache v0.8.9++ Compiling deno_unsync v0.4.4++ Compiling pin-project v1.1.13++ Compiling capacity_builder v0.5.0++ Compiling wasm_dep_analyzer v0.3.0++ Compiling tokio-util v0.7.18++ Compiling http-body-util v0.1.3++ Compiling webpki-roots v1.0.7++ Compiling bincode v1.3.3++ Compiling cssparser-macros v0.6.1++ Compiling selectors v0.26.0++ Compiling universal-hash v0.5.1++ Compiling byteorder v1.5.0++ Compiling deno_core_icudata v0.74.0++ Compiling ryu v1.0.23++ Compiling cooked-waker v5.0.0++ Compiling opaque-debug v0.3.1++ Compiling az v1.3.0++ Compiling static_assertions v1.1.0++ Compiling linux-raw-sys v0.12.1++ Compiling serde_urlencoded v0.7.1++ Compiling polyval v0.6.2++ Compiling fxhash v0.2.1++ Compiling cssparser v0.34.0++ Compiling tower-http v0.6.11++ Compiling hyper-rustls v0.27.9++ Compiling hmac v0.12.1++ Compiling sha1 v0.10.6++ Compiling deno_core v0.350.0++ Compiling derive_more v0.99.20++ Compiling match_token v0.1.0++ Compiling servo_arc v0.4.3++ Compiling fastrand v2.4.1++ Compiling tempfile v3.27.0++ Compiling html5ever v0.29.1++ Compiling rand_core v0.9.5++ Compiling reqwest v0.12.28++ Compiling ghash v0.5.1++ Compiling ctr v0.9.2++ Compiling aes v0.8.4++ Compiling async-trait v0.1.89++ Compiling aead v0.5.2++ Compiling encoding_rs v0.8.35++ Compiling aes-gcm v0.10.3++ Compiling ppv-lite86 v0.2.21++ Compiling obscura-dom v0.1.0 (/root/obscura2/merge471/crates/obscura-dom)++ Compiling hkdf v0.12.4++ Compiling pbkdf2 v0.12.2++ Compiling cbc v0.1.2++ Compiling sha2 v0.10.9++ Compiling rand_chacha v0.9.0++ Compiling utf8parse v0.2.2++ Compiling anstyle-parse v1.0.0++ Compiling rand v0.9.4++ Compiling obscura-net v0.1.0 (/root/obscura2/merge471/crates/obscura-net)++ Compiling colorchoice v1.0.5++ Compiling anstyle v1.0.14++ Compiling anstyle-query v1.1.5++ Compiling is_terminal_polyfill v1.70.2++ Compiling anstream v1.0.0++ Compiling tungstenite v0.26.2++ Compiling strsim v0.11.1++ Compiling lazy_static v1.5.0++ Compiling clap_lex v1.1.0++ Compiling obscura-js v0.1.0 (/root/obscura2/merge471/crates/obscura-js)++ Compiling clap_builder v4.6.0++ Compiling sharded-slab v0.1.7++ Compiling tokio-tungstenite v0.26.2++ Compiling tracing-log v0.2.0++ Compiling clap_derive v4.6.1++ Compiling thread_local v1.1.9++ Compiling nu-ansi-term v0.50.3++ Compiling obscura-cli v0.1.0 (/root/obscura2/merge471/crates/obscura-cli)++ Compiling matchers v0.2.0++ Compiling tracing-subscriber v0.3.23++ Compiling clap v4.6.1++ Compiling obscura-browser v0.1.0 (/root/obscura2/merge471/crates/obscura-browser)++ Compiling obscura-cdp v0.1.0 (/root/obscura2/merge471/crates/obscura-cdp)++ Compiling obscura-mcp v0.1.0 (/root/obscura2/merge471/crates/obscura-mcp)++ Finished `release` profile [optimized] target(s) in 1m 52sdiff --cc crates/obscura-js/js/bootstrap.jsindex aa0d7b20,6da34479..4a0f53f5--- a/crates/obscura-js/js/bootstrap.js+++ b/crates/obscura-js/js/bootstrap.js@@@ -2708,37 -2734,25 +2737,43 @@@ class Document extends Node}return null;},- previousSibling() {- let sibling = this.currentNode.previousSibling;- while (sibling) {- if (this._accept(sibling)) { this.currentNode = sibling; return sibling; }- sibling = sibling.previousSibling;+ // DOM 6.1 "traverse siblings" (issue #469).+ _traverseSiblings(edge, step) {+ let node = this.currentNode;+ if (node === this.root) return null;+ for (;;) {+ let sibling = node[step];+ while (sibling) {+ node = sibling;+ const verdict = this._filter(node);+ if (verdict === 1) { this.currentNode = node; return node; }+ // Descend into a skipped sibling's subtree; a rejected one is+ // off-limits, and a childless one has nothing to descend into.+ sibling = node[edge];+ if (verdict === 2 || !sibling) sibling = node[step];+ }+ node = node.parentNode;+ if (!node || node === this.root) return null;+ // An accepted parent is where the walk would go next, so there is no+ // sibling to return.+ if (this._filter(node) === 1) return null;}- return null;},+ firstChild() { return this._traverseChildren('firstChild', 'nextSibling'); },+ lastChild() { return this._traverseChildren('lastChild', 'previousSibling'); },+ nextSibling() { return this._traverseSiblings('firstChild', 'nextSibling'); },+ previousSibling() { return this._traverseSiblings('lastChild', 'previousSibling'); },+ // DOM 6.1 "parentNode" (issue #475). The old version looked only at the+ // immediate parent, so it couldn't climb past a skipped ancestor; it also+ // excluded `root` as a result yet stepped to root's own parent when- // currentNode was root — returning a node OUTSIDE the walker's subtree.++ // currentNode was root, returning a node OUTSIDE the walker's subtree.+ // The loop's `node !== this.root` guard is what keeps the walk inside+ // root while still allowing root itself to be returned.parentNode() {- let parent = this.currentNode.parentNode;- if (parent && parent !== this.root && this._accept(parent)) {- this.currentNode = parent;- return parent;+ let node = this.currentNode;+ while (node && node !== this.root) {+ node = node.parentNode;+ if (node && this._accept(node)) { this.currentNode = node; return node; }}return null;},diff --cc crates/obscura-js/src/runtime.rsindex 2afc9449,1871d5b5..fdfeb4d6--- a/crates/obscura-js/src/runtime.rs+++ b/crates/obscura-js/src/runtime.rs@@@ -1538,102 -1619,307 +1619,400 @@@ mod tests"#,).unwrap();- assert_eq!(result, serde_json::json!(["P", "A"]));+ // The rejected <section> is skipped but not pruned, so <p> still shows.+ // The leading root is #467: an iterator yields the node it is rooted at.+ assert_eq!(result, serde_json::json!(["DIV", "P", "A"]));+ }++ /// Issue #467: a NodeIterator starts *before* its root, so the first+ /// nextNode() returns the root itself. Aliasing createTreeWalker silently+ /// dropped exactly the element the iterator was rooted at.+ #[test]+ fn node_iterator_yields_the_root_node_first() {+ let mut rt = setup_runtime(r#"<div id="root"><a></a></div>"#);+ let result = rt+ .evaluate(+ r#"+ const root = document.getElementById('root');+ const it = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT);+ const seen = [];+ let node;+ while ((node = it.nextNode())) seen.push(node.tagName);+ return seen;+ "#,+ )+ .unwrap();+ assert_eq!(result, serde_json::json!(["DIV", "A"]));+ }++ /// Issue #467: the NodeIterator interface surface, and that TreeWalker-only+ /// members are not exposed on it.+ #[test]+ fn node_iterator_exposes_its_own_interface() {+ let mut rt = setup_runtime(r#"<div id="root"><a></a></div>"#);+ let result = rt+ .evaluate(+ r#"+ const root = document.getElementById('root');+ const it = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT);+ const before = [it.referenceNode === root, it.pointerBeforeReferenceNode];+ it.nextNode();+ return [+ before,+ typeof it.detach,+ it.detach() === undefined,+ typeof it.previousNode,+ it.root === root,+ it.whatToShow,+ // TreeWalker-only members must not leak onto a NodeIterator.+ typeof it.currentNode,+ typeof it.firstChild,+ typeof it.parentNode,+ // The pointer advanced past the root it just returned.+ [it.referenceNode.tagName, it.pointerBeforeReferenceNode],+ ];+ "#,+ )+ .unwrap();+ assert_eq!(+ result,+ serde_json::json!([+ [true, true],+ "function",+ true,+ "function",+ true,+ 1,+ "undefined",+ "undefined",+ "undefined",+ ["DIV", false]+ ])+ );+ }++ /// Issue #467: previousNode() retraces the iterator, and the root is the+ /// last node it yields going backwards.+ #[test]+ fn node_iterator_previous_node_retraces_the_walk() {+ let mut rt = setup_runtime(r#"<div id="root"><a><b></b></a><c></c></div>"#);+ let result = rt+ .evaluate(+ r#"+ const root = document.getElementById('root');+ const it = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT);+ const forward = [];+ let node;+ while ((node = it.nextNode())) forward.push(node.tagName);+ const backward = [];+ while ((node = it.previousNode())) backward.push(node.tagName);+ return [forward, backward];+ "#,+ )+ .unwrap();+ // Forward ends on <c>; going back re-yields <c> (the pointer sits after+ // it), then the rest in reverse, root included.+ assert_eq!(+ result,+ serde_json::json!([+ ["DIV", "A", "B", "C"],+ ["C", "B", "A", "DIV"]+ ])+ );+ }++ /// Issue #463: `<template>` contents are parsed into the node's+ /// `template_contents` document, but no op exposed it, so `.content` handed+ /// back a fabricated empty fragment and the parsed markup was unreachable.+ #[test]+ fn template_content_exposes_parsed_markup() {+ let mut rt = setup_runtime(+ r#"<body><template id="t"><p class="row">a</p><p class="row">b</p></template></body>"#,+ );+ let result = rt+ .evaluate(+ r#"+ const t = document.getElementById('t');+ return [+ t.content.childNodes.length,+ t.content.querySelectorAll('.row').length,+ t.content.firstElementChild.textContent,+ t.innerHTML,+ t.content.nodeType,+ t.content instanceof DocumentFragment,+ // Identity is stable: frameworks stash `.content` and reuse it.+ t.content === t.content,+ // The children stay off the element itself, per the HTML spec.+ t.childNodes.length,+ ];+ "#,+ )+ .unwrap();+ assert_eq!(+ result,+ serde_json::json!([+ 2,+ 2,+ "a",+ r#"<p class="row">a</p><p class="row">b</p>"#,+ 11,+ true,+ true,+ 0+ ])+ );+ }++ /// Issue #463: the same must hold for a template that arrives via innerHTML+ /// rather than the initial document parse — that is how most frameworks+ /// inject templates.+ #[test]+ fn template_content_works_for_templates_added_via_inner_html() {+ let mut rt = setup_runtime(r#"<body><div id="host"></div></body>"#);+ let result = rt+ .evaluate(+ r#"+ const host = document.getElementById('host');+ host.innerHTML = '<template id="t2"><li class="item">x</li></template>';+ const t = document.getElementById('t2');+ const stamped = t.content.cloneNode(true);+ host.appendChild(stamped);+ return [+ t.content.childNodes.length,+ t.content.querySelector('.item').textContent,+ host.querySelectorAll('li.item').length,+ ];+ "#,+ )+ .unwrap();+ // cloneNode(true) of the content is the canonical stamping idiom.+ assert_eq!(result, serde_json::json!([1, "x", 1]));+ }++ /// Issue #463: a template built with createElement has no parsed contents,+ /// so `.content` must allocate a backing fragment on demand and round-trip+ /// through innerHTML.+ #[test]+ fn template_content_round_trips_for_created_templates() {+ let mut rt = setup_runtime(r#"<body></body>"#);+ let result = rt+ .evaluate(+ r#"+ const t = document.createElement('template');+ t.innerHTML = '<span class="s">hi</span>';+ return [+ t.content.childNodes.length,+ t.content.querySelector('.s').textContent,+ t.innerHTML,+ t.childNodes.length,+ ];+ "#,+ )+ .unwrap();+ assert_eq!(+ result,+ serde_json::json!([1, "hi", r#"<span class="s">hi</span>"#, 0])+ );+ }++ /// Issue #463: serializing a `<template>` must emit its contents, or the+ /// markup silently disappears from outerHTML/innerHTML round-trips — and+ /// `cloneNode(true)`, which round-trips through outer_html, yields an empty+ /// template.+ #[test]+ fn template_contents_survive_serialization_and_clone() {+ let mut rt = setup_runtime(+ r#"<body><template id="t"><li class="item">x</li></template></body>"#,+ );+ let result = rt+ .evaluate(+ r#"+ const t = document.getElementById('t');+ const clone = t.cloneNode(true);+ return [+ t.outerHTML,+ document.body.innerHTML,+ clone.content.childNodes.length,+ clone.content.querySelector('.item').textContent,+ // The clone's contents are its own, not shared with the original.+ (clone.content.firstElementChild === t.content.firstElementChild),+ ];+ "#,+ )+ .unwrap();+ let expected = r#"<template id="t"><li class="item">x</li></template>"#;+ assert_eq!(+ result,+ serde_json::json!([expected, expected, 1, "x", false])+ );+ }++ /// Issue #468: window.scrollTo/scrollBy/scroll were no-op stubs, so the+ /// dominant infinite-scroll idiom never advanced the page offset.+ #[test]+ fn window_scroll_methods_move_the_page_offset() {+ let mut rt = setup_runtime(r#"<html><body><div id="d"></div></body></html>"#);+ let result = rt+ .evaluate(+ r#"+ const scrolled = window.scrollTo(0, 500);+ const afterTo = [window.scrollX, window.scrollY];+ window.scrollBy(0, 200);+ const afterBy = [window.pageXOffset, window.pageYOffset];+ window.scrollTo({ left: 10, top: 40 });+ const afterOptions = [window.scrollX, window.scrollY];+ window.scroll(5, 5);+ const afterScroll = [window.scrollX, window.scrollY];+ // Negative offsets clamp to 0, as they do for elements.+ window.scrollTo(0, -100);+ return [afterTo, afterBy, afterOptions, afterScroll, window.scrollY];+ "#,+ )+ .unwrap();+ assert_eq!(+ result,+ serde_json::json!([[0, 500], [0, 700], [10, 40], [5, 5], 0])+ );+ }++ /// Issue #468: the page offset is one value, readable and writable through+ /// either `window.scrollY` or `document.scrollingElement.scrollTop`.+ #[test]+ fn window_scroll_offset_is_shared_with_the_scrolling_element() {+ let mut rt = setup_runtime(r#"<html><body><div id="d"></div></body></html>"#);+ let result = rt+ .evaluate(+ r#"+ const isDocEl = document.scrollingElement === document.documentElement;+ window.scrollTo(0, 300);+ // Written through the window, read through the element...+ const viaElement = document.scrollingElement.scrollTop;+ // ...and the reverse.+ document.scrollingElement.scrollTop = 90;+ return [isDocEl, viaElement, window.scrollY, window.pageYOffset];+ "#,+ )+ .unwrap();+ assert_eq!(result, serde_json::json!([true, 300, 90, 90]));+ }++ /// Issue #468: a scroll event must reach listeners on both the window and+ /// the document — that is the signal lazy loaders wait for.+ #[tokio::test(flavor = "current_thread")]+ async fn window_scroll_fires_a_scroll_event() {+ let mut rt = setup_runtime(r#"<html><body><div id="d"></div></body></html>"#);+ let result = rt+ .evaluate_for_cdp(+ r#"+ new Promise(resolve => {+ let win = 0, doc = 0;+ window.addEventListener('scroll', () => win++);+ document.addEventListener('scroll', () => doc++);+ window.scrollBy(0, 400);+ setTimeout(() => resolve([win, doc, window.scrollY]), 5);+ })+ "#,+ true,+ true,+ )+ .await+ .unwrap();+ assert_eq!(result.value.unwrap(), serde_json::json!([1, 1, 400]));}+ /// Issue #469: FILTER_SKIP leaves a skipped node's children eligible, so+ /// firstChild()/lastChild() must descend into them. FILTER_REJECT must not.+ #[test]+ fn tree_walker_child_movers_descend_on_skip_but_not_on_reject() {+ let mut rt = setup_runtime(+ r#"<div id="root"><section><a></a><b></b></section></div>"#,+ );+ let result = rt+ .evaluate(+ r#"+ const root = document.getElementById('root');+ function mover(verdict, method) {+ const w = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {+ acceptNode(node) {+ return node.tagName === 'SECTION' ? verdict : NodeFilter.FILTER_ACCEPT;+ }+ });+ const found = w[method]();+ return found ? found.tagName : null;+ }+ return [+ mover(NodeFilter.FILTER_SKIP, 'firstChild'),+ mover(NodeFilter.FILTER_SKIP, 'lastChild'),+ mover(NodeFilter.FILTER_REJECT, 'firstChild'),+ mover(NodeFilter.FILTER_REJECT, 'lastChild'),+ ];+ "#,+ )+ .unwrap();+ // SKIP descends into <section>; REJECT prunes it and finds nothing else.+ assert_eq!(result, serde_json::json!(["A", "B", null, null]));+ }++ /// Issue #469: nextSibling()/previousSibling() must descend into a skipped+ /// sibling's subtree rather than stepping straight over it.+ #[test]+ fn tree_walker_sibling_movers_descend_into_skipped_siblings() {+ let mut rt = setup_runtime(+ r#"<div id="root"><p id="start"></p><section><a></a></section><q></q></div>"#,+ );+ let result = rt+ .evaluate(+ r#"+ const root = document.getElementById('root');+ function mover(verdict, method, from) {+ const w = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {+ acceptNode(node) {+ return node.tagName === 'SECTION' ? verdict : NodeFilter.FILTER_ACCEPT;+ }+ });+ w.currentNode = document.getElementById(from);+ const found = w[method]();+ return found ? found.tagName : null;+ }+ return [+ // <section> is skipped, so its child <a> is the next sibling.+ mover(NodeFilter.FILTER_SKIP, 'nextSibling', 'start'),+ // Rejected: the subtree is off-limits, so skip past to <q>.+ mover(NodeFilter.FILTER_REJECT, 'nextSibling', 'start'),+ ];+ "#,+ )+ .unwrap();+ assert_eq!(result, serde_json::json!(["A", "Q"]));+ }++ /// Issue #469: the backward sibling mover descends to *last* children.+ #[test]+ fn tree_walker_previous_sibling_descends_to_last_child() {+ let mut rt = setup_runtime(+ r#"<div id="root"><section><a></a><b></b></section><p id="start"></p></div>"#,+ );+ let result = rt+ .evaluate(+ r#"+ const root = document.getElementById('root');+ const w = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {+ acceptNode(node) {+ return node.tagName === 'SECTION'+ ? NodeFilter.FILTER_SKIP+ : NodeFilter.FILTER_ACCEPT;+ }+ });+ w.currentNode = document.getElementById('start');+ const found = w.previousSibling();+ return found ? found.tagName : null;+ "#,+ )+ .unwrap();+ // Reverse order descends to <section>'s last child, not its first.+ assert_eq!(result, serde_json::json!("B"));+ }+#[test]fn append_child_flattens_document_fragment() {let mut rt = setup_runtime(r#"<main id="host"></main>"#);