wailsapp/wails · critical
target requires a selector or x/y coordinates
Error message
target requires a selector or x/y coordinates
What it means
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.
Source
Thrown at v3/pkg/application/mcp_inject.js:303
// scrolling selector targets into view first.
async function resolveTarget(target) {
if (target && target.selector) {
const el = document.querySelector(target.selector);
if (!el) throw new Error('no element matches selector: ' + target.selector);
el.scrollIntoView({ block: 'center', inline: 'center', behavior: 'instant' });
await nextFrame();
const rect = el.getBoundingClientRect();
if (rect.width === 0 && rect.height === 0) {
throw new Error('element has zero size (is it hidden?): ' + target.selector);
}
const point = clampToViewport(rect.x + rect.width / 2, rect.y + rect.height / 2);
return { x: Math.round(point.x), y: Math.round(point.y), el };
}
if (target && typeof target.x === 'number' && typeof target.y === 'number') {
const point = clampToViewport(target.x, target.y);
return { x: Math.round(point.x), y: Math.round(point.y), el: null };
}
throw new Error('target requires a selector or x/y coordinates');
}
const BUTTONS = { left: 0, middle: 1, right: 2 };
const BUTTON_MASKS = { 0: 1, 1: 4, 2: 2 };
function focusTarget(el) {
const focusable = el && el.closest
? el.closest('input, textarea, select, button, a[href], [tabindex], [contenteditable]')
: null;
if (focusable && typeof focusable.focus === 'function') {
focusable.focus();
return focusable;
}
if (document.activeElement && document.activeElement !== document.body) {
document.activeElement.blur();
}
return null;
}View on GitHub (pinned to 0e754b1b40)
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.
Example fix
// before bigCache := loadEverything() // fills commit limit CoInitializeEx(COINIT_APARTMENTTHREADED) // E_OUTOFMEMORY panic // after bigCache := loadBudgeted(allocLimit) debug.FreeOSMemory() CoInitializeEx(COINIT_APARTMENTTHREADED)
Defensive patterns
Strategy: fallback
Try / catch
func initCOMWithRetry(flags uintptr) (err error) {
for i := 0; i < 2; i++ {
func() {
defer func() {
if r := recover(); r != nil {
if msg, _ := r.(string); strings.Contains(msg, "E_OUTOFMEMORY") {
debug.FreeOSMemory()
err = fmt.Errorf("com init oom (attempt %d)", i)
return
}
panic(r)
}
}()
CoInitializeEx(flags)
err = nil
}()
if err == nil {
return nil
}
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to init GTK
- element has zero size (is it hidden?): ' + target.selector
- no element matches selector: ' + selector
- 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/37d6a92ca59dbe73.
Report an issue: GitHub.