@skillbuilder/miniapp-simulator 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/assets/audit-auto-stop-config-2026-10-21.jpg +0 -0
- package/docs/assets/audit-balanced-panel-2026-10-16.jpg +0 -0
- package/docs/assets/audit-lcp-input-2026-10-20.jpg +0 -0
- package/docs/assets/audit-paint-game3d-2026-10-16.jpg +0 -0
- package/docs/assets/audit-paint-webgl-2026-10-16.jpg +0 -0
- package/docs/assets/audit-paint-webgl-apm-excerpt-2026-10-16.json +397 -0
- package/docs/assets/audit-poetry-2026-10-16.jpg +0 -0
- package/docs/assets/audit-remaining-results-2026-10-16.json +2749 -0
- package/docs/assets/miniapp-audit-risk-review-2026-10-13.png +0 -0
- package/docs/assets/miniapp-audit-runtime-hung-2026-10-13.png +0 -0
- package/docs/audit-data-collection.codex.md +422 -0
- package/docs/audit-local-validation.codex.md +165 -0
- package/docs/audit-score-design.codex.md +221 -0
- package/docs/audit-score-design.md +885 -0
- package/docs/audit-score-tech-plan.md +448 -0
- package/docs/audit-tech-design.codex.md +468 -0
- package/docs/electron-review.md +223 -12
- package/docs/quality-evaluation-redoc.xml +163 -0
- package/lib/client-BDt3WDu_.mjs +1118 -0
- package/lib/{index-D5AYVv8s.mjs → index-7MeYFlk_.mjs} +210 -182
- package/lib/index.js +1254 -1115
- package/lib/remote-client.js +2 -2
- package/lib/types/host/shadow-host.d.ts +10 -0
- package/lib/types/injection/registry.d.ts +5 -0
- package/lib/types/remote/audit-controller.d.ts +56 -0
- package/lib/types/remote/audit-leave-monitor.d.ts +12 -0
- package/lib/types/remote/audit-telemetry.d.ts +23 -0
- package/lib/types/remote/audit-watchdog.d.ts +14 -0
- package/lib/types/remote/client.d.ts +25 -1
- package/lib/types/remote/load-timing.d.ts +5 -0
- package/lib/types/remote/protocol.d.ts +151 -1
- package/lib/types/remote/runtime.d.ts +2 -0
- package/lib/types/remote-client.d.ts +2 -2
- package/lib/types/sw/service-worker-host.d.ts +15 -0
- package/lib/types/tracker/default-tracker.d.ts +8 -0
- package/lib/types/types/options.d.ts +24 -0
- package/lib/workbench.js +1 -1
- package/package.json +1 -1
- package/lib/client-_vNHVHSm.mjs +0 -775
package/lib/remote-client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { R as r, a as O, c as e } from "./client-
|
|
1
|
+
import { R as r, a as O, c as e } from "./client-BDt3WDu_.mjs";
|
|
2
2
|
import { B as s, M as _ } from "./options-B34ipLmF.mjs";
|
|
3
|
-
import { M } from "./index-
|
|
3
|
+
import { M } from "./index-7MeYFlk_.mjs";
|
|
4
4
|
export {
|
|
5
5
|
s as BusinessLine,
|
|
6
6
|
_ as MINIAPP_SCREENSHOT_ERROR_CODE,
|
|
@@ -31,6 +31,16 @@ export interface MiniAppShadowHost {
|
|
|
31
31
|
stage: HTMLElement;
|
|
32
32
|
/** 宿主侧 overlay(如 toast)应挂载到的根:shadowRoot 或 host */
|
|
33
33
|
overlayRoot: ShadowRoot | HTMLElement;
|
|
34
|
+
/**
|
|
35
|
+
* 与设备画布并排的侧栏槽位(评测面板等)。
|
|
36
|
+
*
|
|
37
|
+
* 默认宽度为 0 且不渲染,只有调用 setSidePanelWidth 打开后才占位。
|
|
38
|
+
* 走分栏而非浮层:浮层会直接盖住设备,而审核页把挂载点限制成手机尺寸,
|
|
39
|
+
* 盖住后审核员既看不到小工具也点不到它。
|
|
40
|
+
*/
|
|
41
|
+
sidePanel: HTMLElement;
|
|
42
|
+
/** 设置侧栏宽度;传 0 收起。bounds 自动让出对应宽度并重新居中设备。 */
|
|
43
|
+
setSidePanelWidth(width: number): void;
|
|
34
44
|
/** 销毁:移除创建的宿主元素 */
|
|
35
45
|
destroy(): void;
|
|
36
46
|
}
|
|
@@ -12,6 +12,11 @@ export declare class InjectionRegistry {
|
|
|
12
12
|
private readonly order;
|
|
13
13
|
register(module: InjectionModule): void;
|
|
14
14
|
unregister(id: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* 把指定模块移到末位。seal 会锁定大量内置原型,任何需要 hook 内置对象的模块
|
|
17
|
+
* 都必须排在它之前执行,否则属性已不可配置,hook 静默失效。
|
|
18
|
+
*/
|
|
19
|
+
moveToEnd(id: string): boolean;
|
|
15
20
|
has(id: string): boolean;
|
|
16
21
|
/** 按注册顺序列出所有模块(拼 head/preload 时按此序) */
|
|
17
22
|
list(): InjectionModule[];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { RemoteAuditStartArgs, RemoteAuditStartResult } from "./protocol";
|
|
2
|
+
export interface AuditPackageSnapshot {
|
|
3
|
+
zipBytes: number;
|
|
4
|
+
files: Array<{
|
|
5
|
+
path: string;
|
|
6
|
+
size: number;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
export interface AuditControllerDeps {
|
|
10
|
+
/** 当前 simulator 实例(需支持 registerInjection / reload) */
|
|
11
|
+
getSimulator(): unknown;
|
|
12
|
+
/** 最近一次加载的包快照;没有内容时返回 null */
|
|
13
|
+
getPackage(): AuditPackageSnapshot | null;
|
|
14
|
+
/** Apollo 下发的评测策略原始值;未下发时为 undefined */
|
|
15
|
+
getPolicy(): unknown;
|
|
16
|
+
getInteractionRegions(): readonly HTMLElement[];
|
|
17
|
+
/** 与当前 Runtime release 绑定的独立插件地址。 */
|
|
18
|
+
auditPluginUrl?: string;
|
|
19
|
+
/** 把评测进度 / 报告以事件推给宿主 */
|
|
20
|
+
emitEvent(event: string, payload: unknown): void;
|
|
21
|
+
/** 视口信息,用于 canvas 预算换算 */
|
|
22
|
+
getViewport(): {
|
|
23
|
+
dpr: number;
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
};
|
|
27
|
+
/** Mars 审核会话:建连后常驻面板,内容加载前自动开始监听。 */
|
|
28
|
+
autoRun?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface AuditController {
|
|
31
|
+
/** 手动 RPC:当前内容已运行时通过 reload 安装 document-start 探针。 */
|
|
32
|
+
start(args?: RemoteAuditStartArgs): Promise<RemoteAuditStartResult>;
|
|
33
|
+
/** 正常结束并评分;不是 abort。 */
|
|
34
|
+
stop(): void;
|
|
35
|
+
status(): {
|
|
36
|
+
phase: string;
|
|
37
|
+
sessionId: string | null;
|
|
38
|
+
};
|
|
39
|
+
report(): unknown;
|
|
40
|
+
setPolicy(input: unknown): void;
|
|
41
|
+
/** 模拟器熔断 / guest 失联时调用,让本次会话作废而不是出一份截断的分 */
|
|
42
|
+
notifyGuardTriggered(reason: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* Mars 在真正装载 guest document 前调用。探针先注册、再加载内容,首屏资源和后续
|
|
45
|
+
* 审核操作都属于同一轮采样;不通过 reload 重开页面。
|
|
46
|
+
*/
|
|
47
|
+
beginForContent(): Promise<void>;
|
|
48
|
+
/** 内容本身无法装载时,及时收口已经预热的会话。 */
|
|
49
|
+
notifyContentLoadFailed(reason: string): void;
|
|
50
|
+
/** 必要评测证据失败时中断;普通封面截图失败不调用此接口。 */
|
|
51
|
+
notifyEvidenceFailure(reason: string): void;
|
|
52
|
+
/** Mars 建连即调用,加载独立资源并展示空态面板。 */
|
|
53
|
+
prepare(): Promise<void>;
|
|
54
|
+
destroy(): void;
|
|
55
|
+
}
|
|
56
|
+
export declare function createAuditController(deps: AuditControllerDeps): AuditController;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const DEFAULT_AUDIT_AUTO_STOP_ON_LEAVE_MS = 30000;
|
|
2
|
+
export declare function resolveAutoStopOnLeaveMs(value: unknown): number;
|
|
3
|
+
/** 监听稳定的模拟器区域,不进入 guest DOM,也不把 iframe 内部切换当作离开。 */
|
|
4
|
+
export declare function createAuditLeaveMonitor(options: {
|
|
5
|
+
regions: readonly HTMLElement[];
|
|
6
|
+
delayMs: number;
|
|
7
|
+
onCountdown(seconds: number | null): void;
|
|
8
|
+
onTimeout(): void;
|
|
9
|
+
}): {
|
|
10
|
+
activity(): void;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type AuditApmFields = Record<string, string | number | null | undefined>;
|
|
2
|
+
/** 候选点位和终态共用一份扁平契约;缺失值省略,布尔值转为 0/1。 */
|
|
3
|
+
export declare function toAuditPaintFields(input: unknown): AuditApmFields;
|
|
4
|
+
interface AuditTelemetryMetadata {
|
|
5
|
+
appType?: string;
|
|
6
|
+
declaredAppType?: string;
|
|
7
|
+
features?: string[];
|
|
8
|
+
policyVersion?: string;
|
|
9
|
+
rulesVersion?: string;
|
|
10
|
+
probeVersion?: string;
|
|
11
|
+
}
|
|
12
|
+
/** 只上报静态聚合,不把文件路径清单带入 APM。 */
|
|
13
|
+
export declare function toAuditPackageFields(pkg: {
|
|
14
|
+
zipBytes: number;
|
|
15
|
+
files: Array<{
|
|
16
|
+
path: string;
|
|
17
|
+
size: number;
|
|
18
|
+
}>;
|
|
19
|
+
}, metadata: AuditTelemetryMetadata, uncompressedJsThresholdBytes: number): AuditApmFields;
|
|
20
|
+
/** 报告和派生指标转成 APM 可检索的扁平标量。 */
|
|
21
|
+
export declare function toAuditResultFields(report: unknown, metrics?: unknown): AuditApmFields;
|
|
22
|
+
export declare function compactFields(fields: AuditApmFields): AuditApmFields;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RemoteAuditReport } from "./protocol";
|
|
2
|
+
export declare const RUNTIME_HUNG_CODE = "RUNTIME_HUNG";
|
|
3
|
+
/** 宿主连续收不到 Runtime 进度时,认为与 guest 共用的主线程已经卡死。 */
|
|
4
|
+
export declare const AUDIT_PROGRESS_STALL_TIMEOUT_MS = 12000;
|
|
5
|
+
/** 正常最长会话结束后,额外留给评分和跨 iframe 消息的收口时间。 */
|
|
6
|
+
export declare const AUDIT_FINALIZATION_GRACE_MS = 35000;
|
|
7
|
+
export declare const RUNTIME_HUNG_TEMPLATE_REASON = "Runtime \u5728\u8BC4\u6D4B\u671F\u95F4\u5931\u53BB\u54CD\u5E94\uFF0C\u5C0F\u5DE5\u5177\u53EF\u80FD\u957F\u65F6\u95F4\u963B\u585E\u4E86\u4E3B\u7EBF\u7A0B";
|
|
8
|
+
/**
|
|
9
|
+
* 将 Runtime 在 reload 前生成的 loadFailed 模板收敛为宿主 watchdog 的最终报告。
|
|
10
|
+
*
|
|
11
|
+
* 只复制结构化数据,不访问 guest / Runtime,也不执行用户代码;因此即使 Runtime 与
|
|
12
|
+
* guest 一同卡死,宿主页仍可安全地产出一个可被本地驱动和审核面板消费的三态报告。
|
|
13
|
+
*/
|
|
14
|
+
export declare function createRuntimeHungAuditReport(template: RemoteAuditReport, sawProgress: boolean): RemoteAuditReport;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { BusinessLine } from "../business-line";
|
|
2
2
|
import type { MiniAppEventMap, MiniAppHostApiController, MiniAppHostApiEntry, MiniAppInspectorSelectionMode, MiniAppLoadFilesResult, MiniAppLoadZipResult, MiniAppPhoneFrame, MiniAppRedirectOptions, MiniAppSceneTreeSnapshot, MiniAppScreenShotResult, MiniAppSimulatorOptions, MiniAppSimulatorRoute, MiniAppViewport, VisualSelection, XhsNoteAppCardData, XhsNotePreviewData, XhsNotePreviewUser, XhsWidgetCoverData } from "../types";
|
|
3
3
|
import { type RemoteLoadTiming } from "./load-timing";
|
|
4
|
-
import { type RemoteMethodArgumentMap, type RemoteSimulatorGatewayOptions, type RemoteSimulatorMethod, type RemoteSimulatorReadyMessage, type RemoteSimulatorSerializableOptions } from "./protocol";
|
|
4
|
+
import { type RemoteAuditContext, type RemoteAuditStartArgs, type RemoteAuditStartResult, type RemoteMethodArgumentMap, type RemoteSimulatorGatewayOptions, type RemoteSimulatorMethod, type RemoteSimulatorReadyMessage, type RemoteSimulatorSerializableOptions } from "./protocol";
|
|
5
|
+
export interface RemoteTrackerDeliveryInfo {
|
|
6
|
+
ok: boolean;
|
|
7
|
+
status?: number;
|
|
8
|
+
attempts: number;
|
|
9
|
+
eventCount: number;
|
|
10
|
+
}
|
|
5
11
|
export interface RemoteMiniAppSimulatorOptions {
|
|
6
12
|
mount: string | HTMLElement;
|
|
7
13
|
/** 模拟器服务入口;SDK 会先请求 `/runtime-manifest` 选择协议对应的 Runtime。 */
|
|
@@ -14,6 +20,10 @@ export interface RemoteMiniAppSimulatorOptions {
|
|
|
14
20
|
businessLine: BusinessLine;
|
|
15
21
|
/** 是否启用远端 Runtime APM,默认启用。 */
|
|
16
22
|
tracker?: boolean;
|
|
23
|
+
/** 单批 APM 请求完成后的诊断回调,不包含事件正文。 */
|
|
24
|
+
onTrackerDelivery?: (result: RemoteTrackerDeliveryInfo) => void;
|
|
25
|
+
/** Mars 审核队列项身份;用于关联评测证据和包版本。 */
|
|
26
|
+
auditContext?: RemoteAuditContext;
|
|
17
27
|
/** 注入到 launchOptions.miniToolEnv.gateways 的宿主网关配置。 */
|
|
18
28
|
gateway?: RemoteSimulatorGatewayOptions;
|
|
19
29
|
/** 宿主自定义 bridge 行为;优先于 Runtime 按 businessLine 提供的默认行为。 */
|
|
@@ -79,6 +89,20 @@ export interface RemoteMiniAppSimulator {
|
|
|
79
89
|
selectByRef(ref: string): Promise<VisualSelection | null>;
|
|
80
90
|
};
|
|
81
91
|
hostApi: MiniAppHostApiController;
|
|
92
|
+
/**
|
|
93
|
+
* 体验评测。仅当 ready 的 capabilities 含 "audit" 时可用;
|
|
94
|
+
* 老 Runtime 上调用会返回 PLUGIN_UNAVAILABLE 而不是握手失败。
|
|
95
|
+
*/
|
|
96
|
+
audit: {
|
|
97
|
+
start(args?: RemoteAuditStartArgs): Promise<RemoteAuditStartResult>;
|
|
98
|
+
stop(): Promise<void>;
|
|
99
|
+
status(): Promise<{
|
|
100
|
+
phase: string;
|
|
101
|
+
sessionId: string | null;
|
|
102
|
+
}>;
|
|
103
|
+
report(): Promise<unknown>;
|
|
104
|
+
setPolicy(policy: unknown): Promise<void>;
|
|
105
|
+
};
|
|
82
106
|
invoke<M extends RemoteSimulatorMethod>(method: M, ...args: RemoteMethodArgumentMap[M]): Promise<unknown>;
|
|
83
107
|
on<E extends keyof MiniAppEventMap>(event: E, handler: (payload: MiniAppEventMap[E]) => void): () => void;
|
|
84
108
|
on(event: string, handler: RemoteSimulatorEventHandler): () => void;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { BusinessLine } from "../business-line";
|
|
2
|
+
import { type DefaultTrackerDeliveryResult } from "../tracker/default-tracker";
|
|
2
3
|
export interface RemoteLoadTiming {
|
|
3
4
|
report(stage: string, fields?: RemoteLoadTimingFields): void;
|
|
5
|
+
reportEvent(name: string, fields: Record<string, string | number | null | undefined>, options?: {
|
|
6
|
+
flush?: boolean;
|
|
7
|
+
}): void;
|
|
4
8
|
flush(): void;
|
|
5
9
|
}
|
|
6
10
|
/**
|
|
@@ -30,6 +34,7 @@ export interface RemoteLoadTimingOptions {
|
|
|
30
34
|
sessionId: string;
|
|
31
35
|
runtimeVersion?: string;
|
|
32
36
|
resolveUserId?: () => Promise<string>;
|
|
37
|
+
onDelivery?: (result: DefaultTrackerDeliveryResult) => void;
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
35
40
|
* 远程模拟器启动链路复用统一加载点位,避免扩展 MessageChannel 消息并触发协议升级。
|
|
@@ -9,6 +9,11 @@ export declare const REMOTE_SIMULATOR_PROTOCOL_VERSION: number;
|
|
|
9
9
|
export declare const REMOTE_SIMULATOR_CONNECT = "miniapp-simulator:connect";
|
|
10
10
|
/** Runtime 已包含可在圈选期间冻结 RAF/timer/CSS/media 的 guest 注入能力。 */
|
|
11
11
|
export declare const REMOTE_INSPECTOR_PAUSE_RUNTIME_CAPABILITY = "inspectorPauseRuntime";
|
|
12
|
+
/**
|
|
13
|
+
* Runtime 支持按需加载体验评测插件。以 capability 协商而非 bump 协议版本:
|
|
14
|
+
* 版本不一致会让老 runtime 直接握手失败,而评测是可选能力,缺失只应降级。
|
|
15
|
+
*/
|
|
16
|
+
export declare const REMOTE_AUDIT_CAPABILITY = "audit";
|
|
12
17
|
export declare const REMOTE_SIMULATOR_CAPABILITIES: string[];
|
|
13
18
|
export type RemoteSimulatorSerializableOptions = Omit<MiniAppSimulatorOptions, "mount" | "appId" | "renderer" | "serviceWorker" | "security" | "jsapi" | "hostApi" | "tracker" | "runtimeLimits" | "onEvent" | "onReady" | "onBeforeLoad" | "onLoad" | "onRenderDone" | "onError" | "onNavigation" | "onConsole" | "onNetwork" | "onDestroy" | "onRouterChange" | "onScreenShot"> & {
|
|
14
19
|
appUrl?: string;
|
|
@@ -27,6 +32,7 @@ export interface RemoteSimulatorConnectMessage {
|
|
|
27
32
|
appId: string;
|
|
28
33
|
businessLine: BusinessLine;
|
|
29
34
|
tracker: boolean;
|
|
35
|
+
auditContext?: RemoteAuditContext;
|
|
30
36
|
gateway?: RemoteSimulatorGatewayOptions;
|
|
31
37
|
userInfo?: Record<string, unknown>;
|
|
32
38
|
hostApiMethods: string[];
|
|
@@ -35,6 +41,20 @@ export interface RemoteSimulatorConnectMessage {
|
|
|
35
41
|
}>;
|
|
36
42
|
options: RemoteSimulatorSerializableOptions;
|
|
37
43
|
}
|
|
44
|
+
/** Mars 队列项提供的稳定业务标识;随评测点位进入 APM,不进入被测 guest。 */
|
|
45
|
+
export interface RemoteAuditContext {
|
|
46
|
+
reviewTaskId: string;
|
|
47
|
+
packageVersion: string;
|
|
48
|
+
/** 业务已有可信制品哈希时可直接传入;否则 Remote Client 在 load* 时计算。 */
|
|
49
|
+
packageHash?: string;
|
|
50
|
+
}
|
|
51
|
+
/** Runtime 发给宿主的内部评测点位;只允许扁平标量字段。 */
|
|
52
|
+
export interface RemoteAuditTelemetryPayload {
|
|
53
|
+
name: "miniapp_audit_session" | "miniapp_audit_sample" | "miniapp_audit_paint" | "miniapp_audit_incident" | "miniapp_audit_package" | "miniapp_audit_result";
|
|
54
|
+
sessionId: string;
|
|
55
|
+
fields: Record<string, string | number | null | undefined>;
|
|
56
|
+
flush?: boolean;
|
|
57
|
+
}
|
|
38
58
|
export interface RemoteSimulatorReadyMessage {
|
|
39
59
|
type: "ready";
|
|
40
60
|
protocolVersion: number;
|
|
@@ -113,7 +133,7 @@ export type RemoteSimulatorPortMessage = {
|
|
|
113
133
|
type: "worker-visibility";
|
|
114
134
|
visible: boolean;
|
|
115
135
|
} | RemoteSimulatorReadyMessage | RemoteSimulatorRequestMessage | RemoteSimulatorResponseMessage | RemoteSimulatorEventMessage | RemoteHostApiRequestMessage | RemoteHostApiResponseMessage | RemoteHostRequestMessage | RemoteHostRequestResponseMessage | RemoteHostRequestAbortMessage | RemoteHostRequestEventMessage;
|
|
116
|
-
export type RemoteSimulatorMethod = "load" | "loadZip" | "loadFiles" | "loadApp" | "unload" | "reload" | "setViewport" | "switchContentMode" | "switchPhoneFrame" | "switchDevice" | "setTouchEmulation" | "permissionSheet.show" | "permissionSheet.hide" | "notePreview.update" | "notePreview.updateUser" | "notePreview.updateAppCard" | "widgetCover.update" | "router.redirectTo" | "router.getRoute" | "inspector.enable" | "inspector.disable" | "inspector.toggle" | "inspector.clear" | "inspector.setSelectionMode" | "inspector.getSelectionMode" | "inspector.getSceneTree" | "inspector.selectByRef" | "capture" | "screenShot" | "setAutoScreenShot" | "hostApi.sync" | "hostApi.emit" | "destroy";
|
|
136
|
+
export type RemoteSimulatorMethod = "load" | "loadZip" | "loadFiles" | "loadApp" | "unload" | "reload" | "setViewport" | "switchContentMode" | "switchPhoneFrame" | "switchDevice" | "setTouchEmulation" | "permissionSheet.show" | "permissionSheet.hide" | "notePreview.update" | "notePreview.updateUser" | "notePreview.updateAppCard" | "widgetCover.update" | "router.redirectTo" | "router.getRoute" | "inspector.enable" | "inspector.disable" | "inspector.toggle" | "inspector.clear" | "inspector.setSelectionMode" | "inspector.getSelectionMode" | "inspector.getSceneTree" | "inspector.selectByRef" | "capture" | "screenShot" | "setAutoScreenShot" | "hostApi.sync" | "hostApi.emit" | "audit.start" | "audit.stop" | "audit.status" | "audit.report" | "audit.setPolicy" | "destroy";
|
|
117
137
|
export interface RemoteLoadZipArgs {
|
|
118
138
|
buffer: ArrayBuffer;
|
|
119
139
|
options?: Omit<MiniAppLoadZipOptions, "jszip">;
|
|
@@ -161,5 +181,135 @@ export type RemoteMethodArgumentMap = {
|
|
|
161
181
|
toast: string;
|
|
162
182
|
}>];
|
|
163
183
|
"hostApi.emit": [string, unknown];
|
|
184
|
+
"audit.start": [RemoteAuditStartArgs?];
|
|
185
|
+
"audit.stop": [];
|
|
186
|
+
"audit.status": [];
|
|
187
|
+
"audit.report": [];
|
|
188
|
+
"audit.setPolicy": [unknown];
|
|
164
189
|
destroy: [string?];
|
|
165
190
|
};
|
|
191
|
+
/** 评测启动参数。阈值不在此传递——一律由 Runtime 侧策略下发,宿主不可越过配置提权。 */
|
|
192
|
+
export interface RemoteAuditStartArgs {
|
|
193
|
+
/**
|
|
194
|
+
* 兼容旧调用方的请求值;Runtime 只会使用 Apollo 的 evaluationDurationMs,
|
|
195
|
+
* 不允许宿主把一次评测延长到策略上限之外。
|
|
196
|
+
*/
|
|
197
|
+
durationMs?: number;
|
|
198
|
+
armingMs?: number;
|
|
199
|
+
declaredAppType?: "tool" | "game2d" | "game3d" | "video";
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* 评测报告的跨 iframe 序列化契约。
|
|
203
|
+
*
|
|
204
|
+
* 它属于 remote protocol,而不是 Runtime 对插件包的类型依赖:评分插件作为独立 ESM
|
|
205
|
+
* 发布、动态加载,宿主只需要理解可以传递、展示和 watchdog 收口的数据形状。
|
|
206
|
+
*/
|
|
207
|
+
export interface RemoteAuditReport {
|
|
208
|
+
stopReason?: "manual" | "pointer_leave_timeout" | "duration_limit" | "interrupted";
|
|
209
|
+
autoStopOnLeaveMs?: number;
|
|
210
|
+
paintTiming?: {
|
|
211
|
+
fcpMs: number | null;
|
|
212
|
+
lcpMs: number | null;
|
|
213
|
+
fcpStatus: "pending" | "measured" | "unsupported" | "hidden";
|
|
214
|
+
lcpStatus: "pending" | "measured" | "unsupported" | "hidden";
|
|
215
|
+
lcpFinalized: boolean;
|
|
216
|
+
finalizeReason?: "interaction" | "hidden" | "pagehide" | "audit-stop";
|
|
217
|
+
finalizeEvent?: string;
|
|
218
|
+
lcpFinalizedAtMs?: number;
|
|
219
|
+
lcpElementTag?: string;
|
|
220
|
+
lcpElementSize?: number;
|
|
221
|
+
};
|
|
222
|
+
status: "loadFailed" | "unscorable" | "scored";
|
|
223
|
+
blocking: {
|
|
224
|
+
passed: boolean;
|
|
225
|
+
enforced: boolean;
|
|
226
|
+
failures: Array<{
|
|
227
|
+
id: string;
|
|
228
|
+
code?: string;
|
|
229
|
+
measured?: number;
|
|
230
|
+
threshold?: number;
|
|
231
|
+
unit?: string;
|
|
232
|
+
message: string;
|
|
233
|
+
}>;
|
|
234
|
+
};
|
|
235
|
+
loadFailure?: {
|
|
236
|
+
code?: string;
|
|
237
|
+
message: string;
|
|
238
|
+
};
|
|
239
|
+
score?: {
|
|
240
|
+
total: number;
|
|
241
|
+
byCategory: Record<string, {
|
|
242
|
+
got: number;
|
|
243
|
+
max: number;
|
|
244
|
+
}>;
|
|
245
|
+
};
|
|
246
|
+
coverage: {
|
|
247
|
+
ratio: number;
|
|
248
|
+
applicable: string[];
|
|
249
|
+
naReasons: Record<string, string>;
|
|
250
|
+
};
|
|
251
|
+
items: Array<{
|
|
252
|
+
id: string;
|
|
253
|
+
category: string;
|
|
254
|
+
weight: number;
|
|
255
|
+
verdict: "pass" | "fail" | "na";
|
|
256
|
+
score?: number;
|
|
257
|
+
measured?: number;
|
|
258
|
+
threshold?: number;
|
|
259
|
+
unit?: string;
|
|
260
|
+
naReason?: string;
|
|
261
|
+
note?: string;
|
|
262
|
+
applicable?: boolean;
|
|
263
|
+
}>;
|
|
264
|
+
quality: {
|
|
265
|
+
effectiveMs: number;
|
|
266
|
+
complete: boolean;
|
|
267
|
+
truncatedReason?: string;
|
|
268
|
+
reloadCount: number;
|
|
269
|
+
probeSaturated: boolean;
|
|
270
|
+
sampleCount: number;
|
|
271
|
+
sufficient: boolean;
|
|
272
|
+
insufficientReasons: string[];
|
|
273
|
+
infrastructureErrorCount: number;
|
|
274
|
+
interactionCount: number;
|
|
275
|
+
firstInteractionAt?: number;
|
|
276
|
+
};
|
|
277
|
+
appType: "tool" | "game2d" | "game3d" | "video";
|
|
278
|
+
tagMismatch: boolean;
|
|
279
|
+
versions: {
|
|
280
|
+
policyVersion: string;
|
|
281
|
+
rulesVersion: string;
|
|
282
|
+
probeVersion: string;
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
export type RemoteAuditStartResult = {
|
|
286
|
+
ok: true;
|
|
287
|
+
sessionId: string;
|
|
288
|
+
/** 本轮由策略确定的最长采集时长。 */
|
|
289
|
+
evaluationDurationMs: number;
|
|
290
|
+
/** 探针就绪后的预热时长。 */
|
|
291
|
+
armingMs: number;
|
|
292
|
+
/**
|
|
293
|
+
* Runtime 在 reload 前生成的兜底报告。若 guest 与 Runtime 共用的主线程被用户代码卡住,
|
|
294
|
+
* 宿主仍可将它作为 `RUNTIME_HUNG` 的 loadFailed 终态发布。
|
|
295
|
+
*/
|
|
296
|
+
runtimeHungReport?: RemoteAuditReport;
|
|
297
|
+
}
|
|
298
|
+
/** 插件未装载(构建未包含 / 懒加载失败)*/
|
|
299
|
+
| {
|
|
300
|
+
ok: false;
|
|
301
|
+
code: "PLUGIN_UNAVAILABLE";
|
|
302
|
+
message: string;
|
|
303
|
+
}
|
|
304
|
+
/** 策略侧关闭了评测 */
|
|
305
|
+
| {
|
|
306
|
+
ok: false;
|
|
307
|
+
code: "POLICY_DISABLED";
|
|
308
|
+
message: string;
|
|
309
|
+
}
|
|
310
|
+
/** 当前没有已加载的小工具内容 */
|
|
311
|
+
| {
|
|
312
|
+
ok: false;
|
|
313
|
+
code: "NO_CONTENT";
|
|
314
|
+
message: string;
|
|
315
|
+
};
|
|
@@ -10,5 +10,7 @@ export interface RemoteRuntimeConfig {
|
|
|
10
10
|
serviceWorkerScope: string;
|
|
11
11
|
allowedParentOrigins: string[];
|
|
12
12
|
runtimeConfigUrl: string;
|
|
13
|
+
/** 与本 Runtime release 绑定的独立评测插件;仅 Mars 审核会话动态加载。 */
|
|
14
|
+
auditPluginUrl?: string;
|
|
13
15
|
}
|
|
14
16
|
export declare function startRemoteMiniAppSimulatorRuntime(): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { createRemoteMiniAppSimulator, type RemoteMiniAppSimulator, type RemoteMiniAppSimulatorOptions, type RemoteSimulatorEventHandler, } from "./remote/client";
|
|
1
|
+
export { createRemoteMiniAppSimulator, type RemoteMiniAppSimulator, type RemoteMiniAppSimulatorOptions, type RemoteSimulatorEventHandler, type RemoteTrackerDeliveryInfo, } from "./remote/client";
|
|
2
2
|
export { BusinessLine } from "./business-line";
|
|
3
|
-
export { REMOTE_INSPECTOR_PAUSE_RUNTIME_CAPABILITY, REMOTE_SIMULATOR_PROTOCOL_VERSION, type RemoteSimulatorGatewayOptions, type RemoteSimulatorSerializableOptions, } from "./remote/protocol";
|
|
3
|
+
export { REMOTE_INSPECTOR_PAUSE_RUNTIME_CAPABILITY, REMOTE_SIMULATOR_PROTOCOL_VERSION, type RemoteAuditContext, type RemoteSimulatorGatewayOptions, type RemoteSimulatorSerializableOptions, } from "./remote/protocol";
|
|
4
4
|
export { MiniAppJsApiErrorCode, MINIAPP_SCREENSHOT_ERROR_CODE } from "./types";
|
|
5
5
|
export type { MiniAppContentMode, MiniAppLoadZipResult, MiniAppHostApiController, MiniAppHostApiEntry, MiniAppHostApiHandler, MiniAppHostApiRequest, MiniAppHostRequest, MiniAppHostRequestOptions, MiniAppHostRequestResponse, MiniAppViewport, VisualSelection, XhsNoteAppCardData, XhsNotePreviewUser, XhsWidgetCoverData, MiniAppSimulatorRoute, MiniAppRedirectOptions, MiniAppScreenShotResult, MiniAppScreenShotErrorCode, MiniAppRouterChangeEvent, MiniAppSimulatorOptions, } from "./types";
|
|
@@ -29,6 +29,10 @@ export interface ServiceWorkerHostLike {
|
|
|
29
29
|
fileUrl(fsScope: string, path: string): string;
|
|
30
30
|
mount(input: ServiceWorkerMountInput): Promise<string>;
|
|
31
31
|
restoreMount(id: string): Promise<void>;
|
|
32
|
+
remount(id: string, patch: {
|
|
33
|
+
injectHead: string;
|
|
34
|
+
csp: string;
|
|
35
|
+
}): Promise<boolean>;
|
|
32
36
|
fsInvoke(id: string, op: ServiceWorkerFileSystemOperation, args?: ServiceWorkerFileSystemArgs): Promise<unknown>;
|
|
33
37
|
unmount(id: string): void;
|
|
34
38
|
}
|
|
@@ -55,6 +59,17 @@ export declare class ServiceWorkerHost {
|
|
|
55
59
|
mount(input: ServiceWorkerMountInput): Promise<string>;
|
|
56
60
|
/** 重新挂载已知实例:用于 iframe 被卸载后再次加载虚拟 URL 前恢复 SW 代理。 */
|
|
57
61
|
restoreMount(id: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* 就地替换已挂载实例的 head 注入与 CSP,虚拟 URL 保持不变。
|
|
64
|
+
*
|
|
65
|
+
* MOUNT 在 worker 侧按 id 覆盖写,所以重发一次即可让后续对同一 URL 的导航拿到新
|
|
66
|
+
* 注入。文件表复用快照副本(原始 ArrayBuffer 首次传输时已被 detach)。
|
|
67
|
+
* 返回 false 表示该 id 没有快照,调用方应回退到完整重新加载。
|
|
68
|
+
*/
|
|
69
|
+
remount(id: string, patch: {
|
|
70
|
+
injectHead: string;
|
|
71
|
+
csp: string;
|
|
72
|
+
}): Promise<boolean>;
|
|
58
73
|
/**
|
|
59
74
|
* 文件系统调用(host→SW):按 `op` 分派并返回 op 结果。
|
|
60
75
|
*/
|
|
@@ -5,6 +5,12 @@ export interface DefaultTracker {
|
|
|
5
5
|
/** 立即发送缓冲中的所有打点 */
|
|
6
6
|
flush(): void;
|
|
7
7
|
}
|
|
8
|
+
export interface DefaultTrackerDeliveryResult {
|
|
9
|
+
ok: boolean;
|
|
10
|
+
status?: number;
|
|
11
|
+
attempts: number;
|
|
12
|
+
eventCount: number;
|
|
13
|
+
}
|
|
8
14
|
export interface DefaultTrackerConfig {
|
|
9
15
|
/** xray 上报端点 URL */
|
|
10
16
|
endpoint: string;
|
|
@@ -14,6 +20,8 @@ export interface DefaultTrackerConfig {
|
|
|
14
20
|
resolveUserId: () => Promise<string>;
|
|
15
21
|
/** 打印到 console 而非真正上报;仅显式传 true 时开启。 */
|
|
16
22
|
debug?: boolean;
|
|
23
|
+
/** 单批请求完成后的诊断回调,不包含事件正文。 */
|
|
24
|
+
onDelivery?: (result: DefaultTrackerDeliveryResult) => void;
|
|
17
25
|
}
|
|
18
26
|
/** 创建默认 Tracker:自定义点位缓冲后批量 POST 到 APM 端点 */
|
|
19
27
|
export declare function createDefaultTracker(config: DefaultTrackerConfig): DefaultTracker;
|
|
@@ -4,6 +4,7 @@ import type { MiniAppPermissionKind, MiniAppPermissionSheetResult } from '../nat
|
|
|
4
4
|
import type { MiniAppEventHandler, MiniAppEventName } from './events';
|
|
5
5
|
import type { MiniAppInspectorController } from './inspector';
|
|
6
6
|
import type { GestureDispatchInput, GestureDispatchResult } from '../gesture/types';
|
|
7
|
+
import type { InjectionModule } from '../injection/types';
|
|
7
8
|
export type { GestureDispatchAction, GestureDispatchInput, GestureDispatchResult } from '../gesture/types';
|
|
8
9
|
/**
|
|
9
10
|
* 配置与运行态类型(原 types.ts 段落 1)。
|
|
@@ -790,6 +791,29 @@ export interface MiniAppSimulator {
|
|
|
790
791
|
* 宿主可据此在主进程把真 Chrome DevTools 嵌入自定义面板(setDevToolsWebContents)。
|
|
791
792
|
*/
|
|
792
793
|
getWebContentsId(): number | null;
|
|
794
|
+
/**
|
|
795
|
+
* 注册扩展注入模块(评测探针等),下次 load / reload 生效。
|
|
796
|
+
* 内部会把 security 重排到末位,保证探针在 seal 锁定内置原型之前安装。
|
|
797
|
+
*/
|
|
798
|
+
registerInjection(module: InjectionModule): void;
|
|
799
|
+
/** 注销扩展注入模块;下次 load / reload 生效。 */
|
|
800
|
+
unregisterInjection(id: string): boolean;
|
|
801
|
+
/**
|
|
802
|
+
* 重算 head 注入并就地替换 SW 已挂载实例的注入载荷;随后 reload 才会带上新注入。
|
|
803
|
+
* 返回 false 表示当前不是 SW 直供状态。
|
|
804
|
+
*/
|
|
805
|
+
refreshInjection(): Promise<boolean>;
|
|
806
|
+
/** 打开与设备画布并排的侧栏,返回可挂载内容的容器。 */
|
|
807
|
+
openSidePanel(width: number): HTMLElement;
|
|
808
|
+
/** 收起侧栏并清空其内容。 */
|
|
809
|
+
closeSidePanel(): void;
|
|
810
|
+
/** 整块模拟器的交互区域(设备、侧栏及内部留白),用于边界监听。 */
|
|
811
|
+
getInteractionRegions(): readonly HTMLElement[];
|
|
812
|
+
/**
|
|
813
|
+
* 临时调整 guest 堆熔断线(字节),传 null 恢复建实例时的值。
|
|
814
|
+
* 改值后须 refreshInjection + reload 才会下发新阈值。
|
|
815
|
+
*/
|
|
816
|
+
setHeapLimitOverride(maxHeapUsedBytes: number | false | null): void;
|
|
793
817
|
destroy(reason?: string): void;
|
|
794
818
|
on<E extends MiniAppEventName>(event: E, handler: MiniAppEventHandler<E>): () => void;
|
|
795
819
|
once<E extends MiniAppEventName>(event: E, handler: MiniAppEventHandler<E>): () => void;
|
package/lib/workbench.js
CHANGED