{"record":{"id":"4d4f74046b0d56d3","repo":"DioxusLabs/dioxus","slug":"head-element-to-exist","errorCode":null,"errorMessage":"Head element to exist","messagePattern":"Head element to exist","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/desktop/src/protocol.rs","lineNumber":122,"sourceCode":"    request: &Request<Vec<u8>>,\n    custom_head: Option<String>,\n    custom_index: Option<String>,\n    root_name: &str,\n    headless: bool,\n    edit_state: &WebviewEdits,\n) -> Option<Response<Vec<u8>>> {\n    // If the request is for the root, we'll serve the index.html file.\n    if request.uri().path() != \"/\" {\n        return None;\n    }\n\n    // Load a custom index file if provided\n    let mut index = custom_index.unwrap_or_else(|| DEFAULT_INDEX.to_string());\n\n    // Insert a custom head if provided\n    // We look just for the closing head tag. If a user provided a custom index with weird syntax, this might fail\n    if let Some(head) = custom_head {\n        index.insert_str(index.find(\"</head>\").expect(\"Head element to exist\"), &head);\n    }\n\n    // Inject our module loader by looking for a body tag\n    // A failure mode here, obviously, is if the user provided a custom index without a body tag\n    // Might want to document this\n    index.insert_str(\n        index.find(\"</body>\").expect(\"Body element to exist\"),\n        &module_loader(root_name, headless, edit_state),\n    );\n\n    Response::builder()\n        .header(\"Content-Type\", \"text/html\")\n        .header(\"Access-Control-Allow-Origin\", \"*\")\n        .body(index.into())\n        .ok()\n}\n\n/// Construct the inline script that boots up the page and bridges the webview with rust code.","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/24f6a829df0dfa203961a98ea4cae21c2ff27e28/packages/desktop/src/protocol.rs#L104-L140","documentation":"The desktop server tried to splice a custom head into the served index.html but the string \"</head>\" was not found. The custom index file lacks a well-formed closing head tag, so the insertion point cannot be located.","triggerScenarios":"Thrown at packages/desktop/src/protocol.rs:122 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure your index.html contains a <head> element; the desktop renderer injects its protocol content into <head>."],"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-23T08:17:48.524Z"}