Skip to content

clickMouse

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. Obsidian 1.13.7’s markdown viewport (margin) menu, for example, opens from cm.scrollDOM.addEventListener('contextmenu', (e) => { if (!e.defaultPrevented && e.isTrusted && …) }) — a dispatched contextmenu never gets past that check.

It is the low-level primitive: a single trusted mouseMovemouseDownmouseUp 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 clickElement for element-relative clicks.

Must be awaited — see clickElement.

Import:

import { clickMouse } from 'obsidian-dev-utils/obsidian/desktop-trusted-input';

Signature:

function clickMouse(params: ClickMouseParams): Promise<void>

Parameters:

ParameterTypeDescription
paramsClickMouseParamsThe web-contents DIP coordinates to click at, the button to press and any modifiers to hold.

Returns: Promise<void> — A Promise that resolves once the click has been injected.


Links to this page: