{"record":{"id":"89430d37b4518ac0","repo":"DioxusLabs/dioxus","slug":"should-have-access-to-the-window","errorCode":null,"errorMessage":"should have access to the Window","messagePattern":"should have access to the Window","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/web/src/events/mod.rs","lineNumber":284,"sourceCode":"    raw: Event,\n    element: Element,\n}\n\n// todo: some of these events are being casted to the wrong event type.\n// We need tests that simulate clicks/etc and make sure every event type works.\npub(crate) fn virtual_event_from_websys_event(\n    event: web_sys::Event,\n    target: Element,\n) -> PlatformEventData {\n    PlatformEventData::new(Box::new(GenericWebSysEvent {\n        raw: event,\n        element: target,\n    }))\n}\n\npub(crate) fn load_document() -> Document {\n    web_sys::window()\n        .expect(\"should have access to the Window\")\n        .document()\n        .expect(\"should have access to the Document\")\n}\n","sourceCodeStart":266,"sourceCodeEnd":288,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/393d190a801ccb441d41923e232289b4f8a5c669/packages/web/src/events/mod.rs#L266-L288","documentation":"`load_document()` in dioxus-web's event module calls `web_sys::window().expect(\"should have access to the Window\")`. `web_sys::window()` is None wherever no Window global exists - web workers, Node/SSR processes, non-browser wasm runtimes - so the renderer panics the first time its event machinery needs the document in such a context.","triggerScenarios":"Loading or running dioxus-web inside a web worker (no Window global); executing web-renderer event code during server-side rendering because the web crate was linked into the server build; wasm-bindgen-test runs outside a browser page.","commonSituations":"Fullstack apps without cfg-gating renderer-specific code; experiments moving UI into workers; feature misconfiguration pulling dioxus::web into a non-browser target.","solutions":["Launch the web renderer only from the browser main thread (wasm-bindgen start inside an HTML page)","Gate web-only code with `#[cfg(target_arch = \"wasm32\")]` and select the correct renderer per platform","In tests or SSR, use the server/memory renderer instead of dioxus-web","Check `web_sys::window().is_some()` before entering code paths that depend on web event APIs"],"exampleFix":"// before: compiled for every target, panics on the server/worker\nfn setup_events() { /* dioxus-web event wiring */ }\n// after: only compiled for the browser\n#[cfg(target_arch = \"wasm32\")]\nfn setup_events() { /* dioxus-web event wiring */ }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn has_browser_window() -> bool {\n    web_sys::window().is_some()\n}","tryCatchPattern":null,"preventionTips":["Never run dioxus-web in a web worker - the renderer requires the Window global (use liveview or another renderer for worker contexts)","cfg-gate browser-only code with #[cfg(target_arch = \"wasm32\")] so SSR/server builds cannot link it","Feature-detect with web_sys::window().is_some() at startup and fail with a clear message instead of letting event code panic"],"tags":["dioxus-web","wasm","window","environment","ssr","panic"],"backgroundTag":null,"analyzedSha":"393d190a801ccb441d41923e232289b4f8a5c669","analyzedAt":"2026-08-16T11:27:45.815Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}