{"record":{"id":"1e1f00971ec3b85a","repo":"DioxusLabs/dioxus","slug":"this-code-should-be-running-in-a-web-context","errorCode":null,"errorMessage":"this code should be running in a web context","messagePattern":"this code should be running in a web context","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/web/src/devtools.rs","lineNumber":289,"sourceCode":"            // Remove the old force reload param\n            query_params.retain(|param| !param.starts_with(\"dx_force_reload=\"));\n            // Add the new force reload param\n            let force_reload = format!(\"dx_force_reload={noise}\");\n            query_params.push(&force_reload);\n\n            // Rejoin the query\n            let query = query_params.join(\"&\");\n\n            _ = link.set_attribute(\"href\", &format!(\"{url}?{query}\"));\n        }\n    }\n}\n\n/// Initialize required devtools for dioxus-playground.\n///\n/// This listens for window message events from other Windows (such as window.top when this is running in an iframe).\nfn playground(tx: UnboundedSender<HotReloadMsg>) {\n    let window = web_sys::window().expect(\"this code should be running in a web context\");\n\n    let binding = Closure::<dyn FnMut(MessageEvent)>::new(move |e: MessageEvent| {\n        let Ok(text) = e.data().dyn_into::<JsString>() else {\n            return;\n        };\n        let string: String = text.into();\n        let Ok(hr_msg) = serde_json::from_str::<HotReloadMsg>(&string) else {\n            return;\n        };\n        _ = tx.unbounded_send(hr_msg);\n    });\n\n    let callback = binding.as_ref().unchecked_ref();\n    window\n        .add_event_listener_with_callback(\"message\", callback)\n        .expect(\"event listener should be added successfully\");\n\n    binding.forget();","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/24f6a829df0dfa203961a98ea4cae21c2ff27e28/packages/web/src/devtools.rs#L271-L307","documentation":"The playground devtools code called web_sys::window() in a context where no global window exists — i.e. the code is not running in a browser/web environment (or runs in a non-window context such as a worker without DOM).","triggerScenarios":"Thrown at packages/web/src/devtools.rs:289 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Only call this devtools code in a web (WASM) context; guard it with cfg(target_arch = \"wasm32\") or platform checks."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"24f6a829df0dfa203961a98ea4cae21c2ff27e28","analyzedAt":"2026-08-23T07:10:14.078Z","contentChangedAt":"2026-08-23T07:10:14.078Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}