unoplatform/uno · error · Error
BrowserHtmlElement: Element with id '${id}' not found.
Error message
BrowserHtmlElement: Element with id '${id}' not found. What it means
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.
Source
Thrown at src/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/BrowserNativeElementHostingExtension.ts:231
return String(eval(command) || "");
}
public static async invokeAsync(command: string): Promise<string> {
// Preseve the original emscripten marshalling semantics
// to always return a valid string.
var result = await eval(command);
return String(result || "");
}
/**
* Returns the element with the given id, or throws an error if not found.
*/
private static getElementOrThrow(id: string): HTMLElement {
const element = document.getElementById(id);
if (!element) {
throw new Error(`BrowserHtmlElement: Element with id '${id}' not found.`);
}
return element as HTMLElement;
}
}
}
View on GitHub (pinned to 0418340488)
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.
Example fix
// before: id does not exist in DOM yet
const el = document.getElementById('my-div-42'); // null → throws
// after: ensure the element is created and appended before retrieval
const el = document.createElement('div');
el.id = 'my-div-42';
document.body.appendChild(el);
// now getElementOrThrow('my-div-42') succeeds Defensive patterns
Strategy: validation
Validate before calling
// Verify element exists before requesting it via the interop
if (!document.getElementById(id)) {
console.warn(`Element ${id} not in DOM yet`);
return null;
} Try / catch
try {
// call the native element hosting interop
} catch (e) {
if (e.message.includes("not found")) {
// element was removed or never inserted — retry after DOM update
} else { throw e; }
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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).
Related errors
- retrieveFiles failed to find pending drag and drop data for
- Keyboard lock is not supported by this browser.
- Function ${funcName} returned an unsupported type: ${typeof
- A DragDropExtension has already been enabled
- The current DragDropExtension does not match the provided ar
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/0996a8b0db9a6898.
Report an issue: GitHub.