UNPKG

@huolala-tech/page-spy-lynx

Version:

An SDK of PageSpy for debugging Lynx app

52 lines (51 loc) 2.68 kB
import type { SpyConsole, PageSpyPlugin, OnInitParams, SpyBase } from '@huolala-tech/page-spy-types'; import type { InitConfig } from '../config'; type ConsoleTarget = Record<string, any>; /** Console 插件:代理 JS console,并接收原生侧 console 日志后转发到 PageSpy。 */ export default class ConsolePlugin implements PageSpyPlugin { /** 插件名称。 */ name: string; /** 保存原始 console 方法,用于插件内部回显和 reset 恢复。 */ console: Record<string, any>; /** 已被代理的 console 目标列表及其原始方法。 */ consoleTargets: { target: ConsoleTarget; host?: Record<string, any>; key?: string; originHostValue?: ConsoleTarget; originals: Record<string, any>; }[]; /** 原生 console 桥回调引用,reset 时用于移除。 */ nativeConsoleHandler: ((payload: any, ...rest: any[]) => void) | null; /** 标记是否已通过 lynx.add 安装原生事件监听。 */ nativeConsoleEventInstalled: boolean; /** 轮询原生 console 模块的定时器。 */ nativeConsolePollTimer: ReturnType<typeof setTimeout> | null; /** 原生模块连续缺失次数,用于延迟打印告警。 */ nativeConsoleMissingCount: number; /** 避免重复打印原生模块缺失告警。 */ nativeConsoleMissingWarned: boolean; static hasInitd: boolean; /** 需要代理的 console 方法类型。 */ proxyTypes: SpyConsole.ProxyType[]; $pageSpyConfig: InitConfig | null; /** 插件初始化:注册远程 debug 指令并安装 console 代理。 */ onInit({ config }: OnInitParams<InitConfig>): Promise<void>; /** 代理所有可发现的 console 对象,并保留原始方法用于本地输出。 */ init(): void; /** 恢复被代理的 console 方法和宿主 console 对象。 */ reset(): void; /** 插件重置入口,恢复代理并清理初始化标记。 */ onReset(): void; /** 安装原生 console 桥:支持全局回调、lynx 事件和 NativeModule 轮询三种路径。 */ initNativeConsoleBridge(): void; /** 移除原生 console 桥并清理轮询状态。 */ resetNativeConsoleBridge(): void; /** 轮询原生 console 模块,读取宿主侧缓存的日志消息。 */ startNativeConsolePolling(): void; static handleDebugger({ source }: SpyBase.InteractiveEvent<string>, reply: (data: any) => void): void; printLog(data: SpyConsole.DataItem): void; /** 发送 console 日志到 PageSpy,并按配置决定是否公开原始值或序列化值。 */ sendLog(data: SpyConsole.DataItem, shouldPrint: boolean): void; } export {};