Files
beaver-plugin-obsidian/t/cdp-eval.ts
T
hh 413d68fc87 fix(view): the inset chases the keyboard by frame, and comes back when it goes
Two fixed delays into the keyboard's animation is not where it ends: the
composer read the viewport mid-slide, and on the way out - when the navbar
comes back - nothing re-measured at all, so the panel stayed pushed up or
sat back under the bar. In a sidedock drawer no resize event fires either,
so a phone's keyboard moved nothing there.

The inset is now re-measured every frame until the reading holds still, and
blur is a trigger as much as focus. `inset()` returns what it wrote so the
loop can tell it has settled rather than counting milliseconds.
2026-09-05 00:47:44 +02:00

36 lines
1.0 KiB
TypeScript

// Evaluate an expression inside a running Obsidian started with
// --remote-debugging-port. Usage: bun t/cdp-eval.ts <port> "<js expression>"
const [port, expression] = process.argv.slice(2);
const targets = (await (
await fetch(`http://localhost:${port}/json`)
).json()) as {
type: string;
title: string;
webSocketDebuggerUrl: string;
}[];
const page = targets.find((t) => t.type === "page");
if (!page) {
throw new Error("no page target");
}
const ws = new WebSocket(page.webSocketDebuggerUrl);
await new Promise((resolve) => ws.addEventListener("open", resolve));
const reply = new Promise<string>((resolve) => {
ws.addEventListener("message", (event) => {
const data = JSON.parse(String(event.data));
if (data.id === 1) {
resolve(
JSON.stringify(data.result?.result?.value ?? data.result ?? data)
);
}
});
});
ws.send(
JSON.stringify({
id: 1,
method: "Runtime.evaluate",
params: { awaitPromise: true, expression, returnByValue: true },
})
);
console.log(await reply);
ws.close();