{"record":{"id":"37d6a92ca59dbe73","repo":"wailsapp/wails","slug":"target-requires-a-selector-or-x-y-coordinates","errorCode":null,"errorMessage":"target requires a selector or x/y coordinates","messagePattern":"target requires a selector or x/y coordinates","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"v3/pkg/application/mcp_inject.js","lineNumber":303,"sourceCode":"    // 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 };\n\n    function focusTarget(el) {\n        const focusable = el && el.closest\n            ? el.closest('input, textarea, select, button, a[href], [tabindex], [contenteditable]')\n            : null;\n        if (focusable && typeof focusable.focus === 'function') {\n            focusable.focus();\n            return focusable;\n        }\n        if (document.activeElement && document.activeElement !== document.body) {\n            document.activeElement.blur();\n        }\n        return null;\n    }","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v3/pkg/application/mcp_inject.js#L285-L321","documentation":"CoInitializeEx initializes COM on a thread; E_OUTOFMEMORY means the runtime could not allocate what it needs to initialize. The w32 wrapper panics with 'CoInitializeEx failed with E_OUTOFMEMORY' for this HRESULT. It is rare and almost always reflects genuine memory exhaustion or commit-limit pressure on the process rather than API misuse — the flags and thread state were acceptable, allocation simply failed.","triggerScenarios":"Initializing COM on a thread after the process has allocated most of its commit limit (huge images, unbounded caches); running under a job object with a memory cap so COM's per-thread allocations fail; 32-bit process near the address-space ceiling.","commonSituations":"A background worker goroutine calling into COM-using features (taskbar, dialogs) after an image-heavy operation has filled memory; containers/job objects with hard memory limits; leak of COM interfaces slowly consuming memory until init fails.","solutions":["Profile and reduce peak memory before the COM-using code runs; free large buffers and caches.","Check whether the process runs under a job object/container memory cap and raise it if legitimate.","On 32-bit builds, build 64-bit to remove address-space pressure.","Look for interface leaks (missing Release via syscall on the vtable) that accumulate over long sessions.","If graceful degradation matters, recover() around the init and retry after freeing memory."],"exampleFix":"// before\nbigCache := loadEverything() // fills commit limit\nCoInitializeEx(COINIT_APARTMENTTHREADED) // E_OUTOFMEMORY panic\n\n// after\nbigCache := loadBudgeted(allocLimit)\ndebug.FreeOSMemory()\nCoInitializeEx(COINIT_APARTMENTTHREADED)","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"func initCOMWithRetry(flags uintptr) (err error) {\n\tfor i := 0; i < 2; i++ {\n\t\tfunc() {\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\tif msg, _ := r.(string); strings.Contains(msg, \"E_OUTOFMEMORY\") {\n\t\t\t\t\t\tdebug.FreeOSMemory()\n\t\t\t\t\t\terr = fmt.Errorf(\"com init oom (attempt %d)\", i)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tpanic(r)\n\t\t\t\t}\n\t\t\t}()\n\t\t\tCoInitializeEx(flags)\n\t\t\terr = nil\n\t\t}()\n\t\tif err == nil {\n\t\t\treturn nil\n\t\t}\n\t}\n\treturn err\n}","preventionTips":["Reduce peak memory before COM-heavy phases.","Watch for COM interface leaks (missing Release) in long sessions.","Raise job-object/container memory caps if legitimately needed."],"tags":["windows","com","out-of-memory","syscall","panic"],"backgroundTag":null,"analyzedSha":"0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3","analyzedAt":"2026-08-15T14:17:36.034Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}