wailsapp/wails · error
no element matches selector: ' + selector
Error message
no element matches selector: ' + selector
What it means
CoCreateInstance creates a COM object from a CLSID; the w32 wrapper panics with 'CoCreateInstance failed with E_INVALIDARG' when the HRESULT is E_INVALIDARG. For this API that means one of the pointer arguments is bad: a nil/null riid, a clsid pointer that is not a valid GUID, an out-of-range dwClsContext, or an invalid ppv output address. Notably REGDB_E_CLASSNOTREGISTERED and E_NOINTERFACE — the common 'missing class' errors — are returned, not panicked, so this specific panic is an argument bug in the caller's marshaling.
Source
Thrown at v3/pkg/application/mcp_tools_enabled.go:262
return m.mcpEvalTool(args, js)
},
},
{
Name: "dom_html",
Description: "Get the HTML of the page or of the first element matching a selector. " +
"Useful for inspecting the UI before interacting with it.",
Schema: mcpObjectSchema(nil, map[string]any{
"selector": mcpProp("string", "CSS selector. Defaults to the whole document."),
"max_bytes": mcpProp("number", "Maximum HTML length to return. Defaults to 100000."),
"window": mcpWindowProp(),
}),
Handler: func(args map[string]any) (any, error) {
selector, _ := mcpArgString(args, "selector")
maxBytes := mcpArgInt(args, "max_bytes", 100_000)
return m.mcpEvalTool(args, fmt.Sprintf(`
const selector = %s, maxBytes = %d;
const el = selector ? document.querySelector(selector) : document.documentElement;
if (!el) throw new Error('no element matches selector: ' + selector);
const html = el.outerHTML;
return {
html: html.length > maxBytes ? html.slice(0, maxBytes) : html,
truncated: html.length > maxBytes,
totalLength: html.length,
};`,
strconv.Quote(selector), maxBytes))
},
},
{
Name: "dom_query",
Description: "Find elements by CSS selector and return a summary of each: tag, id, classes, text, " +
"value, viewport bounds and visibility. Use this to discover what to click or type into.",
Schema: mcpObjectSchema([]string{"selector"}, map[string]any{
"selector": mcpProp("string", "CSS selector to query."),
"limit": mcpProp("number", "Maximum number of elements to return. Defaults to 25."),
"window": mcpWindowProp(),
}),View on GitHub (pinned to 0e754b1b40)
Solutions
- Ensure clsid and riid are valid, fully initialized *syscall.GUID (use GUIDFromString and check its error).
- Pass ppv as a pointer to a real pointer variable created in the same call expression: uintptr(unsafe.Pointer(&obj)).
- Use a legal dwClsContext such as CLSCTX_ALL or CLSCTX_INPROC_SERVER from the w32 constants.
- Test the same CLSID/IID pair in a minimal script (PowerShell New-Object -ComObject) to confirm the identifiers themselves are correct.
Example fix
// before
var clsid syscall.GUID // zero value!
var obj uintptr
CoCreateInstance(&clsid, CLSCTX_ALL, nil, obj) // nil riid, zero guid -> E_INVALIDARG
// after
clsid, _ := windows.GUIDFromString("{...}")
riid, _ := windows.GUIDFromString("{00000000-0000-0000-C000-000000000046}") // IUnknown
var obj *syscall.GUID // real pointer target
CoCreateInstance(&clsid, CLSCTX_ALL, &riid, uintptr(unsafe.Pointer(&obj))) Defensive patterns
Strategy: validation
Validate before calling
func validCreateInstanceArgs(clsid, riid *syscall.GUID, ctx uintptr, ppv uintptr) bool {
return clsid != nil && riid != nil && ppv != 0 && ctx != 0
}
// usage: build GUIDs via GUIDFromString and check errors before calling Prevention
- Build GUIDs with GUIDFromString and check the error; never pass zero-value GUIDs.
- Pass ppv as uintptr(unsafe.Pointer(&obj)) with obj a real pointer variable in the same expression.
- Use w32 CLSCTX constants for the context argument.
When it happens
Trigger: Passing nil for riid because the IID was assumed optional; passing an uninitialized syscall.GUID for clsid; using a ppv uintptr that points at a Go value that was garbage-collected or is not a pointer to pointer; giving dwClsContext a value outside CLSCTX_INPROC_SERVER/LOCAL_SERVER/etc. flags.
Common situations: Hand-written syscall wrappers for a COM API where the GUID structs are populated from wrong-endian hex strings; unsafe.Pointer-to-uintptr conversions done outside the call expression letting the GC move the target; upgrading Go versions where pointer rules tightened and old conversion patterns became invalid.
Related errors
- element has zero size (is it hidden?): ' + target.selector
- target requires a selector or x/y coordinates
- failed to init GTK
- Invalid JSON passed to callback: ${e.message}. Message: ${in
- Callback '${callbackID}' not registered!!!
AI-assisted analysis of wailsapp/wails@0e754b1b40 (2026-08-15).
Data as JSON: /api/errors/6723bf6af19a146d.
Report an issue: GitHub.