napcat-plugin-browser-center-types
v1.0.0
Published
浏览器能力中心的进程内类型契约 (纯类型, 无运行时)
Maintainers
Readme
napcat-plugin-browser-center-types
「浏览器能力中心」NapCat 插件的进程内类型契约。
本包只有类型声明, 没有运行时代码。调用方通过 ctx.getPluginExports() 取得插件的导出模块, 再用 getBrowserService() 获取服务。
import type {
BrowserCenterModuleExports,
BrowserService,
} from 'napcat-plugin-browser-center-types';
const plugin = ctx.getPluginExports<BrowserCenterModuleExports>(
'napcat-plugin-browser-center',
);
const service: BrowserService | undefined = plugin?.getBrowserService();
const session = await service?.createSession({ owner: ctx.pluginName });
await session?.goto('https://example.com');
const snapshot = await session?.snapshot();
await session?.close();约定:
owner必须是当前已加载插件的 id, 只用于配额、日志与回收, 不是身份认证。- 调用方每次使用前重新
getPluginExports, 不要缓存导出对象。 - 所有方法失败时抛出带
code与retryable的BrowserCenterError(运行时构造函数由插件导出)。 screenshot()返回 PNG 字节 (Uint8Array, 运行时为 NodeBuffer)。- 契约没有
evaluate、反检测、拟人或脚本 DSL; 能力面是刻意收窄的。
