@mearl/client 2.0.2 → 2.2.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 +6 -2
- package/dist/actionTimeouts.js +9 -11
- package/dist/cli.js +5 -2
- package/dist/commands.d.ts +890 -4
- package/dist/commands.js +79 -4
- package/dist/generated-browser-action-protocol.d.ts +677 -0
- package/dist/generated-browser-action-protocol.js +144 -0
- package/dist/index.d.ts +41 -425
- package/dist/index.js +10 -12
- package/dist/socket.d.ts +2 -0
- package/dist/socket.js +70 -19
- package/package.json +3 -3
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Generated by scripts/generate-client-action-protocol.mjs.
|
|
2
|
+
// Do not edit directly; update browser-core/src/browserActionProtocol.ts.
|
|
3
|
+
export const PAGE_ACT_ACTIONS = [
|
|
4
|
+
'page_click',
|
|
5
|
+
'page_type',
|
|
6
|
+
'page_hover',
|
|
7
|
+
'page_scroll',
|
|
8
|
+
'page_press',
|
|
9
|
+
'page_upload',
|
|
10
|
+
'page_eval',
|
|
11
|
+
];
|
|
12
|
+
export const BROWSER_ACTIONS = {
|
|
13
|
+
get_requests: true,
|
|
14
|
+
get_logs: true,
|
|
15
|
+
get_events: true,
|
|
16
|
+
get_api_schema: true,
|
|
17
|
+
set_mock: true,
|
|
18
|
+
get_mocks: true,
|
|
19
|
+
set_rule: true,
|
|
20
|
+
get_rules: true,
|
|
21
|
+
send_request: true,
|
|
22
|
+
send_mtop_request: true,
|
|
23
|
+
tdbank_account: true,
|
|
24
|
+
browser_list: true,
|
|
25
|
+
browser_select_browser: true,
|
|
26
|
+
browser_release: true,
|
|
27
|
+
browser_launch: true,
|
|
28
|
+
browser_close: true,
|
|
29
|
+
page_screenshot: true,
|
|
30
|
+
page_selected_element: true,
|
|
31
|
+
tab_open: true,
|
|
32
|
+
tab_close: true,
|
|
33
|
+
tab_list: true,
|
|
34
|
+
page_click: true,
|
|
35
|
+
page_type: true,
|
|
36
|
+
page_scroll: true,
|
|
37
|
+
page_hover: true,
|
|
38
|
+
page_eval: true,
|
|
39
|
+
page_snapshot: true,
|
|
40
|
+
page_press: true,
|
|
41
|
+
page_wait: true,
|
|
42
|
+
page_navigate: true,
|
|
43
|
+
page_upload: true,
|
|
44
|
+
page_frames: true,
|
|
45
|
+
set_device_emulation: true,
|
|
46
|
+
set_timezone: true,
|
|
47
|
+
get_cookie: true,
|
|
48
|
+
set_cookie: true,
|
|
49
|
+
record_start: true,
|
|
50
|
+
record_stop: true,
|
|
51
|
+
request_domain_permission: true,
|
|
52
|
+
get_user_info: true,
|
|
53
|
+
run_actions: true,
|
|
54
|
+
};
|
|
55
|
+
export const BROWSER_COMMAND_ACTIONS = {
|
|
56
|
+
get_requests: true,
|
|
57
|
+
get_logs: true,
|
|
58
|
+
get_events: true,
|
|
59
|
+
get_api_schema: true,
|
|
60
|
+
set_mock: true,
|
|
61
|
+
get_mocks: true,
|
|
62
|
+
set_rule: true,
|
|
63
|
+
get_rules: true,
|
|
64
|
+
send_request: true,
|
|
65
|
+
send_mtop_request: true,
|
|
66
|
+
tdbank_account: true,
|
|
67
|
+
browser_list: true,
|
|
68
|
+
browser_release: true,
|
|
69
|
+
browser_launch: true,
|
|
70
|
+
browser_close: true,
|
|
71
|
+
page_screenshot: true,
|
|
72
|
+
page_selected_element: true,
|
|
73
|
+
tab_open: true,
|
|
74
|
+
tab_close: true,
|
|
75
|
+
tab_list: true,
|
|
76
|
+
page_click: true,
|
|
77
|
+
page_type: true,
|
|
78
|
+
page_scroll: true,
|
|
79
|
+
page_hover: true,
|
|
80
|
+
page_eval: true,
|
|
81
|
+
page_snapshot: true,
|
|
82
|
+
page_press: true,
|
|
83
|
+
page_wait: true,
|
|
84
|
+
page_navigate: true,
|
|
85
|
+
page_upload: true,
|
|
86
|
+
page_frames: true,
|
|
87
|
+
set_device_emulation: true,
|
|
88
|
+
set_timezone: true,
|
|
89
|
+
get_cookie: true,
|
|
90
|
+
set_cookie: true,
|
|
91
|
+
record_start: true,
|
|
92
|
+
record_stop: true,
|
|
93
|
+
request_domain_permission: true,
|
|
94
|
+
get_user_info: true,
|
|
95
|
+
run_actions: true,
|
|
96
|
+
};
|
|
97
|
+
export const EXTENSION_BROWSER_ACTIONS = {
|
|
98
|
+
get_requests: true,
|
|
99
|
+
get_logs: true,
|
|
100
|
+
get_events: true,
|
|
101
|
+
get_api_schema: true,
|
|
102
|
+
set_mock: true,
|
|
103
|
+
get_mocks: true,
|
|
104
|
+
set_rule: true,
|
|
105
|
+
get_rules: true,
|
|
106
|
+
send_request: true,
|
|
107
|
+
send_mtop_request: true,
|
|
108
|
+
tdbank_account: true,
|
|
109
|
+
browser_release: true,
|
|
110
|
+
page_screenshot: true,
|
|
111
|
+
page_selected_element: true,
|
|
112
|
+
tab_open: true,
|
|
113
|
+
tab_close: true,
|
|
114
|
+
tab_list: true,
|
|
115
|
+
page_click: true,
|
|
116
|
+
page_type: true,
|
|
117
|
+
page_scroll: true,
|
|
118
|
+
page_hover: true,
|
|
119
|
+
page_eval: true,
|
|
120
|
+
page_snapshot: true,
|
|
121
|
+
page_press: true,
|
|
122
|
+
page_wait: true,
|
|
123
|
+
page_navigate: true,
|
|
124
|
+
page_upload: true,
|
|
125
|
+
page_frames: true,
|
|
126
|
+
set_device_emulation: true,
|
|
127
|
+
set_timezone: true,
|
|
128
|
+
get_cookie: true,
|
|
129
|
+
set_cookie: true,
|
|
130
|
+
record_start: true,
|
|
131
|
+
record_stop: true,
|
|
132
|
+
request_domain_permission: true,
|
|
133
|
+
get_user_info: true,
|
|
134
|
+
run_actions: true,
|
|
135
|
+
};
|
|
136
|
+
export function isBrowserAction(value) {
|
|
137
|
+
return typeof value === 'string' && Object.hasOwn(BROWSER_ACTIONS, value);
|
|
138
|
+
}
|
|
139
|
+
export function isBrowserCommandAction(value) {
|
|
140
|
+
return typeof value === 'string' && Object.hasOwn(BROWSER_COMMAND_ACTIONS, value);
|
|
141
|
+
}
|
|
142
|
+
export function isExtensionBrowserAction(value) {
|
|
143
|
+
return typeof value === 'string' && Object.hasOwn(EXTENSION_BROWSER_ACTIONS, value);
|
|
144
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,431 +3,47 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 通过 Unix Domain Socket 与 Chrome Extension 的 native host 通信,
|
|
5
5
|
* 提供类型安全的具名方法和通用的 invoke 底层方法。
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* import * as client from '@mearl/client';
|
|
10
|
-
*
|
|
11
|
-
* // 具名方法(类型安全)
|
|
12
|
-
* const result = await client.sendRequest({ url: 'https://...', method: 'GET', withCookies: true });
|
|
13
|
-
*
|
|
14
|
-
* // 底层通用方法(灵活扩展)
|
|
15
|
-
* const data = await client.invoke('send_request', { url: '...' });
|
|
16
|
-
* ```
|
|
17
6
|
*/
|
|
18
7
|
export { invoke } from './socket.js';
|
|
19
8
|
export type { InvokeOptions } from './socket.js';
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export declare function
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export declare function
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export declare function
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
/** 请求 query/body 字段子集匹配;$index 从 0 开始指定调用顺序 */
|
|
62
|
-
conditions?: Record<string, any>;
|
|
63
|
-
}
|
|
64
|
-
export declare function setMock(params: SetMockParams): Promise<any>;
|
|
65
|
-
export interface GetMocksParams {
|
|
66
|
-
apiName?: string;
|
|
67
|
-
}
|
|
68
|
-
export declare function getMocks(params?: GetMocksParams): Promise<any>;
|
|
69
|
-
export interface GetApiSchemaParams {
|
|
70
|
-
api: string;
|
|
71
|
-
version?: string;
|
|
72
|
-
fields?: ('schema' | 'hsf')[];
|
|
73
|
-
}
|
|
74
|
-
export declare function getApiSchema(params: GetApiSchemaParams): Promise<any>;
|
|
75
|
-
export interface SendRequestParams {
|
|
76
|
-
url: string;
|
|
77
|
-
method?: string;
|
|
78
|
-
headers?: Record<string, string>;
|
|
79
|
-
params?: Record<string, string>;
|
|
80
|
-
body?: any;
|
|
81
|
-
withCookies?: boolean;
|
|
82
|
-
cookieDomain?: string;
|
|
83
|
-
responseType?: 'json' | 'text' | 'auto';
|
|
84
|
-
timeout?: number;
|
|
85
|
-
}
|
|
86
|
-
export declare function sendRequest(params: SendRequestParams): Promise<any>;
|
|
87
|
-
export interface SendMtopRequestParams {
|
|
88
|
-
api: string;
|
|
89
|
-
data?: any;
|
|
90
|
-
version?: string;
|
|
91
|
-
method?: string;
|
|
92
|
-
appKey?: string;
|
|
93
|
-
env?: string;
|
|
94
|
-
timeout?: number;
|
|
95
|
-
}
|
|
96
|
-
export declare function sendMtopRequest(params: SendMtopRequestParams): Promise<any>;
|
|
97
|
-
export interface TdbankAccountParams {
|
|
98
|
-
operation?: 'current' | 'list' | 'switch' | 'borrow';
|
|
99
|
-
pageIndex?: number;
|
|
100
|
-
refresh?: boolean;
|
|
101
|
-
query?: string;
|
|
102
|
-
accountId?: string | number;
|
|
103
|
-
havanaId?: string | number;
|
|
104
|
-
site?: string | number;
|
|
105
|
-
tabId?: number;
|
|
106
|
-
}
|
|
107
|
-
export declare function tdbankAccount(params?: TdbankAccountParams): Promise<any>;
|
|
108
|
-
export type BrowserStatus = 'connected' | 'running_disconnected' | 'stopped';
|
|
109
|
-
export interface BrowserInfoBase {
|
|
110
|
-
browserId: string;
|
|
111
|
-
name: string;
|
|
112
|
-
status: BrowserStatus;
|
|
113
|
-
extensionVersion?: string;
|
|
114
|
-
nativeHostVersion?: string;
|
|
115
|
-
transport?: 'extension' | 'cdp';
|
|
116
|
-
}
|
|
117
|
-
export interface RegularBrowserInfo extends BrowserInfoBase {
|
|
118
|
-
type: 'regular';
|
|
119
|
-
status: 'connected';
|
|
120
|
-
}
|
|
121
|
-
export interface ManagedBrowserAccount {
|
|
122
|
-
accountId?: string;
|
|
123
|
-
loginId?: string;
|
|
124
|
-
nickname: string;
|
|
125
|
-
}
|
|
126
|
-
export interface ManagedBrowserInfo extends BrowserInfoBase {
|
|
127
|
-
type: 'managed';
|
|
128
|
-
headless: boolean;
|
|
129
|
-
persistent: boolean;
|
|
130
|
-
cdpPort: number;
|
|
131
|
-
createdAt: string;
|
|
132
|
-
account?: ManagedBrowserAccount;
|
|
133
|
-
copiedCookies?: {
|
|
134
|
-
domains: string[];
|
|
135
|
-
count: number;
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
export type BrowserInfo = RegularBrowserInfo | ManagedBrowserInfo;
|
|
139
|
-
export interface BrowserListResult {
|
|
140
|
-
count: number;
|
|
141
|
-
connectedCount: number;
|
|
142
|
-
defaultBrowserId: string | null;
|
|
143
|
-
browsers: BrowserInfo[];
|
|
144
|
-
}
|
|
145
|
-
export declare function browserList(): Promise<BrowserListResult>;
|
|
146
|
-
export interface SelectBrowserParams {
|
|
147
|
-
browser?: string;
|
|
148
|
-
}
|
|
149
|
-
export interface SelectBrowserResult {
|
|
150
|
-
selected: {
|
|
151
|
-
browserId: string;
|
|
152
|
-
name: string;
|
|
153
|
-
} | null;
|
|
154
|
-
note?: string;
|
|
155
|
-
}
|
|
156
|
-
export declare function selectBrowser(params?: SelectBrowserParams): Promise<SelectBrowserResult>;
|
|
157
|
-
export interface BrowserLaunchParams {
|
|
158
|
-
name: string;
|
|
159
|
-
headless?: boolean;
|
|
160
|
-
userAgentMode?: 'default' | 'desktop';
|
|
161
|
-
persistent?: boolean;
|
|
162
|
-
executablePath?: string;
|
|
163
|
-
url?: string;
|
|
164
|
-
accountId?: string | number;
|
|
165
|
-
havanaId?: string | number;
|
|
166
|
-
site?: string | number;
|
|
167
|
-
query?: string;
|
|
168
|
-
tabId?: number;
|
|
169
|
-
copyCookieDomains?: string[];
|
|
170
|
-
}
|
|
171
|
-
export declare function browserLaunch(params: BrowserLaunchParams): Promise<any>;
|
|
172
|
-
export interface BrowserCloseParams {
|
|
173
|
-
browser: string;
|
|
174
|
-
deleteProfile?: boolean;
|
|
175
|
-
}
|
|
176
|
-
export declare function browserClose(params: BrowserCloseParams): Promise<any>;
|
|
177
|
-
export interface SetRuleParams {
|
|
178
|
-
actionType: 'redirect' | 'block' | 'allow' | 'upgradeScheme' | 'modifyHeaders';
|
|
179
|
-
filter: string;
|
|
180
|
-
redirectUrl?: string;
|
|
181
|
-
requestHeaders?: Array<{
|
|
182
|
-
header: string;
|
|
183
|
-
operation: 'set' | 'append' | 'remove';
|
|
184
|
-
value?: string;
|
|
185
|
-
}>;
|
|
186
|
-
responseHeaders?: Array<{
|
|
187
|
-
header: string;
|
|
188
|
-
operation: 'set' | 'append' | 'remove';
|
|
189
|
-
value?: string;
|
|
190
|
-
}>;
|
|
191
|
-
initiatorDomains?: string;
|
|
192
|
-
resourceTypes?: string[];
|
|
193
|
-
priority?: number;
|
|
194
|
-
description?: string;
|
|
195
|
-
}
|
|
196
|
-
export declare function setRule(params: SetRuleParams): Promise<any>;
|
|
197
|
-
/** 返回当前存储的全部请求规则(含 Options 面板配置的),字段结构与 set_rule 入参对齐。 */
|
|
198
|
-
export declare function getRules(): Promise<{
|
|
199
|
-
enabled: boolean;
|
|
200
|
-
rules: Array<Record<string, any>>;
|
|
201
|
-
}>;
|
|
202
|
-
export interface PageScreenshotParams {
|
|
203
|
-
tabId: number;
|
|
204
|
-
selector?: string;
|
|
205
|
-
format?: 'png' | 'jpeg';
|
|
206
|
-
quality?: number;
|
|
207
|
-
}
|
|
208
|
-
export declare function pageScreenshot(params: PageScreenshotParams): Promise<any>;
|
|
209
|
-
export interface PageSelectedElementParams {
|
|
210
|
-
tabId: number;
|
|
211
|
-
includeOuterHTML?: boolean;
|
|
212
|
-
includeScreenshot?: boolean;
|
|
213
|
-
}
|
|
214
|
-
export declare function pageSelectedElement(params: PageSelectedElementParams): Promise<any>;
|
|
215
|
-
export interface TabOpenParams {
|
|
216
|
-
url: string;
|
|
217
|
-
active?: boolean;
|
|
218
|
-
/** 打开前先关闭 Agent 受控的已有标签页。默认 false */
|
|
219
|
-
closeExisting?: boolean;
|
|
220
|
-
/** 是否复用匹配标签页。默认 never,保持始终新开的兼容行为。 */
|
|
221
|
-
reuse?: 'never' | 'prefer' | 'require';
|
|
222
|
-
/** 复用标签页时的 URL 匹配规则。 */
|
|
223
|
-
match?: {
|
|
224
|
-
/** 完整 URL glob,`*` 匹配任意字符;省略时匹配 url。 */
|
|
225
|
-
urlPattern?: string;
|
|
226
|
-
ignoreSearch?: boolean;
|
|
227
|
-
ignoreHash?: boolean;
|
|
228
|
-
onMultiple?: 'error' | 'first';
|
|
229
|
-
};
|
|
230
|
-
/** active 新标签页关闭后,恢复打开前的活动标签页。默认 false。 */
|
|
231
|
-
restoreFocusOnClose?: boolean;
|
|
232
|
-
/**
|
|
233
|
-
* 开 tab 即进入移动端模拟态(视口/UA/触摸),在导航前生效,页面首屏即移动态、无需 reload。
|
|
234
|
-
* 等价于随后立即调用 set_device_emulation,但省一次整页加载并避开桌面态首屏的 UA 判端跳转。
|
|
235
|
-
*/
|
|
236
|
-
emulation?: EmulationOptions;
|
|
237
|
-
/** 把标签页加入指定标题的分组(同窗口同名分组存在则加入,否则新建)。仅扩展模式支持。 */
|
|
238
|
-
group?: string;
|
|
239
|
-
}
|
|
240
|
-
export declare function tabOpen(params: TabOpenParams): Promise<any>;
|
|
241
|
-
export interface TabCloseParams {
|
|
242
|
-
tabId: number;
|
|
243
|
-
}
|
|
244
|
-
export declare function tabClose(params: TabCloseParams): Promise<any>;
|
|
245
|
-
export declare function tabList(): Promise<any>;
|
|
246
|
-
/**
|
|
247
|
-
* 页面交互动作(click/type/hover/scroll/press/upload)默认内置观察:
|
|
248
|
-
* 同一次调用内执行动作并等待异步稳定,返回 `{ action, observation }`。
|
|
249
|
-
* 传 `observe: false` 关闭观察,仅执行裸动作并直接返回其结果。
|
|
250
|
-
* page_eval 默认裸执行,显式传 observe 对象时才进入同一观察链路。
|
|
251
|
-
*/
|
|
252
|
-
export interface PageObserveOptions {
|
|
253
|
-
quietMs?: number;
|
|
254
|
-
firstChangeTimeoutMs?: number;
|
|
255
|
-
timeoutMs?: number;
|
|
256
|
-
navigationGraceMs?: number;
|
|
257
|
-
navigationTimeoutMs?: number;
|
|
258
|
-
networkIdleMs?: number;
|
|
259
|
-
contentReadyAfterMs?: number;
|
|
260
|
-
}
|
|
261
|
-
export interface PageClickParams {
|
|
262
|
-
tabId: number;
|
|
263
|
-
/** 原生 CSS 选择器,或 snapshot / 页面动作 observation 返回的 @eN ref。 */
|
|
264
|
-
selector?: string;
|
|
265
|
-
/** 按可见文本(AX name)定位;可配合 role/exact 消歧。 */
|
|
266
|
-
text?: string;
|
|
267
|
-
/** 按视口坐标点击(CSS 像素)。 */
|
|
268
|
-
point?: {
|
|
269
|
-
x: number;
|
|
270
|
-
y: number;
|
|
271
|
-
};
|
|
272
|
-
/** 配合 text,按 AX role 过滤。 */
|
|
273
|
-
role?: string;
|
|
274
|
-
/** 配合 text,默认 true(精确匹配),false 时子串匹配。 */
|
|
275
|
-
exact?: boolean;
|
|
276
|
-
/** 配合 text,把 AX 文本匹配限制在指定 CSS 元素或 @eN ref 子树内。 */
|
|
277
|
-
scope?: string;
|
|
278
|
-
/**
|
|
279
|
-
* 点击模式。auto 会在可见页按设备模拟状态选择可信 mouse/touch,在隐藏页
|
|
280
|
-
* 使用 DOM fallback;checkbox/radio 使用带状态校验的 DOM 路径。
|
|
281
|
-
* dom/mouse/touch 可强制指定实际派发方式。
|
|
282
|
-
*/
|
|
283
|
-
clickMode?: 'auto' | 'dom' | 'mouse' | 'touch';
|
|
284
|
-
/** 观察选项;传 false 关闭内置观察。 */
|
|
285
|
-
observe?: PageObserveOptions | false;
|
|
286
|
-
}
|
|
287
|
-
export declare function pageClick(params: PageClickParams): Promise<any>;
|
|
288
|
-
export interface PageTypeParams {
|
|
289
|
-
tabId: number;
|
|
290
|
-
selector: string;
|
|
291
|
-
text: string;
|
|
292
|
-
clearFirst?: boolean;
|
|
293
|
-
/** 观察选项;传 false 关闭内置观察。 */
|
|
294
|
-
observe?: PageObserveOptions | false;
|
|
295
|
-
}
|
|
296
|
-
export declare function pageType(params: PageTypeParams): Promise<any>;
|
|
297
|
-
export interface PageScrollParams {
|
|
298
|
-
tabId: number;
|
|
299
|
-
direction: 'up' | 'down' | 'top' | 'bottom';
|
|
300
|
-
distance?: number;
|
|
301
|
-
/** 原生 CSS 选择器或 page_snapshot 返回的 @eN ref;不传时滚动页面。 */
|
|
302
|
-
selector?: string;
|
|
303
|
-
/** selector 指向子节点时,是否自动使用最近的可滚动祖先。默认 self。 */
|
|
304
|
-
containerPolicy?: 'self' | 'nearest';
|
|
305
|
-
/** 观察选项;传 false 关闭内置观察。 */
|
|
306
|
-
observe?: PageObserveOptions | false;
|
|
307
|
-
}
|
|
308
|
-
export declare function pageScroll(params: PageScrollParams): Promise<any>;
|
|
309
|
-
export interface PageHoverParams {
|
|
310
|
-
tabId: number;
|
|
311
|
-
selector: string;
|
|
312
|
-
/** 观察选项;传 false 关闭内置观察。 */
|
|
313
|
-
observe?: PageObserveOptions | false;
|
|
314
|
-
}
|
|
315
|
-
export declare function pageHover(params: PageHoverParams): Promise<any>;
|
|
316
|
-
export interface PageEvalParams {
|
|
317
|
-
tabId: number;
|
|
318
|
-
expression: string;
|
|
319
|
-
frameId?: string;
|
|
320
|
-
awaitPromise?: boolean;
|
|
321
|
-
/** 显式传入时观察表达式引发的页面变化;不传保持轻量裸执行。 */
|
|
322
|
-
observe?: PageObserveOptions;
|
|
323
|
-
}
|
|
324
|
-
export declare function pageEval(params: PageEvalParams): Promise<any>;
|
|
325
|
-
export interface PageSnapshotQuery {
|
|
326
|
-
/** 按 accessibility name 匹配。 */
|
|
327
|
-
text?: string;
|
|
328
|
-
/** 按 AX role 匹配。 */
|
|
329
|
-
role?: string;
|
|
330
|
-
/** 默认 true 精确匹配;false 时按子串匹配 text。 */
|
|
331
|
-
exact?: boolean;
|
|
332
|
-
}
|
|
333
|
-
export interface PageSnapshotParams {
|
|
334
|
-
tabId: number;
|
|
335
|
-
depth?: number;
|
|
336
|
-
maxChars?: number;
|
|
337
|
-
maxNodes?: number;
|
|
338
|
-
/** CSS 根元素;与 rootRef 互斥。 */
|
|
339
|
-
rootSelector?: string;
|
|
340
|
-
/** 以已有 @eN ref 为根获取局部 AX 子树;与 rootSelector 互斥。 */
|
|
341
|
-
rootRef?: string;
|
|
342
|
-
/** rootRef 向上扩展的 DOM 祖先层数,默认 0,最大 20。 */
|
|
343
|
-
ancestorDepth?: number;
|
|
344
|
-
/** 服务端过滤 AX 树,只保留命中节点及其祖先路径。 */
|
|
345
|
-
query?: PageSnapshotQuery;
|
|
346
|
-
/** full 为完整树;interactive 为当前视口内的语义控件;viewport 为当前可视区域。 */
|
|
347
|
-
mode?: 'full' | 'interactive' | 'viewport';
|
|
348
|
-
}
|
|
349
|
-
export declare function pageSnapshot(params: PageSnapshotParams): Promise<any>;
|
|
350
|
-
export interface PagePressParams {
|
|
351
|
-
tabId: number;
|
|
352
|
-
key: string;
|
|
353
|
-
modifiers?: string[];
|
|
354
|
-
/** 观察选项;传 false 关闭内置观察。 */
|
|
355
|
-
observe?: PageObserveOptions | false;
|
|
356
|
-
}
|
|
357
|
-
export declare function pagePress(params: PagePressParams): Promise<any>;
|
|
358
|
-
export interface PageWaitParams {
|
|
359
|
-
tabId: number;
|
|
360
|
-
time?: number;
|
|
361
|
-
selector?: string;
|
|
362
|
-
/** 在页面主执行上下文中轮询,表达式返回 truthy 时结束。 */
|
|
363
|
-
condition?: string;
|
|
364
|
-
timeout?: number;
|
|
365
|
-
interval?: number;
|
|
366
|
-
}
|
|
367
|
-
export declare function pageWait(params: PageWaitParams): Promise<any>;
|
|
368
|
-
export interface PageNavigateParams {
|
|
369
|
-
tabId: number;
|
|
370
|
-
/** 要导航到的 URL;与 refresh/history 互斥。 */
|
|
371
|
-
url?: string;
|
|
372
|
-
/** 为 true 时直接重新加载当前页面;与 url/history 互斥。 */
|
|
373
|
-
refresh?: boolean;
|
|
374
|
-
/** 沿当前标签页的浏览历史后退或前进;与 url/refresh 互斥。 */
|
|
375
|
-
history?: 'back' | 'forward';
|
|
376
|
-
}
|
|
377
|
-
export declare function pageNavigate(params: PageNavigateParams): Promise<any>;
|
|
378
|
-
export interface PageUploadParams {
|
|
379
|
-
tabId: number;
|
|
380
|
-
selector: string;
|
|
381
|
-
filePaths: string[];
|
|
382
|
-
/** 观察选项;传 false 关闭内置观察。 */
|
|
383
|
-
observe?: PageObserveOptions | false;
|
|
384
|
-
}
|
|
385
|
-
export declare function pageUpload(params: PageUploadParams): Promise<any>;
|
|
386
|
-
export interface PageFramesParams {
|
|
387
|
-
tabId: number;
|
|
388
|
-
}
|
|
389
|
-
export declare function pageFrames(params: PageFramesParams): Promise<any>;
|
|
390
|
-
export type DevicePresetName = 'iphone-15-pro' | 'iphone-se' | 'pixel-8' | 'ipad-mini' | 'galaxy-s23';
|
|
391
|
-
/**
|
|
392
|
-
* 移动端模拟入参(不含 enabled/tabId/reload)。tab_open 的 emulation 字段与
|
|
393
|
-
* set_device_emulation 复用同一套字段,规则一致。
|
|
394
|
-
*/
|
|
395
|
-
export interface EmulationOptions {
|
|
396
|
-
preset?: DevicePresetName;
|
|
397
|
-
width?: number;
|
|
398
|
-
height?: number;
|
|
399
|
-
deviceScaleFactor?: number;
|
|
400
|
-
mobile?: boolean;
|
|
401
|
-
userAgent?: string;
|
|
402
|
-
orientation?: 'portrait' | 'landscape';
|
|
403
|
-
touch?: boolean;
|
|
404
|
-
}
|
|
405
|
-
export interface SetDeviceEmulationParams extends EmulationOptions {
|
|
406
|
-
tabId: number;
|
|
407
|
-
enabled: boolean;
|
|
408
|
-
reload?: boolean;
|
|
409
|
-
}
|
|
410
|
-
export declare function setDeviceEmulation(params: SetDeviceEmulationParams): Promise<any>;
|
|
411
|
-
export interface SetTimezoneParams {
|
|
412
|
-
tabId: number;
|
|
413
|
-
/** IANA timezone identifier, or an empty string to restore the browser default. */
|
|
414
|
-
timezone: string;
|
|
415
|
-
}
|
|
416
|
-
export interface SetTimezoneResult {
|
|
417
|
-
enabled: boolean;
|
|
418
|
-
timezone: string | null;
|
|
419
|
-
}
|
|
420
|
-
export declare function setTimezone(params: SetTimezoneParams): Promise<SetTimezoneResult>;
|
|
421
|
-
export interface GetUserInfoParams {
|
|
422
|
-
detail?: boolean;
|
|
423
|
-
}
|
|
424
|
-
export declare function getUserInfo(params?: GetUserInfoParams): Promise<any>;
|
|
425
|
-
export interface ActionStep {
|
|
426
|
-
action: string;
|
|
427
|
-
data?: Record<string, any>;
|
|
428
|
-
}
|
|
429
|
-
export interface RunActionsParams {
|
|
430
|
-
actions: ActionStep[];
|
|
431
|
-
tabId: number;
|
|
432
|
-
}
|
|
433
|
-
export declare function runActions(params: RunActionsParams): Promise<any>;
|
|
9
|
+
export { BROWSER_ACTIONS, BROWSER_COMMAND_ACTIONS, EXTENSION_BROWSER_ACTIONS, PAGE_ACT_ACTIONS, isBrowserAction, isBrowserCommandAction, isExtensionBrowserAction, } from './generated-browser-action-protocol.js';
|
|
10
|
+
export type { ActionStep, BrowserAction, BrowserActionMap, BrowserActionRequest, BrowserActionResponse, BrowserCloseParams, BrowserCommandAction, BrowserInfo, BrowserInfoBase, BrowserLaunchParams, BrowserListResult, BrowserReleaseFailure, BrowserReleaseResult, BrowserStatus, BrowserDevicePresetName, BrowserEmulationOptions, ExtensionBrowserAction, GetApiSchemaParams, GetCookieParams, GetCookieResult, GetEventsParams, GetLogsParams, GetMocksParams, GetRequestsParams, GetUserInfoParams, ManagedBrowserAccount, ManagedBrowserInfo, PageClickParams, PageActAction, PageEvalParams, PageFramesParams, PageHoverParams, PageNavigateParams, PageObservationWaitOptions, PagePressParams, PageScreenshotParams, PageScrollParams, PageSelectedElementParams, PageSnapshotParams, PageSnapshotQuery, PageTypeParams, PageUploadParams, PageWaitParams, RecordParams, RegularBrowserInfo, RequestDomainPermissionParams, RulesResult, RunActionName, RunActionsParams, SelectBrowserParams, SelectBrowserResult, SendMtopRequestParams, SendRequestParams, SetCookieParams, SetCookieResult, SetDeviceEmulationParams, SetMockParams, SetRuleParams, SetTimezoneParams, SetTimezoneResult, TabCloseParams, TabOpenParams, TdbankAccountParams, } from './generated-browser-action-protocol.js';
|
|
11
|
+
import type * as Protocol from './generated-browser-action-protocol.js';
|
|
12
|
+
export declare function getRequests(params?: Protocol.GetRequestsParams): Promise<Protocol.BrowserActionResponse<'get_requests'>>;
|
|
13
|
+
export declare function getLogs(params?: Protocol.GetLogsParams): Promise<Protocol.BrowserActionResponse<'get_logs'>>;
|
|
14
|
+
export declare function getEvents(params?: Protocol.GetEventsParams): Promise<Protocol.BrowserActionResponse<'get_events'>>;
|
|
15
|
+
export declare function setMock(params: Protocol.SetMockParams): Promise<Protocol.BrowserActionResponse<'set_mock'>>;
|
|
16
|
+
export declare function getMocks(params?: Protocol.GetMocksParams): Promise<Protocol.BrowserActionResponse<'get_mocks'>>;
|
|
17
|
+
export declare function getApiSchema(params: Protocol.GetApiSchemaParams): Promise<Protocol.BrowserActionResponse<'get_api_schema'>>;
|
|
18
|
+
export declare function sendRequest(params: Protocol.SendRequestParams): Promise<Protocol.BrowserActionResponse<'send_request'>>;
|
|
19
|
+
export declare function sendMtopRequest(params: Protocol.SendMtopRequestParams): Promise<Protocol.BrowserActionResponse<'send_mtop_request'>>;
|
|
20
|
+
export declare function tdbankAccount(params?: Protocol.TdbankAccountParams): Promise<Protocol.BrowserActionResponse<'tdbank_account'>>;
|
|
21
|
+
export declare function browserList(): Promise<Protocol.BrowserActionResponse<'browser_list'>>;
|
|
22
|
+
export declare function selectBrowser(params?: Protocol.SelectBrowserParams): Promise<Protocol.BrowserActionResponse<'browser_select_browser'>>;
|
|
23
|
+
export declare function browserRelease(): Promise<Protocol.BrowserActionResponse<'browser_release'>>;
|
|
24
|
+
export declare function browserLaunch(params: Protocol.BrowserLaunchParams): Promise<Protocol.BrowserActionResponse<'browser_launch'>>;
|
|
25
|
+
export declare function browserClose(params: Protocol.BrowserCloseParams): Promise<Protocol.BrowserActionResponse<'browser_close'>>;
|
|
26
|
+
export declare function setRule(params: Protocol.SetRuleParams): Promise<Protocol.BrowserActionResponse<'set_rule'>>;
|
|
27
|
+
export declare function getRules(): Promise<Protocol.BrowserActionResponse<'get_rules'>>;
|
|
28
|
+
export declare function pageScreenshot(params: Protocol.PageScreenshotParams): Promise<Protocol.BrowserActionResponse<'page_screenshot'>>;
|
|
29
|
+
export declare function pageSelectedElement(params: Protocol.PageSelectedElementParams): Promise<Protocol.BrowserActionResponse<'page_selected_element'>>;
|
|
30
|
+
export declare function tabOpen(params: Protocol.TabOpenParams): Promise<Protocol.BrowserActionResponse<'tab_open'>>;
|
|
31
|
+
export declare function tabClose(params: Protocol.TabCloseParams): Promise<Protocol.BrowserActionResponse<'tab_close'>>;
|
|
32
|
+
export declare function tabList(): Promise<Protocol.BrowserActionResponse<'tab_list'>>;
|
|
33
|
+
export declare function pageClick(params: Protocol.PageClickParams): Promise<Protocol.BrowserActionResponse<'page_click'>>;
|
|
34
|
+
export declare function pageType(params: Protocol.PageTypeParams): Promise<Protocol.BrowserActionResponse<'page_type'>>;
|
|
35
|
+
export declare function pageScroll(params: Protocol.PageScrollParams): Promise<Protocol.BrowserActionResponse<'page_scroll'>>;
|
|
36
|
+
export declare function pageHover(params: Protocol.PageHoverParams): Promise<Protocol.BrowserActionResponse<'page_hover'>>;
|
|
37
|
+
export declare function pageEval(params: Protocol.PageEvalParams): Promise<Protocol.BrowserActionResponse<'page_eval'>>;
|
|
38
|
+
export declare function pageSnapshot(params: Protocol.PageSnapshotParams): Promise<Protocol.BrowserActionResponse<'page_snapshot'>>;
|
|
39
|
+
export declare function pagePress(params: Protocol.PagePressParams): Promise<Protocol.BrowserActionResponse<'page_press'>>;
|
|
40
|
+
export declare function pageWait(params: Protocol.PageWaitParams): Promise<Protocol.BrowserActionResponse<'page_wait'>>;
|
|
41
|
+
export declare function pageNavigate(params: Protocol.PageNavigateParams): Promise<Protocol.BrowserActionResponse<'page_navigate'>>;
|
|
42
|
+
export declare function pageUpload(params: Protocol.PageUploadParams): Promise<Protocol.BrowserActionResponse<'page_upload'>>;
|
|
43
|
+
export declare function pageFrames(params: Protocol.PageFramesParams): Promise<Protocol.BrowserActionResponse<'page_frames'>>;
|
|
44
|
+
export declare function setDeviceEmulation(params: Protocol.SetDeviceEmulationParams): Promise<Protocol.BrowserActionResponse<'set_device_emulation'>>;
|
|
45
|
+
export declare function setTimezone(params: Protocol.SetTimezoneParams): Promise<Protocol.BrowserActionResponse<'set_timezone'>>;
|
|
46
|
+
export declare function getCookie(params: Protocol.GetCookieParams): Promise<Protocol.BrowserActionResponse<'get_cookie'>>;
|
|
47
|
+
export declare function setCookie(params: Protocol.SetCookieParams): Promise<Protocol.BrowserActionResponse<'set_cookie'>>;
|
|
48
|
+
export declare function getUserInfo(params?: Protocol.GetUserInfoParams): Promise<Protocol.BrowserActionResponse<'get_user_info'>>;
|
|
49
|
+
export declare function runActions(params: Protocol.RunActionsParams): Promise<Protocol.BrowserActionResponse<'run_actions'>>;
|
package/dist/index.js
CHANGED
|
@@ -3,19 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 通过 Unix Domain Socket 与 Chrome Extension 的 native host 通信,
|
|
5
5
|
* 提供类型安全的具名方法和通用的 invoke 底层方法。
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* import * as client from '@mearl/client';
|
|
10
|
-
*
|
|
11
|
-
* // 具名方法(类型安全)
|
|
12
|
-
* const result = await client.sendRequest({ url: 'https://...', method: 'GET', withCookies: true });
|
|
13
|
-
*
|
|
14
|
-
* // 底层通用方法(灵活扩展)
|
|
15
|
-
* const data = await client.invoke('send_request', { url: '...' });
|
|
16
|
-
* ```
|
|
17
6
|
*/
|
|
18
7
|
export { invoke } from './socket.js';
|
|
8
|
+
export { BROWSER_ACTIONS, BROWSER_COMMAND_ACTIONS, EXTENSION_BROWSER_ACTIONS, PAGE_ACT_ACTIONS, isBrowserAction, isBrowserCommandAction, isExtensionBrowserAction, } from './generated-browser-action-protocol.js';
|
|
19
9
|
import { invoke } from './socket.js';
|
|
20
10
|
export function getRequests(params = {}) {
|
|
21
11
|
return invoke('get_requests', params);
|
|
@@ -50,6 +40,9 @@ export function browserList() {
|
|
|
50
40
|
export function selectBrowser(params = {}) {
|
|
51
41
|
return invoke('browser_select_browser', params);
|
|
52
42
|
}
|
|
43
|
+
export function browserRelease() {
|
|
44
|
+
return invoke('browser_release', {});
|
|
45
|
+
}
|
|
53
46
|
export function browserLaunch(params) {
|
|
54
47
|
return invoke('browser_launch', params);
|
|
55
48
|
}
|
|
@@ -59,7 +52,6 @@ export function browserClose(params) {
|
|
|
59
52
|
export function setRule(params) {
|
|
60
53
|
return invoke('set_rule', params);
|
|
61
54
|
}
|
|
62
|
-
/** 返回当前存储的全部请求规则(含 Options 面板配置的),字段结构与 set_rule 入参对齐。 */
|
|
63
55
|
export function getRules() {
|
|
64
56
|
return invoke('get_rules', {});
|
|
65
57
|
}
|
|
@@ -117,6 +109,12 @@ export function setDeviceEmulation(params) {
|
|
|
117
109
|
export function setTimezone(params) {
|
|
118
110
|
return invoke('set_timezone', params);
|
|
119
111
|
}
|
|
112
|
+
export function getCookie(params) {
|
|
113
|
+
return invoke('get_cookie', params);
|
|
114
|
+
}
|
|
115
|
+
export function setCookie(params) {
|
|
116
|
+
return invoke('set_cookie', params);
|
|
117
|
+
}
|
|
120
118
|
export function getUserInfo(params = {}) {
|
|
121
119
|
return invoke('get_user_info', params);
|
|
122
120
|
}
|
package/dist/socket.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface InvokeOptions {
|
|
|
20
20
|
transport?: 'cdp';
|
|
21
21
|
/** Target a specific browser by id / name (see the browser registry). */
|
|
22
22
|
browser?: string;
|
|
23
|
+
/** Identifies whether browser control originated locally or through the cloud connector. */
|
|
24
|
+
controlSource?: 'local' | 'cloud';
|
|
23
25
|
}
|
|
24
26
|
/** Pin the default target browser for subsequent invokes (undefined clears it). */
|
|
25
27
|
export declare function setDefaultBrowser(selector: string | undefined): void;
|