Following from rust-windowing/winit#2259, the WebWindowHandle.id is a flaky way to share canvas references between crates. As discussed in that thread, synchronizing the IDs is challenging (leading to duplicates) and it isn't possible to query canvas elements in a Shadow DOM or offscreen canvases at all.
What consumers need is a way to pass the canvas reference through HasRawWindowHandle. AFAICT, that can be done with either an enum with variants for web_sys::HtmlCanvasElement and web_sys::OffscreenCanvas, or with wasm_bindgen::JsValue. It looks like another option is the FromWasmAbi and IntoWasmAbi traits provided by wasm_bindgen if the reference needs to cross the WASM ABI boundary for some reason.
I think the best way forward in the short-term is a feature to enable the use of one of these reference types in addition to the id: u32. It is preferable to replace the id entirely but may not be realistic without a deprecation period. The feature also mitigates a potential downside that it adds a dependency on web_sys and/or wasm_bindgen.
Open to discussion and other alternatives, but the current design appears to be a significant shortcoming in web environments.
Following from rust-windowing/winit#2259, the
WebWindowHandle.idis a flaky way to share canvas references between crates. As discussed in that thread, synchronizing the IDs is challenging (leading to duplicates) and it isn't possible to query canvas elements in a Shadow DOM or offscreen canvases at all.What consumers need is a way to pass the canvas reference through
HasRawWindowHandle. AFAICT, that can be done with either an enum with variants forweb_sys::HtmlCanvasElementandweb_sys::OffscreenCanvas, or withwasm_bindgen::JsValue. It looks like another option is theFromWasmAbiandIntoWasmAbitraits provided bywasm_bindgenif the reference needs to cross the WASM ABI boundary for some reason.I think the best way forward in the short-term is a feature to enable the use of one of these reference types in addition to the
id: u32. It is preferable to replace the id entirely but may not be realistic without a deprecation period. The feature also mitigates a potential downside that it adds a dependency onweb_sysand/orwasm_bindgen.Open to discussion and other alternatives, but the current design appears to be a significant shortcoming in web environments.