@mearl/client 3.0.12 → 3.1.1
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.en.md +40 -30
- package/README.md +39 -29
- package/dist/actionTimeouts.js +9 -7
- package/dist/browserRegistry.d.ts +1 -1
- package/dist/browserRegistry.js +3 -1
- package/dist/capabilityHelp.js +21 -12
- package/dist/check.d.ts +0 -1
- package/dist/check.js +7 -22
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +16 -22
- package/dist/commandHelp.js +5 -8
- package/dist/commands.d.ts +88 -62
- package/dist/commands.js +87 -73
- package/dist/guides/api-browser-setup.md +23 -19
- package/dist/guides/api-page-automation.md +3 -1
- package/dist/guides/api-page-environment.md +5 -5
- package/dist/guides/api-request-debugging.md +1 -1
- package/dist/guides/browser-tool-cooperation.md +2 -2
- package/dist/guides/core.md +5 -5
- package/dist/guides/related-skills.md +16 -4
- package/dist/guides/troubleshooting.md +2 -2
- package/dist/index.d.ts +5 -6
- package/dist/index.js +9 -11
- package/dist/plugins/runtime/pluginDiagnostics.js +0 -1
- package/dist/plugins/runtime/pluginTaskManager.js +2 -5
- package/dist/script.js +22 -9
- package/dist/scriptCli.js +3 -5
- package/dist/sdkMethods.js +6 -1
- package/dist/socket.d.ts +0 -2
- package/dist/socket.js +159 -146
- package/dist/unified.d.ts +2 -3
- package/dist/unified.js +171 -84
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { UnifiedClient, UnifiedClient as MearlClient, decodeBrowserTarget, invok
|
|
|
13
13
|
export type { UnifiedClientOptions, UnifiedInvokeOptions, UnifiedInvokeOptions as InvokeOptions, } from './unified.js';
|
|
14
14
|
export type { PluginInvocation, PluginInvokeOptions, PluginProgress, StructuredPluginProgress, } from './plugins/sdk/plugin.js';
|
|
15
15
|
export { APP_PROFILE_NAMES, BROWSER_DEVICE_PRESET_NAMES, BROWSER_ACTIONS, BROWSER_CAPABILITY_ACTIONS, BROWSER_COMMAND_ACTIONS, EXTENSION_BROWSER_ACTIONS, PAGE_ACT_ACTIONS, SEND_REQUEST_MAX_FILES, SEND_REQUEST_MAX_TOTAL_BASE64_FILE_BYTES, SEND_REQUEST_MAX_TOTAL_FILE_BYTES, isBrowserAction, isBrowserCapabilityAction, isBrowserCommandAction, isExtensionBrowserAction, } from '@mearl/browser-core';
|
|
16
|
-
export type { ActionStep, AppProfileName, BrowserAction, BrowserActionMap, BrowserActionRequest, BrowserActionResponse, BrowserCapabilities, BrowserCapabilityAction, BrowserCloseParams, BrowserCommandAction, BrowserInfo, BrowserInfoBase, BrowserJsonValue, BrowserLaunchParams, BrowserProviderOperation, BrowserListResult, BrowserListParams, BrowserPairingInfo, BrowserReleaseFailure, BrowserReleaseResult, BrowserProviderDefinition, BrowserProviderIdentity, BrowserProviderInputSchema, BrowserProviderListResult, BrowserReference, BrowserDetails, BrowserSource, BrowserStatus, BrowserScreenshotKind, BrowserTransport, CaptureCheckpointParams, CaptureCheckpointResult, BrowserDevicePresetName, BrowserEmulationOptions, ExtensionBrowserAction, GetCookieParams, GetCookieResult, GetEventsParams, GetLogsParams, GetMocksParams, GetRequestsParams, ManagedBrowserInfo, PageClickParams, PageDragEndpoint, PageDragParams, PageDragPoint, PageActAction, PageDiagnosticsOptions, PageDiagnosticsSetting, PageEvalParams, PageFramesParams, PageHoverParams, PageInspectFilter, PageInspectParams, PageNavigateParams, PageObservationWaitOptions, PagePressParams, PageScreenshotParams, PageScrollParams, PageSnapshotParams, PageSnapshotQuery, PageTypeParams, PageUploadParams, PageWaitParams, RegularBrowserInfo, RequestPermissionParams, RulesResult, RunActionName, RunActionsParams, SelectBrowserParams, SelectBrowserResult, SendRequestFile, SendRequestBinaryBody, SendRequestFormValue, SendRequestParams, SetAppProfileParams, SetCookieParams, SetCookieResult, SetDeviceEmulationParams, SetMockParams, SetRuleParams, SetTimezoneParams, SetTimezoneResult, TabCloseParams, TabOpenParams, } from '@mearl/browser-core';
|
|
16
|
+
export type { ActionStep, AppProfileName, BrowserAction, BrowserActionMap, BrowserActionRequest, BrowserActionResponse, BrowserCapabilities, BrowserCapabilityAction, BrowserCloseParams, BrowserCommandAction, BrowserInfo, BrowserInfoBase, BrowserJsonValue, BrowserLaunchParams, BrowserManageParams, ControlSessionInfo, SessionManageParams, BrowserProviderOperation, BrowserListResult, BrowserListParams, BrowserPairingInfo, BrowserReleaseFailure, BrowserReleaseResult, BrowserProviderDefinition, BrowserProviderIdentity, BrowserProviderInputSchema, BrowserProviderListResult, BrowserReference, BrowserDetails, BrowserSource, BrowserStatus, BrowserScreenshotKind, BrowserTransport, CaptureCheckpointParams, CaptureCheckpointResult, BrowserDevicePresetName, BrowserEmulationOptions, ExtensionBrowserAction, GetCookieParams, GetCookieResult, GetEventsParams, GetLogsParams, GetMocksParams, GetRequestsParams, ManagedBrowserInfo, PageClickParams, PageDragEndpoint, PageDragParams, PageDragPoint, PageActAction, PageDiagnosticsOptions, PageDiagnosticsSetting, PageEvalParams, PageFramesParams, PageHoverParams, PageInspectFilter, PageInspectParams, PageNavigateParams, PageObservationWaitOptions, PagePressParams, PageScreenshotParams, PageScrollParams, PageSnapshotParams, PageSnapshotQuery, PageTypeParams, PageUploadParams, PageWaitParams, RegularBrowserInfo, RequestPermissionParams, RulesResult, RunActionName, RunActionsParams, SelectBrowserParams, SelectBrowserResult, SendRequestFile, SendRequestBinaryBody, SendRequestFormValue, SendRequestParams, SetAppProfileParams, SetCookieParams, SetCookieResult, SetDeviceEmulationParams, SetMockParams, SetRuleParams, SetTimezoneParams, SetTimezoneResult, TabCloseParams, TabOpenParams, } from '@mearl/browser-core';
|
|
17
17
|
import { type UnifiedInvokeOptions } from './unified.js';
|
|
18
18
|
import type * as Protocol from '@mearl/browser-core';
|
|
19
19
|
export declare function tabCheckpoint(params: Protocol.CaptureCheckpointParams, options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'tab_checkpoint'>>;
|
|
@@ -28,10 +28,9 @@ export declare function sendRequest(params: Protocol.SendRequestParams, options?
|
|
|
28
28
|
export declare function browserList(options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'browser_list'>>;
|
|
29
29
|
export declare function browserList(params: Protocol.BrowserListParams, options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'browser_list'>>;
|
|
30
30
|
export declare function selectBrowser(params?: Protocol.SelectBrowserParams, options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'browser_select_browser'>>;
|
|
31
|
-
export declare function
|
|
32
|
-
export declare function
|
|
33
|
-
export declare function
|
|
34
|
-
export declare function browserClose(params: Protocol.BrowserCloseParams, options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'browser_close'>>;
|
|
31
|
+
export declare function browserManage(params: Protocol.BrowserManageParams, options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'browser_manage'>>;
|
|
32
|
+
export declare function sessionList(options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'session_list'>>;
|
|
33
|
+
export declare function sessionManage(params: Protocol.SessionManageParams, options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'session_manage'>>;
|
|
35
34
|
export declare function setRule(params: Protocol.SetRuleParams, options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'set_rule'>>;
|
|
36
35
|
export declare function getRules(options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'get_rules'>>;
|
|
37
36
|
export declare function pageScreenshot(params: Protocol.PageScreenshotParams, options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'page_screenshot'>>;
|
|
@@ -60,8 +59,8 @@ export declare function setTimezone(params: Protocol.SetTimezoneParams, options?
|
|
|
60
59
|
export declare function getCookie(params: Protocol.GetCookieParams, options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'get_cookie'>>;
|
|
61
60
|
export declare function setCookie(params: Protocol.SetCookieParams, options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'set_cookie'>>;
|
|
62
61
|
export declare function runActions(params: Protocol.RunActionsParams, options?: UnifiedInvokeOptions): Promise<Protocol.BrowserActionResponse<'run_actions'>>;
|
|
63
|
-
export declare function browserControl(params: Protocol.BrowserControlParams, options?: UnifiedInvokeOptions): Promise<any>;
|
|
64
62
|
export declare function pageDownload(params: Protocol.PageDownloadParams, options?: UnifiedInvokeOptions): Promise<any>;
|
|
63
|
+
export declare function pageRecord(params: Protocol.PageRecordParams, options?: UnifiedInvokeOptions): Promise<any>;
|
|
65
64
|
export declare function saveArtifact(artifact: Protocol.BrowserArtifact & {
|
|
66
65
|
browserId?: string;
|
|
67
66
|
}, outputPath: string, options?: UnifiedInvokeOptions): Promise<{
|
package/dist/index.js
CHANGED
|
@@ -44,16 +44,14 @@ export function browserList(paramsOrOptions = {}, options) {
|
|
|
44
44
|
export function selectBrowser(params = {}, options) {
|
|
45
45
|
return invoke('browser_select_browser', params, options);
|
|
46
46
|
}
|
|
47
|
-
export function
|
|
48
|
-
return options
|
|
49
|
-
? invoke('browser_release', paramsOrOptions, options)
|
|
50
|
-
: invoke('browser_release', {}, paramsOrOptions);
|
|
47
|
+
export function browserManage(params, options) {
|
|
48
|
+
return invoke('browser_manage', params, options);
|
|
51
49
|
}
|
|
52
|
-
export function
|
|
53
|
-
return invoke('
|
|
50
|
+
export function sessionList(options) {
|
|
51
|
+
return invoke('session_list', {}, options);
|
|
54
52
|
}
|
|
55
|
-
export function
|
|
56
|
-
return invoke('
|
|
53
|
+
export function sessionManage(params, options) {
|
|
54
|
+
return invoke('session_manage', params, options);
|
|
57
55
|
}
|
|
58
56
|
export function setRule(params, options) {
|
|
59
57
|
return invoke('set_rule', params, options);
|
|
@@ -139,12 +137,12 @@ export function setCookie(params, options) {
|
|
|
139
137
|
export function runActions(params, options) {
|
|
140
138
|
return invoke('run_actions', params, options);
|
|
141
139
|
}
|
|
142
|
-
export function browserControl(params, options) {
|
|
143
|
-
return invoke('browser_control', params, options);
|
|
144
|
-
}
|
|
145
140
|
export function pageDownload(params, options) {
|
|
146
141
|
return invoke('page_download', params, options);
|
|
147
142
|
}
|
|
143
|
+
export function pageRecord(params, options) {
|
|
144
|
+
return invoke('page_record', params, options);
|
|
145
|
+
}
|
|
148
146
|
export async function saveArtifact(artifact, outputPath, options = {}) {
|
|
149
147
|
const { exportArtifact } = await import('./artifacts.js');
|
|
150
148
|
return exportArtifact({ invoke }, artifact, outputPath, options);
|
|
@@ -168,7 +168,6 @@ function taskProjection(record, options, observedAt) {
|
|
|
168
168
|
...(routing.session ? { session: text(routing.session) } : {}),
|
|
169
169
|
...(routing.connector ? { connector: text(routing.connector) } : {}),
|
|
170
170
|
...(routing.local !== undefined ? { local: routing.local } : {}),
|
|
171
|
-
...(routing.transport ? { transport: routing.transport } : {}),
|
|
172
171
|
},
|
|
173
172
|
}
|
|
174
173
|
: {}),
|
|
@@ -240,9 +240,6 @@ export class PluginTaskManager {
|
|
|
240
240
|
throw new Error('Invalid plugin task invocation timeout');
|
|
241
241
|
if (request.options.local !== undefined && typeof request.options.local !== 'boolean')
|
|
242
242
|
throw new Error('Invalid plugin task local routing option');
|
|
243
|
-
if (request.options.transport !== undefined &&
|
|
244
|
-
!['extension', 'cdp'].includes(request.options.transport))
|
|
245
|
-
throw new Error('Invalid plugin task transport');
|
|
246
243
|
if (bridge.scope.bridge === 'service' &&
|
|
247
244
|
request.options.browser &&
|
|
248
245
|
!decodeBrowserTarget(request.options.browser))
|
|
@@ -978,9 +975,9 @@ export class PluginTaskManager {
|
|
|
978
975
|
}
|
|
979
976
|
}
|
|
980
977
|
assertRouting(options, bound) {
|
|
981
|
-
if (Object.keys(options).some(key => !['browser', 'connector', 'session', 'local', '
|
|
978
|
+
if (Object.keys(options).some(key => !['browser', 'connector', 'session', 'local', 'timeoutSec'].includes(key)))
|
|
982
979
|
throw error('PLUGIN_TASK_TARGET_CHANGED', 'Plugin task cannot override internal routing options');
|
|
983
|
-
for (const key of ['browser', 'connector', 'session', 'local'
|
|
980
|
+
for (const key of ['browser', 'connector', 'session', 'local'])
|
|
984
981
|
if (options[key] !== undefined && options[key] !== bound[key])
|
|
985
982
|
throw error('PLUGIN_TASK_TARGET_CHANGED', 'Plugin task cannot change its bound browser routing');
|
|
986
983
|
}
|
package/dist/script.js
CHANGED
|
@@ -37,18 +37,24 @@ export async function executeScript(code, options = {}) {
|
|
|
37
37
|
const controller = new AbortController();
|
|
38
38
|
const invoke = async (action, payload, overrides = {}) => {
|
|
39
39
|
controller.signal.throwIfAborted();
|
|
40
|
+
const managesSession = action === 'session_manage';
|
|
41
|
+
const sessionOverride = managesSession ? payload.sessionId : undefined;
|
|
42
|
+
const inheritsSession = action !== 'browser_manage' &&
|
|
43
|
+
action !== 'session_list' &&
|
|
44
|
+
!(managesSession && (payload.operation === 'new' || sessionOverride));
|
|
40
45
|
const result = await client.invoke(action, payload, {
|
|
41
46
|
...defaults,
|
|
42
|
-
session: sessionId,
|
|
47
|
+
session: inheritsSession ? sessionId : undefined,
|
|
43
48
|
...overrides,
|
|
44
49
|
});
|
|
45
50
|
if (result?.action?.stage === 'dispatch-uncertain' || result?.stage === 'dispatch-uncertain')
|
|
46
51
|
uncertainEffects = true;
|
|
47
52
|
if (result?.session?.sessionId &&
|
|
48
|
-
(!overrides.session || overrides.session === 'new' || overrides.session === sessionId)
|
|
53
|
+
(!overrides.session || overrides.session === 'new' || overrides.session === sessionId) &&
|
|
54
|
+
(!sessionOverride || !sessionId || sessionOverride === sessionId)) {
|
|
49
55
|
session = result.session;
|
|
50
56
|
if (!overrides.session || overrides.session === 'new')
|
|
51
|
-
sessionId = result.session.sessionId;
|
|
57
|
+
sessionId = result.session.status === 'released' ? undefined : result.session.sessionId;
|
|
52
58
|
}
|
|
53
59
|
return result;
|
|
54
60
|
};
|
|
@@ -95,7 +101,14 @@ export async function executeScript(code, options = {}) {
|
|
|
95
101
|
}
|
|
96
102
|
};
|
|
97
103
|
const abort = () => stop({ code: 'SCRIPT_CANCELLED', message: 'Script execution cancelled' });
|
|
98
|
-
const
|
|
104
|
+
const timeOut = () => stop({ code: 'SCRIPT_TIMEOUT', message: 'Script execution deadline exceeded' });
|
|
105
|
+
const pastDeadline = () => {
|
|
106
|
+
if (Date.now() < executionDeadline)
|
|
107
|
+
return false;
|
|
108
|
+
timeOut();
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
const deadline = setTimeout(timeOut, Math.max(0, executionDeadline - Date.now()));
|
|
99
112
|
signal?.addEventListener('abort', abort, { once: true });
|
|
100
113
|
if (signal?.aborted)
|
|
101
114
|
abort();
|
|
@@ -138,7 +151,8 @@ export async function executeScript(code, options = {}) {
|
|
|
138
151
|
}
|
|
139
152
|
};
|
|
140
153
|
const send = (message) => {
|
|
141
|
-
|
|
154
|
+
// A transport timer can settle a pending call before the script timer gets its turn.
|
|
155
|
+
if (outcome !== undefined || !child.connected || pastDeadline())
|
|
142
156
|
return;
|
|
143
157
|
child.send(message, error => {
|
|
144
158
|
if (error)
|
|
@@ -146,7 +160,7 @@ export async function executeScript(code, options = {}) {
|
|
|
146
160
|
});
|
|
147
161
|
};
|
|
148
162
|
child.on('message', (message) => {
|
|
149
|
-
if (outcome !== undefined || !message || typeof message !== 'object')
|
|
163
|
+
if (outcome !== undefined || !message || typeof message !== 'object' || pastDeadline())
|
|
150
164
|
return;
|
|
151
165
|
if (message.type === 'done' || message.type === 'error') {
|
|
152
166
|
stop(message.type === 'error'
|
|
@@ -210,11 +224,10 @@ export async function executeScript(code, options = {}) {
|
|
|
210
224
|
session: sessionId,
|
|
211
225
|
...args[2],
|
|
212
226
|
});
|
|
213
|
-
const optionsOnly =
|
|
227
|
+
const optionsOnly = OPTIONS_ONLY.has(method) &&
|
|
214
228
|
!(method === 'browserList' &&
|
|
215
229
|
args[0] &&
|
|
216
|
-
('provider' in args[0] || 'launchForm' in args[0]))
|
|
217
|
-
(method === 'browserRelease' && args.length < 2);
|
|
230
|
+
('provider' in args[0] || 'launchForm' in args[0]));
|
|
218
231
|
return invoke(METHOD_ACTIONS.get(method), optionsOnly ? {} : (args[0] ?? {}), optionsOnly ? args[0] : args[1]);
|
|
219
232
|
})
|
|
220
233
|
.then(result => send({ type: 'response', id, result, session }), error => send({ type: 'response', id, error: serializeError(error), session }))
|
package/dist/scriptCli.js
CHANGED
|
@@ -11,7 +11,6 @@ export async function runScriptCli(args, commandName) {
|
|
|
11
11
|
.option('--browser <id-or-name>', '指定浏览器')
|
|
12
12
|
.option('--connector <id-or-name>', '限制到远端 connector')
|
|
13
13
|
.option('--local', '仅使用本机浏览器')
|
|
14
|
-
.option('--cdp', '强制本机 CDP')
|
|
15
14
|
.option('--server <url>', '覆盖 cloud-server 地址')
|
|
16
15
|
.option('--timeout <seconds>', '整个脚本的执行时限(默认 60 秒)', '60')
|
|
17
16
|
.allowExcessArguments(false)
|
|
@@ -25,8 +24,8 @@ export async function runScriptCli(args, commandName) {
|
|
|
25
24
|
const timeout = Number(options.timeout);
|
|
26
25
|
if (!Number.isFinite(timeout) || timeout <= 0 || timeout * 1000 > 2_147_483_647)
|
|
27
26
|
throw new Error('--timeout 必须是有效范围内的大于 0 的秒数');
|
|
28
|
-
if (
|
|
29
|
-
throw new Error('--local
|
|
27
|
+
if (options.local && options.connector)
|
|
28
|
+
throw new Error('--local 不能与 --connector 同时使用');
|
|
30
29
|
if (options.file)
|
|
31
30
|
source = await readFile(resolve(options.file), 'utf8');
|
|
32
31
|
else {
|
|
@@ -64,8 +63,7 @@ export async function runScriptCli(args, commandName) {
|
|
|
64
63
|
...(options.session ? { session: options.session } : {}),
|
|
65
64
|
...(options.browser ? { browser: options.browser } : {}),
|
|
66
65
|
...(options.connector ? { connector: options.connector } : {}),
|
|
67
|
-
...(options.local
|
|
68
|
-
...(options.cdp ? { transport: 'cdp' } : {}),
|
|
66
|
+
...(options.local ? { local: true } : {}),
|
|
69
67
|
...(options.server ? { serverUrl: options.server } : {}),
|
|
70
68
|
});
|
|
71
69
|
if (result.stdout)
|
package/dist/sdkMethods.js
CHANGED
|
@@ -6,4 +6,9 @@ export const SDK_METHOD_ACTIONS = new Map(Object.keys(BROWSER_COMMAND_ACTIONS).m
|
|
|
6
6
|
]));
|
|
7
7
|
SDK_METHOD_ACTIONS.set('selectBrowser', 'browser_select_browser');
|
|
8
8
|
SDK_METHOD_ACTIONS.set('captureCheckpoint', 'tab_checkpoint');
|
|
9
|
-
export const SDK_OPTIONS_ONLY_METHODS = new Set([
|
|
9
|
+
export const SDK_OPTIONS_ONLY_METHODS = new Set([
|
|
10
|
+
'browserList',
|
|
11
|
+
'sessionList',
|
|
12
|
+
'tabList',
|
|
13
|
+
'getRules',
|
|
14
|
+
]);
|
package/dist/socket.d.ts
CHANGED
|
@@ -25,8 +25,6 @@ export interface InvokeOptions {
|
|
|
25
25
|
timeoutSec?: number;
|
|
26
26
|
/** Absolute cutoff for sending this request, including any routing retries. */
|
|
27
27
|
deadline?: number;
|
|
28
|
-
/** Force CDP transport instead of extension */
|
|
29
|
-
transport?: 'cdp';
|
|
30
28
|
/** Target a specific browser by id / name (see the browser registry). */
|
|
31
29
|
browser?: string;
|
|
32
30
|
/** Identifies whether browser control originated on this machine or through a remote connector. */
|