dsh-browser-view 0.1.2 → 0.3.0
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/README.md +158 -16
- package/lib/client.js +1 -1
- package/lib/index.js +3542 -138
- package/lib/types/browser/extract.d.ts +13 -0
- package/lib/types/browser/recordings.d.ts +4 -9
- package/lib/types/browser/reports.d.ts +42 -0
- package/lib/types/browser/session.d.ts +82 -8
- package/lib/types/browser/tools.d.ts +418 -28
- package/lib/types/browser/types.d.ts +49 -0
- package/lib/types/lib/tools.d.ts +11 -0
- package/lib/types/lib/types.d.ts +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function toCsv(rows: Record<string, unknown>[]): string;
|
|
2
|
+
export declare function toJsonl(rows: Record<string, unknown>[]): string;
|
|
3
|
+
export declare function toMarkdownTable(rows: Record<string, unknown>[]): string;
|
|
4
|
+
/** 按格式序列化抽取结果(json 为 pretty JSON 字符串)。 */
|
|
5
|
+
export declare function serializeRows(rows: Record<string, unknown>[], format: string): string;
|
|
6
|
+
/** 由文件扩展名推断序列化格式(显式 format 优先)。 */
|
|
7
|
+
export declare function formatFromFile(file: string): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* 解析 CSV 文本为行对象数组(首行为表头;支持引号包裹、双引号转义、
|
|
10
|
+
* 逗号/换行内嵌)。供 browser_replay 的 dataFile 使用。
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseCsv(text: string): Record<string, string>[];
|
|
13
|
+
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
+
import type { ReplayStep } from "./types.js";
|
|
1
2
|
/** 录制存储目录($DSH_HOME/.dsh-browser/recordings)。 */
|
|
2
3
|
export declare function recordingsDir(): string;
|
|
3
4
|
/** 名字安全化:只保留字母数字 . _ -,连续点压成下划线防路径穿越。 */
|
|
4
5
|
export declare function safeName(name: string): string;
|
|
5
6
|
/** 加载目录下所有 .json 录制进内存表;返回加载数量。坏文件静默跳过。 */
|
|
6
7
|
export declare function loadRecordings(): number;
|
|
7
|
-
/** 写一个录制到磁盘(原子替换);返回文件路径。 */
|
|
8
|
-
export declare function saveRecordingFile(name: string, steps:
|
|
9
|
-
tool: string;
|
|
10
|
-
args: any;
|
|
11
|
-
}[]): string;
|
|
8
|
+
/** 写一个录制到磁盘(原子替换);返回文件路径。formatVersion 2 起步骤可带 meta(选择器指纹)与 {{var}} 占位符。 */
|
|
9
|
+
export declare function saveRecordingFile(name: string, steps: ReplayStep[]): string;
|
|
12
10
|
/** 删除磁盘上的录制文件;返回是否存在并删除。 */
|
|
13
11
|
export declare function deleteRecordingFile(name: string): boolean;
|
|
14
12
|
/** 录制列表(面板 / browser_record list 共用)。 */
|
|
@@ -21,10 +19,7 @@ export declare function listRecordings(): Array<{
|
|
|
21
19
|
/** 录制详情(面板展开查看步骤)。 */
|
|
22
20
|
export declare function recordingDetail(name: string): {
|
|
23
21
|
name: string;
|
|
24
|
-
steps:
|
|
25
|
-
tool: string;
|
|
26
|
-
args: any;
|
|
27
|
-
}[];
|
|
22
|
+
steps: ReplayStep[];
|
|
28
23
|
} | undefined;
|
|
29
24
|
/** 删除录制(内存 + 磁盘同步);返回是否存在并删除。 */
|
|
30
25
|
export declare function deleteRecording(name: string): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** 一步的执行结果(与 runReplay results 条目同形,外加自愈标记)。 */
|
|
2
|
+
export interface RunStepResult {
|
|
3
|
+
index: number;
|
|
4
|
+
tool: string;
|
|
5
|
+
ok: boolean;
|
|
6
|
+
error?: string;
|
|
7
|
+
healed?: boolean;
|
|
8
|
+
via?: string;
|
|
9
|
+
resolved?: string;
|
|
10
|
+
}
|
|
11
|
+
/** 一次 replay/batch 的运行记录。 */
|
|
12
|
+
export interface RunRecord {
|
|
13
|
+
runId: string;
|
|
14
|
+
ts: number;
|
|
15
|
+
kind: "replay" | "batch";
|
|
16
|
+
source: string;
|
|
17
|
+
total: number;
|
|
18
|
+
passed: number;
|
|
19
|
+
failed: number;
|
|
20
|
+
healedCount: number;
|
|
21
|
+
durationMs: number;
|
|
22
|
+
/** data 数据集模式时的行号(单次运行为 undefined)。 */
|
|
23
|
+
row?: number;
|
|
24
|
+
results: RunStepResult[];
|
|
25
|
+
}
|
|
26
|
+
/** 报告存储目录($DSH_HOME/.dsh-browser/reports)。 */
|
|
27
|
+
export declare function reportsDir(): string;
|
|
28
|
+
/** 生成 runId:YYYYMMDD-HHmmss-随机4位。 */
|
|
29
|
+
export declare function makeRunId(ts: number): string;
|
|
30
|
+
/** 追加一条运行记录;超限时截断旧行(原子替换)。 */
|
|
31
|
+
export declare function appendRun(record: RunRecord): void;
|
|
32
|
+
/** 读取全部运行记录(按时间倒序);坏行静默跳过。 */
|
|
33
|
+
export declare function listRuns(limit?: number): RunRecord[];
|
|
34
|
+
/** 最近一次运行(无记录返回 null)。 */
|
|
35
|
+
export declare function latestRun(): RunRecord | null;
|
|
36
|
+
/** 按 runId 取单条记录。 */
|
|
37
|
+
export declare function getRun(runId: string): RunRecord | null;
|
|
38
|
+
/** 生成 Markdown 回归报告。 */
|
|
39
|
+
export declare function renderMarkdownReport(runs: RunRecord[], source?: string): string;
|
|
40
|
+
/** 生成自包含 HTML 回归报告(内联样式,无外部资源)。 */
|
|
41
|
+
export declare function renderHtmlReport(runs: RunRecord[], source?: string): string;
|
|
42
|
+
//# sourceMappingURL=reports.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Page } from "playwright-core";
|
|
2
|
-
import type { BrowserConfig, ProfileState, DownloadEntry, FormField, NavEntry } from "./types.js";
|
|
1
|
+
import type { BrowserContext, Page } from "playwright-core";
|
|
2
|
+
import type { BrowserConfig, ProfileState, DownloadEntry, FormField, NavEntry, RefEntry, ReplayStep, SelectorHint } from "./types.js";
|
|
3
3
|
/** 当前活动 profile 名(默认 "default")。 */
|
|
4
4
|
export declare let currentProfile: string;
|
|
5
5
|
/** 多配置文件浏览器会话:name → 会话状态。 */
|
|
@@ -8,12 +8,24 @@ export declare const profileStates: Map<string, ProfileState>;
|
|
|
8
8
|
export declare const savedForms: Map<string, FormField[]>;
|
|
9
9
|
/** 最近一次 browser_form 填充的字段(供 browser_form_save 无参保存)。 */
|
|
10
10
|
export declare let lastFormFields: FormField[];
|
|
11
|
+
/** 记录一次 aria 快照分配的 ref(整表替换)。 */
|
|
12
|
+
export declare function setPageRefs(page: Page, refs: Map<string, RefEntry>): void;
|
|
13
|
+
/** 查询某个 ref 的定位信息;未注册返回 undefined。 */
|
|
14
|
+
export declare function pageRef(page: Page, ref: string): RefEntry | undefined;
|
|
15
|
+
/** 清空页面的 ref 表(导航/新快照时调用)。 */
|
|
16
|
+
export declare function clearPageRefs(page: Page): void;
|
|
17
|
+
/** 取页面当前完整 ref 表(browser_find 增量续号合并用;无则空 Map)。 */
|
|
18
|
+
export declare function pageRefsOf(page: Page): Map<string, RefEntry>;
|
|
19
|
+
export interface SnapshotCache {
|
|
20
|
+
version: number;
|
|
21
|
+
text: string;
|
|
22
|
+
aria: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function snapshotCacheOf(page: Page): SnapshotCache | undefined;
|
|
25
|
+
export declare function setSnapshotCache(page: Page, cache: SnapshotCache): void;
|
|
11
26
|
/** 已保存的录制脚本:name → 步骤数组。 */
|
|
12
27
|
export declare const savedRecordings: Map<string, {
|
|
13
|
-
steps:
|
|
14
|
-
tool: string;
|
|
15
|
-
args: any;
|
|
16
|
-
}[];
|
|
28
|
+
steps: ReplayStep[];
|
|
17
29
|
savedAt: number;
|
|
18
30
|
}>;
|
|
19
31
|
/** 一次工具调用的记录(操作轨迹 / 录制 / 回放共用)。 */
|
|
@@ -24,15 +36,69 @@ export interface TestCall {
|
|
|
24
36
|
ms: number;
|
|
25
37
|
ts: number;
|
|
26
38
|
error?: string;
|
|
39
|
+
/** 录制时采集的选择器指纹(回放自愈用;register 包装层异步补齐)。 */
|
|
40
|
+
meta?: {
|
|
41
|
+
hint?: SelectorHint;
|
|
42
|
+
source?: "human";
|
|
43
|
+
};
|
|
44
|
+
/** source: "human" 表示这条来自用户在浏览器中的手动操作(混合录制)。 */
|
|
45
|
+
source?: "human";
|
|
27
46
|
}
|
|
28
47
|
export declare function isRecording(): boolean;
|
|
29
48
|
export declare function startRecording(): void;
|
|
30
49
|
export declare function stopRecording(): TestCall[];
|
|
31
|
-
/**
|
|
32
|
-
export declare function
|
|
50
|
+
/** 最近一次完整录制(start→stop)的 buffer;从未录制过返回 null。 */
|
|
51
|
+
export declare function lastRecordingOf(): TestCall[] | null;
|
|
52
|
+
/** 操作轨迹追加(同时写入录制 buffer,排除 record/replay 自身)。返回存入的调用对象(供调用方补 meta)。 */
|
|
53
|
+
export declare function recordCall(call: TestCall): TestCall;
|
|
33
54
|
/** 操作轨迹(按时间倒序,最新在前)。 */
|
|
34
55
|
export declare function testLogOf(): TestCall[];
|
|
56
|
+
export declare function setPauseInstruction(instruction: string): void;
|
|
57
|
+
export declare function clearPauseInstruction(): void;
|
|
58
|
+
export declare function currentPause(): {
|
|
59
|
+
instruction: string;
|
|
60
|
+
startedAt: number;
|
|
61
|
+
} | null;
|
|
62
|
+
/** 一次待审批的敏感操作(browser_confirm 等待期间供面板展示与提交决策)。 */
|
|
63
|
+
export interface PendingConfirm {
|
|
64
|
+
id: string;
|
|
65
|
+
reason: string;
|
|
66
|
+
tool?: string;
|
|
67
|
+
args?: Record<string, any>;
|
|
68
|
+
startedAt: number;
|
|
69
|
+
decision?: "allowed" | "denied";
|
|
70
|
+
}
|
|
71
|
+
export declare function setPendingConfirm(entry: PendingConfirm): void;
|
|
72
|
+
export declare function getPendingConfirm(): PendingConfirm | null;
|
|
73
|
+
export declare function clearPendingConfirm(): void;
|
|
74
|
+
/** 面板提交审批决策;id 不匹配(已被新审批取代/超时清理)时返回 false。 */
|
|
75
|
+
export declare function resolveConfirm(id: string, decision: "allowed" | "denied"): boolean;
|
|
35
76
|
export declare function clearTestLog(): void;
|
|
77
|
+
/** window 上的回传 binding 名(须为合法 JS 标识符)。 */
|
|
78
|
+
export declare const HUMAN_BINDING = "__dshBrowserHumanEvent";
|
|
79
|
+
/** agent 即将/刚刚执行了 DOM 操作(register 包装层调用);1.5s 内的页内事件视为工具回声。 */
|
|
80
|
+
export declare function noteAgentAction(): void;
|
|
81
|
+
/** 导出供测试:距上次 agent 操作是否在去重窗口内。 */
|
|
82
|
+
export declare function agentActionRecent(now?: number, windowMs?: number): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* 页内人工操作事件 → 录制步骤(纯函数,导出供测试)。
|
|
85
|
+
* payload 由 installHumanRecorder 生成:{ kind, selector, value?, testid?, role?, name?, id?, text?, tag? }。
|
|
86
|
+
* 无法映射(缺 selector / 未知 kind / 空输入)返回 null。
|
|
87
|
+
*/
|
|
88
|
+
export declare function humanEventToStep(payload: unknown): {
|
|
89
|
+
tool: string;
|
|
90
|
+
args: Record<string, any>;
|
|
91
|
+
meta: {
|
|
92
|
+
hint: SelectorHint;
|
|
93
|
+
source: "human";
|
|
94
|
+
};
|
|
95
|
+
} | null;
|
|
96
|
+
/**
|
|
97
|
+
* 页内注入的人工操作监听(addInitScript 序列化;每次导航自动重装)。
|
|
98
|
+
* 监听常驻但 node 侧只在录制中生效,关闭录制等价于"移除"。
|
|
99
|
+
* 只上报可交互元素上的 click 与表单控件的 change,避免逐键噪音。
|
|
100
|
+
*/
|
|
101
|
+
export declare function installHumanRecorder(): void;
|
|
36
102
|
/** 网络请求/响应记录。 */
|
|
37
103
|
export interface NetworkEntry {
|
|
38
104
|
url: string;
|
|
@@ -62,6 +128,14 @@ export declare function loadPlaywright(): Promise<typeof import("playwright-core
|
|
|
62
128
|
export declare function launchProfile(name: string, config: BrowserConfig): Promise<void>;
|
|
63
129
|
/** 当前 profile 状态(未启动时创建空状态)。 */
|
|
64
130
|
export declare function stateOf(): ProfileState;
|
|
131
|
+
export interface NamedContext {
|
|
132
|
+
context: BrowserContext;
|
|
133
|
+
pageIds: Set<number>;
|
|
134
|
+
createdAt: number;
|
|
135
|
+
}
|
|
136
|
+
export declare function namedContextsOf(): Map<string, NamedContext>;
|
|
137
|
+
/** 把一个已 attach 的页面注册进 profile 标签表并激活,返回分配的 tab id。 */
|
|
138
|
+
export declare function registerTabPage(state: ProfileState, page: Page): number;
|
|
65
139
|
/** 新建一个页面(当前 profile 会话未启动时先启动)。 */
|
|
66
140
|
export declare function newPage(config: BrowserConfig): Promise<Page>;
|
|
67
141
|
/** 返回当前活动页面(没有则新建),并保证浏览器已启动。 */
|