Skip to content

pin-window-focus

Draws the Obsidian window as FOCUSED for the length of a capture, so a frame does not depend on whether the operating system gave the window foreground focus that run.

Obsidian styles its window chrome from one class, body.is-focused, which it keeps in step with the window itself: on desktop it runs body.toggleClass('is-focused', electronWindow.isFocused()) on every focuschange (read from the 1.14.2 app.js). The title bar of an unfocused window is darker, so a capture’s bytes depended on something the harness does not control. Measured in obsidian-alias-quick-switcher on 2026-09-25: five back-to-back capture runs of an unchanged tree agreed byte for byte in runs 2-5, and run 1 differed in EVERY desktop frame, in the title-bar band alone (y 0-62, the full width, rgb(29,29,29) against rgb(37,37,37)). Windows’ focus-stealing prevention had refused the freshly launched window the foreground, so the class was absent.

The class is pinned rather than the window focused. Asking Electron for BrowserWindow.focus() is a request the OS is free to refuse, which is the same refusal that caused this; adding the class is deterministic and needs no cooperation from anything. The frame then shows the focused chrome every run, which is what the runs that got focus were already committing.

Restored afterwards, to what Obsidian itself would compute, not to what it was before: when focus arrives in the middle of a capture, Obsidian has nothing left to toggle, so putting back a stale “absent” would leave a focused window drawn unfocused. And only when this call added the class, so a window that was focused all along is never touched.

captureObsidianScreenshot calls this by default. It is exported for a consumer capturing through a raw connectToCdp connection, the same reason hideCaret and hideVaultName are.

Interface Description
PinnedWindowFocus What pinWindowFocus returns: whether the class had to be added, and how to undo that.
PinWindowFocusOptions Options for pinWindowFocus.
Function Description
pinWindowFocus Adds is-focused to the body when the window is drawn unfocused.