Skip to content

Lib.clickMouse

Lib › clickMouse

Type: (this: void, params: ClickMouseParams) => Promise<void>

Clicks at the given web-contents coordinates using **trusted** Electron pointer input, so Chromium synthesizes a real click (or contextmenu, for the right button) with isTrusted === true.

This is what element.dispatchEvent(new MouseEvent('click')) cannot do: Obsidian and CodeMirror gate on isTrusted, so a dispatched event silently exercises nothing while the test still passes whatever weaker assertion it makes. Obsidian 1.13.7's markdown viewport (margin) menu, for example, opens from a cm.scrollDOM contextmenu listener guarded by e.isTrusted, which a dispatched event never gets past.

It is the low-level primitive: a single trusted mouseMove → mouseDown → mouseUp at one point, with no waiting for any effect (callers poll their own readiness signal). The leading move is what puts the pointer over the hit-test target before the button goes down. Prefer Lib.clickElement for element-relative clicks.

A real context menu actually opens, so a suite driving a right click must close it (or remove the leftover .menu element) before the next test.

It clicks in the main window unless ClickMouseParams.window names a popout. Lib.clickElement needs no such parameter: it clicks in the window that owns its element.

**On mobile** the button model does not survive the port: touch has no buttons, so 'left' (the default) is a **tap**, 'right' is the **long-press** that opens Obsidian Mobile's context menu, and 'middle' throws — there is no gesture for it, and inventing one would be worse than saying so. The coordinates are CSS pixels in the WebView's own viewport, which is what CDP takes, so devicePixelRatio never enters the picture.

**Must be awaited** — see Lib.clickElement.