{"record":{"id":"6723bf6af19a146d","repo":"wailsapp/wails","slug":"no-element-matches-selector-selector","errorCode":null,"errorMessage":"no element matches selector: ' + selector","messagePattern":"no element matches selector: ' \\+ selector","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/pkg/application/mcp_tools_enabled.go","lineNumber":262,"sourceCode":"\t\t\t\treturn m.mcpEvalTool(args, js)\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tName: \"dom_html\",\n\t\t\tDescription: \"Get the HTML of the page or of the first element matching a selector. \" +\n\t\t\t\t\"Useful for inspecting the UI before interacting with it.\",\n\t\t\tSchema: mcpObjectSchema(nil, map[string]any{\n\t\t\t\t\"selector\":  mcpProp(\"string\", \"CSS selector. Defaults to the whole document.\"),\n\t\t\t\t\"max_bytes\": mcpProp(\"number\", \"Maximum HTML length to return. Defaults to 100000.\"),\n\t\t\t\t\"window\":    mcpWindowProp(),\n\t\t\t}),\n\t\t\tHandler: func(args map[string]any) (any, error) {\n\t\t\t\tselector, _ := mcpArgString(args, \"selector\")\n\t\t\t\tmaxBytes := mcpArgInt(args, \"max_bytes\", 100_000)\n\t\t\t\treturn m.mcpEvalTool(args, fmt.Sprintf(`\n\t\t\t\t\tconst selector = %s, maxBytes = %d;\n\t\t\t\t\tconst el = selector ? document.querySelector(selector) : document.documentElement;\n\t\t\t\t\tif (!el) throw new Error('no element matches selector: ' + selector);\n\t\t\t\t\tconst html = el.outerHTML;\n\t\t\t\t\treturn {\n\t\t\t\t\t\thtml: html.length > maxBytes ? html.slice(0, maxBytes) : html,\n\t\t\t\t\t\ttruncated: html.length > maxBytes,\n\t\t\t\t\t\ttotalLength: html.length,\n\t\t\t\t\t};`,\n\t\t\t\t\tstrconv.Quote(selector), maxBytes))\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tName: \"dom_query\",\n\t\t\tDescription: \"Find elements by CSS selector and return a summary of each: tag, id, classes, text, \" +\n\t\t\t\t\"value, viewport bounds and visibility. Use this to discover what to click or type into.\",\n\t\t\tSchema: mcpObjectSchema([]string{\"selector\"}, map[string]any{\n\t\t\t\t\"selector\": mcpProp(\"string\", \"CSS selector to query.\"),\n\t\t\t\t\"limit\":    mcpProp(\"number\", \"Maximum number of elements to return. Defaults to 25.\"),\n\t\t\t\t\"window\":   mcpWindowProp(),\n\t\t\t}),","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v3/pkg/application/mcp_tools_enabled.go#L244-L280","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar clsid syscall.GUID // zero value!\nvar obj uintptr\nCoCreateInstance(&clsid, CLSCTX_ALL, nil, obj) // nil riid, zero guid -> E_INVALIDARG\n\n// after\nclsid, _ := windows.GUIDFromString(\"{...}\")\nriid, _ := windows.GUIDFromString(\"{00000000-0000-0000-C000-000000000046}\") // IUnknown\nvar obj *syscall.GUID // real pointer target\nCoCreateInstance(&clsid, CLSCTX_ALL, &riid, uintptr(unsafe.Pointer(&obj)))","handlingStrategy":"validation","validationCode":"func validCreateInstanceArgs(clsid, riid *syscall.GUID, ctx uintptr, ppv uintptr) bool {\n\treturn clsid != nil && riid != nil && ppv != 0 && ctx != 0\n}\n\n// usage: build GUIDs via GUIDFromString and check errors before calling","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["windows","com","marshaling","syscall","panic"],"backgroundTag":null,"analyzedSha":"0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3","analyzedAt":"2026-08-15T14:17:36.034Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}