Files
ObsidianHome/百家/.cdp/client.mjs
T

18 lines
591 B
JavaScript
Raw Normal View History

2026-11-09 09:18:58 +08:00
// 桥客户端:通过常驻桥执行表达式,避免每次都新开 Chrome 连接
const BRIDGE = 'http://127.0.0.1:65177';
export async function evalViaBridge(expr, { urlMatch = 'baijiahao.baidu.com', save = null } = {}) {
const r = await fetch(BRIDGE + '/eval', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ expr, urlMatch, save }),
});
const j = await r.json();
if (!j.ok) throw new Error(j.error);
return j.value;
}
export async function health() {
const r = await fetch(BRIDGE + '/health');
return r.json();
}