{"record":{"id":"5d0a80fede260e57","repo":"DioxusLabs/dioxus","slug":"event-listener-should-be-added-successfully","errorCode":null,"errorMessage":"event listener should be added successfully","messagePattern":"event listener should be added successfully","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/web/src/devtools.rs","lineNumber":305,"sourceCode":"/// 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();\n}\n\nfn hook_impl(info: &std::panic::PanicHookInfo) {\n    #[wasm_bindgen]\n    extern \"C\" {\n        #[wasm_bindgen(js_namespace = console)]\n        fn error(msg: String);\n\n        type Error;\n\n        #[wasm_bindgen(constructor)]\n        fn new() -> Error;\n\n        #[wasm_bindgen(structural, method, getter)]\n        fn stack(error: &Error) -> String;\n    }","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/24f6a829df0dfa203961a98ea4cae21c2ff27e28/packages/web/src/devtools.rs#L287-L323","documentation":"The devtools playground registers a window `message` event listener and `expect`s `add_event_listener_with_callback` to succeed. This panic fires if the browser refuses to attach the listener (rare; e.g. invalid closure or unsupported context), breaking hot-reload message receiving in the playground iframe.","triggerScenarios":"Thrown at packages/web/src/devtools.rs:305 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the event target exists and supports the event listener being registered; check the browser console for the underlying DOM exception."],"exampleFix":null,"handlingStrategy":"fallback","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"}