{"record":{"id":"334e1ebc7d230fc0","repo":"wailsapp/wails","slug":"no-element-matches-selector-target-selector","errorCode":null,"errorMessage":"no element matches selector: ' + target.selector","messagePattern":"no element matches selector: ' \\+ target\\.selector","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/pkg/application/mcp_inject.js","lineNumber":289,"sourceCode":"            bounds: {\n                x: Math.round(rect.x),\n                y: Math.round(rect.y),\n                width: Math.round(rect.width),\n                height: Math.round(rect.height),\n            },\n        };\n        if ('value' in el && typeof el.value === 'string') description.value = el.value.slice(0, 500);\n        if (el.disabled) description.disabled = true;\n        if (el.href) description.href = el.href;\n        return description;\n    }\n\n    // Resolve {selector} or {x, y} into concrete viewport coordinates,\n    // scrolling selector targets into view first.\n    async function resolveTarget(target) {\n        if (target && target.selector) {\n            const el = document.querySelector(target.selector);\n            if (!el) throw new Error('no element matches selector: ' + target.selector);\n            el.scrollIntoView({ block: 'center', inline: 'center', behavior: 'instant' });\n            await nextFrame();\n            const rect = el.getBoundingClientRect();\n            if (rect.width === 0 && rect.height === 0) {\n                throw new Error('element has zero size (is it hidden?): ' + target.selector);\n            }\n            const point = clampToViewport(rect.x + rect.width / 2, rect.y + rect.height / 2);\n            return { x: Math.round(point.x), y: Math.round(point.y), el };\n        }\n        if (target && typeof target.x === 'number' && typeof target.y === 'number') {\n            const point = clampToViewport(target.x, target.y);\n            return { x: Math.round(point.x), y: Math.round(point.y), el: null };\n        }\n        throw new Error('target requires a selector or x/y coordinates');\n    }\n\n    const BUTTONS = { left: 0, middle: 1, right: 2 };\n    const BUTTON_MASKS = { 0: 1, 1: 4, 2: 2 };","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v3/pkg/application/mcp_inject.js#L271-L307","documentation":"LoadResource loads a found resource into memory given a module handle and an HRSRC from FindResource, returning an HGLOBAL or NULL. The w32 wrapper panics with 'LoadResource failed' on NULL. NULL means the HRSRC is invalid — most often because FindResource already failed and its zero result was passed through — or the module handle is wrong (null module with resources actually in a DLL, or a freed library).","triggerScenarios":"Ignoring FindResource's error return (the w32 FindResource returns an error exactly for this) and passing the zero HRSRC onward; looking up a resource by a name/type that does not match how it was embedded; using a stale HMODULE after FreeLibrary.","commonSituations":"Windows icon/notification-icon code loading icons from the executable's resources where the embedding step (rsrc/winres) was removed or renamed in the build; CI builds producing a binary without the .syso resource file so every lookup fails only on the CI artifact.","solutions":["Check FindResource's error before calling LoadResource and surface it with the resource name/type for a actionable message.","Confirm the .syso/.rsrc embedding step runs in all build configurations (check the binary for the resource with Resource Hacker).","Use the correct HMODULE: GetModuleHandle(nil) for the exe, the LoadLibrary result for DLL resources.","Match integer IDs vs string names exactly (IDs are typically passed as MAKEINTRESOURCE-style low-order values)."],"exampleFix":"// before\nhrs, _ := w32.FindResource(hMod, id, w32.RT_RCDATA)\nhg := w32.LoadResource(hMod, hrs) // hrs==0 -> panic\n\n// after\nhrs, err := w32.FindResource(hMod, id, w32.RT_RCDATA)\nif err != nil {\n\treturn fmt.Errorf(\"find resource %d: %w\", id, err)\n}\nhg := w32.LoadResource(hMod, hrs)","handlingStrategy":"validation","validationCode":"func findResourceChecked(hMod w32.HMODULE, id w32.ResourceID, typ *uint16) (w32.HRSRC, error) {\n\thrs, err := w32.FindResource(hMod, id, typ)\n\tif err != nil || hrs == 0 {\n\t\treturn 0, fmt.Errorf(\"resource not found (id=%v): %w\", id, err)\n\t}\n\treturn hrs, nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check FindResource's error return — it exists precisely to prevent this panic.","Ensure the resource-embedding build step (rsrc/winres .syso) runs in every build config.","Use GetModuleHandle(nil) for exe resources and the LoadLibrary handle for DLLs."],"tags":["windows","resources","win32","syscall","panic"],"backgroundTag":null,"analyzedSha":"0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3","analyzedAt":"2026-08-15T14:17:36.034Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}