wailsapp/wails · error

no element matches selector: ' + target.selector

Error message

no element matches selector: ' + target.selector

What it means

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).

Source

Thrown at v3/pkg/application/mcp_inject.js:289

            bounds: {
                x: Math.round(rect.x),
                y: Math.round(rect.y),
                width: Math.round(rect.width),
                height: Math.round(rect.height),
            },
        };
        if ('value' in el && typeof el.value === 'string') description.value = el.value.slice(0, 500);
        if (el.disabled) description.disabled = true;
        if (el.href) description.href = el.href;
        return description;
    }

    // Resolve {selector} or {x, y} into concrete viewport coordinates,
    // 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 };

View on GitHub (pinned to 0e754b1b40)

Solutions

  1. Check FindResource's error before calling LoadResource and surface it with the resource name/type for a actionable message.
  2. Confirm the .syso/.rsrc embedding step runs in all build configurations (check the binary for the resource with Resource Hacker).
  3. Use the correct HMODULE: GetModuleHandle(nil) for the exe, the LoadLibrary result for DLL resources.
  4. Match integer IDs vs string names exactly (IDs are typically passed as MAKEINTRESOURCE-style low-order values).

Example fix

// before
hrs, _ := w32.FindResource(hMod, id, w32.RT_RCDATA)
hg := w32.LoadResource(hMod, hrs) // hrs==0 -> panic

// after
hrs, err := w32.FindResource(hMod, id, w32.RT_RCDATA)
if err != nil {
	return fmt.Errorf("find resource %d: %w", id, err)
}
hg := w32.LoadResource(hMod, hrs)
Defensive patterns

Strategy: validation

Validate before calling

func findResourceChecked(hMod w32.HMODULE, id w32.ResourceID, typ *uint16) (w32.HRSRC, error) {
	hrs, err := w32.FindResource(hMod, id, typ)
	if err != nil || hrs == 0 {
		return 0, fmt.Errorf("resource not found (id=%v): %w", id, err)
	}
	return hrs, nil
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of wailsapp/wails@0e754b1b40 (2026-08-15). Data as JSON: /api/errors/334e1ebc7d230fc0. Report an issue: GitHub.