Skip to content

Lib.clickElement

Lib › clickElement

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

Clicks the center of an element using **trusted** pointer input — Electron's sendInputEvent on desktop, a CDP touch tap in the WebView on mobile.

The element-relative counterpart of Lib.clickMouse, mirroring the Lib.moveMouse / Lib.hoverElement split. Use Lib.clickMouse directly when the point to click is **not** the element's center — the markdown editor's margin, for instance, lies inside cm.scrollDOM but outside .cm-sizer, so no element's center lands on it.

**Must be awaited.** On mobile the injection is a round-trip to the host — the renderer cannot produce a trusted event itself — so a missing await would let the assertion run before the click landed.

**On mobile it waits for the element to stop moving, and refuses a covered one.** The tap reaches the page about a second after its point is read, and Obsidian Mobile slides a modal in with a transform transition that can hold for over a second, so a point read too early is where the control *used to be*. So the mobile path first waits (up to 5 s) until no finite animation or transition runs on the element or any ancestor and its box has held across two reads, then checks with elementFromPoint that the center belongs to the element (asked of the element's own root, so a target inside a shadow root is hit-tested in its own tree). It throws a named error in either case rather than tapping, because a trusted tap goes to whatever is on top and would otherwise land on it silently. Use Lib.clickMouse to tap a point deliberately, covered or not. Desktop is unchanged.