Ad-hoc debugging
Outside a test framework, connectToCdp() launches (or attaches to) a CDP Obsidian instance, opens a
vault, bootstraps the runtime helpers, and returns a disposable connection — handy for reproducing
behavior in a real Obsidian from a throwaway script or the REPL.
import { connectToCdp } from 'obsidian-integration-testing';
// Owns an isolated instance + an empty temp vault (both cleaned up on dispose).await using conn = await connectToCdp();
console.log(conn.port, conn.cdpUrl); // the free CDP port the instance was launched on
// Raw expression → normalized string result:await conn.invoke('app.vault.getName()');
// Rich, typed path — `callback` runs in the Obsidian renderer with { app, obsidianModule, lib, context }:await conn.evalInObsidian({ callback: ({ app }) => app.workspace.getActiveFile()?.path ?? null });Options
Section titled “Options”connectToCdp accepts the same version knobs as the transport (obsidianVersion,
obsidianInstallerVersion, host, commandTimeoutInMilliseconds, all defaulting to your installed
Obsidian), plus:
vault— path to an existing vault to open. When omitted, an empty temporary vault is created.isObsidianAppVisible— whether the window is shown (defaulttrue). Setfalseto launch it off-screen.port— attach to an already-running Obsidian on thisCDPport instead of owning an instance, as in Attach to a running Obsidian.deadBootGraceInMilliseconds(default10000) — fast-fail with aRendererFailedToInitializeErrorwhen a pinned version pair produces a dead boot;0disables it.shouldRemoveVaultOnDispose— whetherdispose()removes the vault directory. Defaults totruefor an implicit temp vault andfalsewhen avaultpath is given, so a real vault is never auto-deleted. Set it explicitly to override.
The package ships an obsidian-integration-testing bin that wraps connectToCdp, prints the chosen
port/URL, and stays alive until Ctrl+C — useful when an external tool (raw CDP ws, DevTools) needs to
attach to a printed port:
npx obsidian-integration-testing --vault F:/path/to/vault --obsidian-version 1.8.10Flags mirror the options above: --vault, --obsidian-version, --obsidian-installer-version, --port,
--host, --command-timeout, and --no-remove-vault (keep the temp vault on exit).