{"record":{"id":"0996a8b0db9a6898","repo":"unoplatform/uno","slug":"browserhtmlelement-element-with-id-id-not-fo","errorCode":null,"errorMessage":"BrowserHtmlElement: Element with id '${id}' not found.","messagePattern":"BrowserHtmlElement: Element with id '(.+?)' not found\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/BrowserNativeElementHostingExtension.ts","lineNumber":231,"sourceCode":"\t\t\treturn String(eval(command) || \"\");\n\t\t}\n\n\t\tpublic static async invokeAsync(command: string): Promise<string> {\n\t\t\t// Preseve the original emscripten marshalling semantics\n\t\t\t// to always return a valid string.\n\t\t\tvar result = await eval(command);\n\n\t\t\treturn String(result || \"\");\n\n\t\t}\n\n\t\t/**\n\t\t * Returns the element with the given id, or throws an error if not found.\n\t\t */\n\t\tprivate static getElementOrThrow(id: string): HTMLElement {\n\t\t\tconst element = document.getElementById(id);\n\t\t\tif (!element) {\n\t\t\t\tthrow new Error(`BrowserHtmlElement: Element with id '${id}' not found.`);\n\t\t\t}\n\t\t\treturn element as HTMLElement;\n\t\t}\n\t}\n}\n","sourceCodeStart":213,"sourceCodeEnd":237,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/BrowserNativeElementHostingExtension.ts#L213-L237","documentation":"Thrown by the private getElementOrThrow helper in BrowserNativeElementHostingExtension when document.getElementById(id) returns null. This means the C# side (a BrowserHtmlElement / native element host) requested an HTML element by ID that does not exist in the current DOM.","triggerScenarios":"C# calls the native-element-hosting interop with an element id string that has not been registered/inserted into the DOM, or was already removed (e.g. element was detached during a visual-tree update before the interop call arrived).","commonSituations":"Element ID typo or mismatch between the C# managed HTML element wrapper and the DOM, element removed during a layout pass before retrieval, or the element was never attached (e.g. the hosting XAML element was never loaded into the visual tree).","solutions":["Verify the element id string passed from C# matches the id attribute set on the DOM element at insertion time.","Ensure the HTML element is attached to the DOM before issuing the getElement call (wait for the element's Loaded event).","Check that the element was not disposed/removed by a visual-tree update between insertion and retrieval."],"exampleFix":"// before: id does not exist in DOM yet\nconst el = document.getElementById('my-div-42'); // null → throws\n\n// after: ensure the element is created and appended before retrieval\nconst el = document.createElement('div');\nel.id = 'my-div-42';\ndocument.body.appendChild(el);\n// now getElementOrThrow('my-div-42') succeeds","handlingStrategy":"validation","validationCode":"// Verify element exists before requesting it via the interop\nif (!document.getElementById(id)) {\n    console.warn(`Element ${id} not in DOM yet`);\n    return null;\n}","typeGuard":null,"tryCatchPattern":"try {\n    // call the native element hosting interop\n} catch (e) {\n    if (e.message.includes(\"not found\")) {\n        // element was removed or never inserted — retry after DOM update\n    } else { throw e; }\n}","preventionTips":["Wait for the element's Loaded event before issuing getElement calls from C#.","Keep element ids stable and documented between the C# wrapper and the DOM.","Avoid disposing/removing DOM elements while pending interop calls are in flight."],"tags":["wasm","browser","dom","native-element-hosting","typescript"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}