wasm-bindgen icon indicating copy to clipboard operation
wasm-bindgen copied to clipboard

Can't downcast Node of HTMLHeadingElement

Open andrewbaxter opened this issue 4 months ago • 0 comments

I have

let html_children0 = idoc.query_selector_all("h1,h2,h3,h4,h5,h6,p,img").unwrap();
...
let child = html_children0.item(i).unwrap().dyn_into::<HtmlElement>().unwrap();

This panics when trying to dyn_into with:

called `Result::unwrap()` on an `Err` value: Node { obj: EventTarget { obj: Object { obj: JsValue(HTMLHeadingElement) } } }

I'm not sure what to make of this. is_instance_of returns false for Element HtmlElement and HtmlHeadingElement. I'm pretty sure I've casted nodes to HtmlElement before.

Since I'm half rubber ducking here, it might be significant that this is in an iframe. ...And yeah, doing a search I do see a suggestion about something similar: https://github.com/rustwasm/wasm-bindgen/issues/1367 (although that sounds like it was eventually something about boxed elements?)

Originally posted by @andrewbaxter in https://github.com/rustwasm/wasm-bindgen/discussions/4519 - sorry, still not sure if this is an issue or I'm just doing something dumb, but I figured it's at least subtle if nobody's attempted to answer it in discussions

andrewbaxter avatar Jun 13 '25 15:06 andrewbaxter