@mearl/browser-core 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/dist/browserActionProtocol.d.ts +112 -27
- package/dist/browserActionProtocol.js +10 -9
- package/dist/browserManagement.d.ts +4 -0
- package/dist/browserManagement.js +100 -0
- package/dist/cdpRecording.d.ts +11 -0
- package/dist/cdpRecording.js +41 -0
- package/dist/domClicking.js +36 -0
- package/dist/extensionAgentAccess.js +2 -0
- package/dist/extensionServiceProtocol.d.ts +70 -5
- package/dist/extensionServiceProtocol.js +10 -5
- package/dist/headerRules.d.ts +47 -0
- package/dist/headerRules.js +109 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/proxyPermissions.js +4 -1
- package/dist/runActions.js +1 -1
- package/package.json +1 -1
|
@@ -189,7 +189,7 @@ export interface BrowserInfoBase {
|
|
|
189
189
|
export type BrowserScreenshotKind = 'native' | 'reconstructed' | 'none';
|
|
190
190
|
export type BrowserControlSessionMode = 'mearl' | 'external';
|
|
191
191
|
/** Browser-targeted actions that an external provider may implement. */
|
|
192
|
-
export type BrowserCapabilityAction = ExtensionBrowserAction | 'page_download';
|
|
192
|
+
export type BrowserCapabilityAction = ExtensionBrowserAction | 'page_download' | 'browser_release';
|
|
193
193
|
/** Capabilities advertised by an external browser-control provider. */
|
|
194
194
|
export interface BrowserCapabilities {
|
|
195
195
|
actions: BrowserCapabilityAction[];
|
|
@@ -197,6 +197,8 @@ export interface BrowserCapabilities {
|
|
|
197
197
|
screenshot: BrowserScreenshotKind;
|
|
198
198
|
/** Fixed per instance. Omitted means Mearl sessions; external delegates task control. */
|
|
199
199
|
controlSessionMode?: BrowserControlSessionMode;
|
|
200
|
+
/** Provider returns dialog receipts from page_snapshot and accepts page_press dialogId. */
|
|
201
|
+
nativeDialogs?: true;
|
|
200
202
|
}
|
|
201
203
|
export interface RegularBrowserInfo extends BrowserInfoBase {
|
|
202
204
|
type: 'regular';
|
|
@@ -294,6 +296,52 @@ export interface BrowserArtifact {
|
|
|
294
296
|
/** Global browser route is attached by the unified client. */
|
|
295
297
|
browserId?: string;
|
|
296
298
|
}
|
|
299
|
+
export interface PageRecordingOptions {
|
|
300
|
+
maxWidth?: number;
|
|
301
|
+
maxHeight?: number;
|
|
302
|
+
frameRate?: number;
|
|
303
|
+
audio?: boolean;
|
|
304
|
+
}
|
|
305
|
+
export type PageRecordParams = ({
|
|
306
|
+
operation: 'start';
|
|
307
|
+
tabId: number;
|
|
308
|
+
} & PageRecordingOptions) | {
|
|
309
|
+
operation: 'stop' | 'status';
|
|
310
|
+
recordingId: string;
|
|
311
|
+
};
|
|
312
|
+
export type PageRecordingStopReason = 'requested' | 'duration_limit';
|
|
313
|
+
export type PageRecordingStatus = {
|
|
314
|
+
state: 'recording';
|
|
315
|
+
} | {
|
|
316
|
+
state: 'finalizing';
|
|
317
|
+
stopReason: PageRecordingStopReason;
|
|
318
|
+
} | {
|
|
319
|
+
state: 'ready';
|
|
320
|
+
stopReason: PageRecordingStopReason;
|
|
321
|
+
recording: BrowserArtifact;
|
|
322
|
+
} | {
|
|
323
|
+
state: 'interrupted';
|
|
324
|
+
error: string;
|
|
325
|
+
};
|
|
326
|
+
export type PageRecordResult = {
|
|
327
|
+
operation: 'start';
|
|
328
|
+
tabId: number;
|
|
329
|
+
browserId: string;
|
|
330
|
+
recordingId: string;
|
|
331
|
+
maxDurationMs: number;
|
|
332
|
+
} | {
|
|
333
|
+
operation: 'stop';
|
|
334
|
+
tabId: number;
|
|
335
|
+
recordingId: string;
|
|
336
|
+
recording: BrowserArtifact;
|
|
337
|
+
} | ({
|
|
338
|
+
operation: 'status';
|
|
339
|
+
tabId: number;
|
|
340
|
+
browserId: string;
|
|
341
|
+
recordingId: string;
|
|
342
|
+
startedAt: number;
|
|
343
|
+
autoStopAt: number;
|
|
344
|
+
} & PageRecordingStatus);
|
|
297
345
|
export interface PageDownloadParams {
|
|
298
346
|
tabId: number;
|
|
299
347
|
trigger: Omit<PageClickParams, 'tabId'>;
|
|
@@ -332,6 +380,33 @@ export interface BrowserCloseParams {
|
|
|
332
380
|
browser: string;
|
|
333
381
|
deleteProfile?: boolean;
|
|
334
382
|
}
|
|
383
|
+
export type BrowserManageParams = ({
|
|
384
|
+
operation: 'launch';
|
|
385
|
+
} & BrowserLaunchParams) | {
|
|
386
|
+
operation: 'attach';
|
|
387
|
+
provider: string;
|
|
388
|
+
providerOptions?: Record<string, BrowserJsonValue>;
|
|
389
|
+
} | {
|
|
390
|
+
operation: 'close';
|
|
391
|
+
deleteProfile?: boolean;
|
|
392
|
+
} | {
|
|
393
|
+
operation: 'detach';
|
|
394
|
+
} | {
|
|
395
|
+
operation: 'release';
|
|
396
|
+
};
|
|
397
|
+
export type SessionManageParams = {
|
|
398
|
+
operation: 'new';
|
|
399
|
+
} | {
|
|
400
|
+
operation: 'handoff';
|
|
401
|
+
sessionId?: string;
|
|
402
|
+
reason?: string;
|
|
403
|
+
} | {
|
|
404
|
+
operation: 'resume';
|
|
405
|
+
sessionId?: string;
|
|
406
|
+
} | ({
|
|
407
|
+
operation: 'end';
|
|
408
|
+
sessionId?: string;
|
|
409
|
+
} & BrowserReleaseParams);
|
|
335
410
|
interface BrowserProviderSchemaBase extends BrowserProviderLocales<'title' | 'description' | 'placeholder'> {
|
|
336
411
|
title?: string;
|
|
337
412
|
description?: string;
|
|
@@ -393,6 +468,8 @@ export interface BrowserProviderDefinition {
|
|
|
393
468
|
provider: BrowserProviderIdentity;
|
|
394
469
|
browserType: BrowserProviderLocales<'name'> & {
|
|
395
470
|
name: string;
|
|
471
|
+
/** Operation exposed for the Provider's instance entry point. Defaults to launch. */
|
|
472
|
+
openOperation?: 'launch' | 'attach';
|
|
396
473
|
controlSessionModes?: readonly BrowserControlSessionMode[];
|
|
397
474
|
documentationUrl?: string;
|
|
398
475
|
inputSchema: BrowserProviderObjectSchema;
|
|
@@ -792,7 +869,7 @@ export interface SetCookieResult {
|
|
|
792
869
|
export interface RequestPermissionParams {
|
|
793
870
|
domain: string;
|
|
794
871
|
}
|
|
795
|
-
export type RunActionName = Exclude<ExtensionBrowserAction, 'run_actions' | '
|
|
872
|
+
export type RunActionName = Exclude<ExtensionBrowserAction, 'run_actions' | 'get_capabilities'>;
|
|
796
873
|
export interface ActionStep {
|
|
797
874
|
action: RunActionName;
|
|
798
875
|
data?: Record<string, unknown>;
|
|
@@ -855,27 +932,36 @@ export interface BrowserActionMap {
|
|
|
855
932
|
request: SelectBrowserParams;
|
|
856
933
|
response: SelectBrowserResult;
|
|
857
934
|
};
|
|
858
|
-
|
|
859
|
-
request:
|
|
860
|
-
response: BrowserReleaseResult
|
|
935
|
+
browser_manage: {
|
|
936
|
+
request: BrowserManageParams;
|
|
937
|
+
response: ManagedBrowserInfo | BrowserReleaseResult | {
|
|
938
|
+
closed: boolean;
|
|
939
|
+
} | {
|
|
940
|
+
detached: boolean;
|
|
941
|
+
};
|
|
942
|
+
};
|
|
943
|
+
session_list: {
|
|
944
|
+
request: undefined;
|
|
945
|
+
response: {
|
|
946
|
+
sessions: ControlSessionInfo[];
|
|
947
|
+
warnings?: string[];
|
|
948
|
+
};
|
|
861
949
|
};
|
|
862
|
-
|
|
863
|
-
request:
|
|
950
|
+
session_manage: {
|
|
951
|
+
request: SessionManageParams;
|
|
864
952
|
response: {
|
|
865
953
|
session: ControlSessionInfo;
|
|
866
|
-
} | ExternalBrowserControlResult
|
|
954
|
+
} | (Omit<ExternalBrowserControlResult, 'operation'> & {
|
|
955
|
+
operation: 'handoff' | 'resume' | 'end';
|
|
956
|
+
});
|
|
867
957
|
};
|
|
868
958
|
page_download: {
|
|
869
959
|
request: PageDownloadParams;
|
|
870
960
|
response: PageDownloadResult;
|
|
871
961
|
};
|
|
872
|
-
|
|
873
|
-
request:
|
|
874
|
-
response:
|
|
875
|
-
};
|
|
876
|
-
browser_close: {
|
|
877
|
-
request: BrowserCloseParams;
|
|
878
|
-
response: unknown;
|
|
962
|
+
page_record: {
|
|
963
|
+
request: PageRecordParams;
|
|
964
|
+
response: PageRecordResult;
|
|
879
965
|
};
|
|
880
966
|
page_screenshot: {
|
|
881
967
|
request: PageScreenshotParams;
|
|
@@ -991,11 +1077,11 @@ export interface BrowserActionMap {
|
|
|
991
1077
|
export type BrowserAction = keyof BrowserActionMap;
|
|
992
1078
|
export type BrowserActionRequest<A extends BrowserAction> = BrowserActionMap[A]['request'];
|
|
993
1079
|
export type BrowserActionResponse<A extends BrowserAction> = BrowserActionMap[A]['response'] & {
|
|
994
|
-
/** Routing and execution state;
|
|
1080
|
+
/** Routing and execution state; session_manage returns the full tab inventory. */
|
|
995
1081
|
session?: Omit<ControlSessionInfo, 'tabs'>;
|
|
996
1082
|
};
|
|
997
1083
|
export type BrowserCommandAction = Exclude<BrowserAction, 'browser_select_browser'>;
|
|
998
|
-
export type ExtensionBrowserAction = Exclude<BrowserCommandAction, 'browser_list' | '
|
|
1084
|
+
export type ExtensionBrowserAction = Exclude<BrowserCommandAction, 'browser_list' | 'browser_manage' | 'session_list' | 'session_manage' | 'page_download' | 'page_record'>;
|
|
999
1085
|
export declare const TAB_ID_REQUIRED_ACTIONS: readonly ["tab_checkpoint", "capture_checkpoint", "get_requests", "get_logs", "get_events", "set_mock", "get_mocks", "page_screenshot", "tab_close", "page_click", "page_drag", "page_type", "page_scroll", "page_hover", "page_eval", "page_call_tool", "page_inspect", "page_snapshot", "page_press", "page_wait", "page_navigate", "page_upload", "page_download", "page_frames", "set_device_emulation", "set_app_profile", "set_timezone", "run_actions"];
|
|
1000
1086
|
export type TabIdRequiredAction = (typeof TAB_ID_REQUIRED_ACTIONS)[number];
|
|
1001
1087
|
export declare function actionRequiresTabId(action: unknown): action is TabIdRequiredAction;
|
|
@@ -1016,11 +1102,11 @@ export declare const BROWSER_ACTIONS: {
|
|
|
1016
1102
|
readonly send_request: true;
|
|
1017
1103
|
readonly browser_list: true;
|
|
1018
1104
|
readonly browser_select_browser: true;
|
|
1019
|
-
readonly
|
|
1020
|
-
readonly
|
|
1105
|
+
readonly browser_manage: true;
|
|
1106
|
+
readonly session_list: true;
|
|
1107
|
+
readonly session_manage: true;
|
|
1021
1108
|
readonly page_download: true;
|
|
1022
|
-
readonly
|
|
1023
|
-
readonly browser_close: true;
|
|
1109
|
+
readonly page_record: true;
|
|
1024
1110
|
readonly page_screenshot: true;
|
|
1025
1111
|
readonly tab_open: true;
|
|
1026
1112
|
readonly tab_close: true;
|
|
@@ -1062,11 +1148,11 @@ export declare const BROWSER_COMMAND_ACTIONS: {
|
|
|
1062
1148
|
readonly get_capabilities: true;
|
|
1063
1149
|
readonly send_request: true;
|
|
1064
1150
|
readonly browser_list: true;
|
|
1065
|
-
readonly
|
|
1066
|
-
readonly
|
|
1151
|
+
readonly browser_manage: true;
|
|
1152
|
+
readonly session_list: true;
|
|
1153
|
+
readonly session_manage: true;
|
|
1067
1154
|
readonly page_download: true;
|
|
1068
|
-
readonly
|
|
1069
|
-
readonly browser_close: true;
|
|
1155
|
+
readonly page_record: true;
|
|
1070
1156
|
readonly page_screenshot: true;
|
|
1071
1157
|
readonly tab_open: true;
|
|
1072
1158
|
readonly tab_close: true;
|
|
@@ -1107,7 +1193,6 @@ export declare const EXTENSION_BROWSER_ACTIONS: {
|
|
|
1107
1193
|
readonly get_rules: true;
|
|
1108
1194
|
readonly get_capabilities: true;
|
|
1109
1195
|
readonly send_request: true;
|
|
1110
|
-
readonly browser_release: true;
|
|
1111
1196
|
readonly page_screenshot: true;
|
|
1112
1197
|
readonly tab_open: true;
|
|
1113
1198
|
readonly tab_close: true;
|
|
@@ -1138,6 +1223,7 @@ export declare const EXTENSION_BROWSER_ACTIONS: {
|
|
|
1138
1223
|
};
|
|
1139
1224
|
export declare const BROWSER_CAPABILITY_ACTIONS: {
|
|
1140
1225
|
readonly page_download: true;
|
|
1226
|
+
readonly browser_release: true;
|
|
1141
1227
|
readonly tab_checkpoint: true;
|
|
1142
1228
|
readonly capture_checkpoint: true;
|
|
1143
1229
|
readonly get_requests: true;
|
|
@@ -1149,7 +1235,6 @@ export declare const BROWSER_CAPABILITY_ACTIONS: {
|
|
|
1149
1235
|
readonly get_rules: true;
|
|
1150
1236
|
readonly get_capabilities: true;
|
|
1151
1237
|
readonly send_request: true;
|
|
1152
|
-
readonly browser_release: true;
|
|
1153
1238
|
readonly page_screenshot: true;
|
|
1154
1239
|
readonly tab_open: true;
|
|
1155
1240
|
readonly tab_close: true;
|
|
@@ -127,11 +127,11 @@ export const BROWSER_ACTIONS = {
|
|
|
127
127
|
send_request: true,
|
|
128
128
|
browser_list: true,
|
|
129
129
|
browser_select_browser: true,
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
browser_manage: true,
|
|
131
|
+
session_list: true,
|
|
132
|
+
session_manage: true,
|
|
132
133
|
page_download: true,
|
|
133
|
-
|
|
134
|
-
browser_close: true,
|
|
134
|
+
page_record: true,
|
|
135
135
|
page_screenshot: true,
|
|
136
136
|
tab_open: true,
|
|
137
137
|
tab_close: true,
|
|
@@ -173,11 +173,11 @@ export const BROWSER_COMMAND_ACTIONS = {
|
|
|
173
173
|
get_capabilities: true,
|
|
174
174
|
send_request: true,
|
|
175
175
|
browser_list: true,
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
browser_manage: true,
|
|
177
|
+
session_list: true,
|
|
178
|
+
session_manage: true,
|
|
178
179
|
page_download: true,
|
|
179
|
-
|
|
180
|
-
browser_close: true,
|
|
180
|
+
page_record: true,
|
|
181
181
|
page_screenshot: true,
|
|
182
182
|
tab_open: true,
|
|
183
183
|
tab_close: true,
|
|
@@ -218,7 +218,6 @@ export const EXTENSION_BROWSER_ACTIONS = {
|
|
|
218
218
|
get_rules: true,
|
|
219
219
|
get_capabilities: true,
|
|
220
220
|
send_request: true,
|
|
221
|
-
browser_release: true,
|
|
222
221
|
page_screenshot: true,
|
|
223
222
|
tab_open: true,
|
|
224
223
|
tab_close: true,
|
|
@@ -250,6 +249,8 @@ export const EXTENSION_BROWSER_ACTIONS = {
|
|
|
250
249
|
export const BROWSER_CAPABILITY_ACTIONS = {
|
|
251
250
|
...EXTENSION_BROWSER_ACTIONS,
|
|
252
251
|
page_download: true,
|
|
252
|
+
// Provider wire operation for releasing control while preserving its instance.
|
|
253
|
+
browser_release: true,
|
|
253
254
|
};
|
|
254
255
|
export function isBrowserAction(value) {
|
|
255
256
|
return typeof value === 'string' && Object.hasOwn(BROWSER_ACTIONS, value);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BrowserManageParams, SessionManageParams } from './browserActionProtocol.js';
|
|
2
|
+
export declare function parseBrowserManageParams(value: unknown): BrowserManageParams;
|
|
3
|
+
export declare function parseSessionManageParams(value: unknown): SessionManageParams;
|
|
4
|
+
export declare function resolveSessionManageId(command: SessionManageParams, transportId?: string): string | undefined;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
function record(value) {
|
|
2
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
3
|
+
throw new Error('Expected a management payload object');
|
|
4
|
+
return value;
|
|
5
|
+
}
|
|
6
|
+
function allow(data, keys) {
|
|
7
|
+
const extra = Object.keys(data).find(key => key !== 'operation' && !keys.includes(key));
|
|
8
|
+
if (extra)
|
|
9
|
+
throw new Error(`${extra} is not valid for operation "${data.operation}"`);
|
|
10
|
+
}
|
|
11
|
+
export function parseBrowserManageParams(value) {
|
|
12
|
+
const data = record(value);
|
|
13
|
+
switch (data.operation) {
|
|
14
|
+
case 'launch':
|
|
15
|
+
allow(data, [
|
|
16
|
+
'provider',
|
|
17
|
+
'providerOptions',
|
|
18
|
+
'name',
|
|
19
|
+
'headless',
|
|
20
|
+
'userAgentMode',
|
|
21
|
+
'persistent',
|
|
22
|
+
'executablePath',
|
|
23
|
+
'url',
|
|
24
|
+
'copyCookieDomains',
|
|
25
|
+
]);
|
|
26
|
+
break;
|
|
27
|
+
case 'attach':
|
|
28
|
+
allow(data, ['provider', 'providerOptions']);
|
|
29
|
+
if (typeof data.provider !== 'string' || !data.provider.trim())
|
|
30
|
+
throw new Error('operation "attach" requires a provider');
|
|
31
|
+
break;
|
|
32
|
+
case 'close':
|
|
33
|
+
allow(data, ['deleteProfile']);
|
|
34
|
+
if (data.deleteProfile !== undefined && typeof data.deleteProfile !== 'boolean')
|
|
35
|
+
throw new Error('deleteProfile must be a boolean');
|
|
36
|
+
break;
|
|
37
|
+
case 'detach':
|
|
38
|
+
case 'release':
|
|
39
|
+
allow(data, []);
|
|
40
|
+
break;
|
|
41
|
+
default:
|
|
42
|
+
throw new Error('browser_manage requires launch, attach, detach, close or release');
|
|
43
|
+
}
|
|
44
|
+
if (data.provider !== undefined && (typeof data.provider !== 'string' || !data.provider.trim()))
|
|
45
|
+
throw new Error('provider must be a nonempty string');
|
|
46
|
+
if (data.providerOptions !== undefined)
|
|
47
|
+
record(data.providerOptions);
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
export function parseSessionManageParams(value) {
|
|
51
|
+
const data = record(value);
|
|
52
|
+
switch (data.operation) {
|
|
53
|
+
case 'new':
|
|
54
|
+
allow(data, []);
|
|
55
|
+
break;
|
|
56
|
+
case 'handoff':
|
|
57
|
+
allow(data, ['sessionId', 'reason']);
|
|
58
|
+
if (data.reason !== undefined && typeof data.reason !== 'string')
|
|
59
|
+
throw new Error('reason must be a string');
|
|
60
|
+
break;
|
|
61
|
+
case 'resume':
|
|
62
|
+
allow(data, ['sessionId']);
|
|
63
|
+
break;
|
|
64
|
+
case 'end':
|
|
65
|
+
allow(data, [
|
|
66
|
+
'sessionId',
|
|
67
|
+
'closeCreatedTabs',
|
|
68
|
+
'preserveEnvironment',
|
|
69
|
+
'keepTabIds',
|
|
70
|
+
'keepArtifactIds',
|
|
71
|
+
]);
|
|
72
|
+
for (const key of ['closeCreatedTabs', 'preserveEnvironment']) {
|
|
73
|
+
if (data[key] !== undefined && typeof data[key] !== 'boolean')
|
|
74
|
+
throw new Error(`${key} must be a boolean`);
|
|
75
|
+
}
|
|
76
|
+
if (data.keepTabIds !== undefined &&
|
|
77
|
+
(!Array.isArray(data.keepTabIds) ||
|
|
78
|
+
data.keepTabIds.some(id => !Number.isSafeInteger(id) || id < 0) ||
|
|
79
|
+
new Set(data.keepTabIds).size !== data.keepTabIds.length))
|
|
80
|
+
throw new Error('keepTabIds must contain unique nonnegative integer tab IDs');
|
|
81
|
+
if (data.keepArtifactIds !== undefined &&
|
|
82
|
+
(!Array.isArray(data.keepArtifactIds) ||
|
|
83
|
+
data.keepArtifactIds.some(id => typeof id !== 'string' || !id)))
|
|
84
|
+
throw new Error('keepArtifactIds must contain nonempty strings');
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
throw new Error('session_manage requires new, handoff, resume or end');
|
|
88
|
+
}
|
|
89
|
+
if (data.sessionId !== undefined &&
|
|
90
|
+
(typeof data.sessionId !== 'string' || !/^s_[A-Za-z0-9_-]{8}$/.test(data.sessionId)))
|
|
91
|
+
throw new Error('Invalid session id; use session.sessionId');
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
export function resolveSessionManageId(command, transportId) {
|
|
95
|
+
if (command.operation === 'new')
|
|
96
|
+
return transportId;
|
|
97
|
+
if (command.sessionId && transportId && command.sessionId !== transportId)
|
|
98
|
+
throw new Error('Conflicting session IDs');
|
|
99
|
+
return command.sessionId ?? transportId;
|
|
100
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PageRecordingOptions } from './browserActionProtocol.js';
|
|
2
|
+
export interface CdpRecordingStream {
|
|
3
|
+
stop(): Promise<void>;
|
|
4
|
+
read(size: number): Promise<{
|
|
5
|
+
data: string;
|
|
6
|
+
base64Encoded?: boolean;
|
|
7
|
+
eof: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function startCdpRecording(send: (method: string, params?: Record<string, unknown>) => Promise<unknown>, options: Required<PageRecordingOptions>): Promise<CdpRecordingStream>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export async function startCdpRecording(send, options) {
|
|
2
|
+
let handle;
|
|
3
|
+
try {
|
|
4
|
+
const result = (await send('Page.startScreenRecording', { ...options }));
|
|
5
|
+
handle = result.stream;
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
if (error instanceof Error && /-32601|wasn't found|method not found/i.test(error.message))
|
|
9
|
+
throw new Error('This browser does not support native page recording (Chrome 153+ required)');
|
|
10
|
+
throw error;
|
|
11
|
+
}
|
|
12
|
+
let stopPromise;
|
|
13
|
+
let closed = false;
|
|
14
|
+
const stop = () => {
|
|
15
|
+
stopPromise ??= send('Page.stopScreenRecording').then(response => {
|
|
16
|
+
handle = response.stream || handle;
|
|
17
|
+
});
|
|
18
|
+
return stopPromise;
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
stop,
|
|
22
|
+
async read(size) {
|
|
23
|
+
if (!stopPromise || closed)
|
|
24
|
+
throw new Error('Recording stream is unavailable');
|
|
25
|
+
await stopPromise;
|
|
26
|
+
return (await send('IO.read', { handle, size }));
|
|
27
|
+
},
|
|
28
|
+
async close() {
|
|
29
|
+
if (closed)
|
|
30
|
+
return;
|
|
31
|
+
closed = true;
|
|
32
|
+
try {
|
|
33
|
+
await stop();
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
if (handle)
|
|
37
|
+
await send('IO.close', { handle });
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
package/dist/domClicking.js
CHANGED
|
@@ -331,6 +331,15 @@ export function clickElementViaJS(expectedText) {
|
|
|
331
331
|
let ancestor = node.parentElement;
|
|
332
332
|
while (ancestor && ancestor !== document.documentElement) {
|
|
333
333
|
const style = getComputedStyle(ancestor);
|
|
334
|
+
if (ancestor === document.body) {
|
|
335
|
+
// The body's overflow can apply to the viewport instead of its own box.
|
|
336
|
+
const root = getComputedStyle(document.documentElement);
|
|
337
|
+
if ((!root.overflowX || root.overflowX === 'visible') &&
|
|
338
|
+
(!root.overflowY || root.overflowY === 'visible') &&
|
|
339
|
+
(!root.contain || root.contain === 'none') &&
|
|
340
|
+
(!style.contain || style.contain === 'none'))
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
334
343
|
const clipsX = /^(auto|scroll|hidden|clip)$/.test(style.overflowX || '');
|
|
335
344
|
const clipsY = /^(auto|scroll|hidden|clip)$/.test(style.overflowY || '');
|
|
336
345
|
if (clipsX || clipsY) {
|
|
@@ -678,6 +687,15 @@ export function clickElementBySelector(selector, invalidSelectorHint) {
|
|
|
678
687
|
let ancestor = node.parentElement;
|
|
679
688
|
while (ancestor && ancestor !== document.documentElement) {
|
|
680
689
|
const style = getComputedStyle(ancestor);
|
|
690
|
+
if (ancestor === document.body) {
|
|
691
|
+
// The body's overflow can apply to the viewport instead of its own box.
|
|
692
|
+
const root = getComputedStyle(document.documentElement);
|
|
693
|
+
if ((!root.overflowX || root.overflowX === 'visible') &&
|
|
694
|
+
(!root.overflowY || root.overflowY === 'visible') &&
|
|
695
|
+
(!root.contain || root.contain === 'none') &&
|
|
696
|
+
(!style.contain || style.contain === 'none'))
|
|
697
|
+
break;
|
|
698
|
+
}
|
|
681
699
|
const clipsX = /^(auto|scroll|hidden|clip)$/.test(style.overflowX || '');
|
|
682
700
|
const clipsY = /^(auto|scroll|hidden|clip)$/.test(style.overflowY || '');
|
|
683
701
|
if (clipsX || clipsY) {
|
|
@@ -1012,6 +1030,15 @@ export function getClickCoordsFromSelector(selector, invalidSelectorHint) {
|
|
|
1012
1030
|
let ancestor = node.parentElement;
|
|
1013
1031
|
while (ancestor && ancestor !== document.documentElement) {
|
|
1014
1032
|
const style = getComputedStyle(ancestor);
|
|
1033
|
+
if (ancestor === document.body) {
|
|
1034
|
+
// The body's overflow can apply to the viewport instead of its own box.
|
|
1035
|
+
const root = getComputedStyle(document.documentElement);
|
|
1036
|
+
if ((!root.overflowX || root.overflowX === 'visible') &&
|
|
1037
|
+
(!root.overflowY || root.overflowY === 'visible') &&
|
|
1038
|
+
(!root.contain || root.contain === 'none') &&
|
|
1039
|
+
(!style.contain || style.contain === 'none'))
|
|
1040
|
+
break;
|
|
1041
|
+
}
|
|
1015
1042
|
const clipsX = /^(auto|scroll|hidden|clip)$/.test(style.overflowX || '');
|
|
1016
1043
|
const clipsY = /^(auto|scroll|hidden|clip)$/.test(style.overflowY || '');
|
|
1017
1044
|
if (clipsX || clipsY) {
|
|
@@ -1261,6 +1288,15 @@ export function getClickCoordsFromNode(expectedText) {
|
|
|
1261
1288
|
let ancestor = node.parentElement;
|
|
1262
1289
|
while (ancestor && ancestor !== document.documentElement) {
|
|
1263
1290
|
const style = getComputedStyle(ancestor);
|
|
1291
|
+
if (ancestor === document.body) {
|
|
1292
|
+
// The body's overflow can apply to the viewport instead of its own box.
|
|
1293
|
+
const root = getComputedStyle(document.documentElement);
|
|
1294
|
+
if ((!root.overflowX || root.overflowX === 'visible') &&
|
|
1295
|
+
(!root.overflowY || root.overflowY === 'visible') &&
|
|
1296
|
+
(!root.contain || root.contain === 'none') &&
|
|
1297
|
+
(!style.contain || style.contain === 'none'))
|
|
1298
|
+
break;
|
|
1299
|
+
}
|
|
1264
1300
|
const clipsX = /^(auto|scroll|hidden|clip)$/.test(style.overflowX || '');
|
|
1265
1301
|
const clipsY = /^(auto|scroll|hidden|clip)$/.test(style.overflowY || '');
|
|
1266
1302
|
if (clipsX || clipsY) {
|
|
@@ -6,6 +6,8 @@ export function requiresExtensionAgentAccess(action, data, trustedInternal = fal
|
|
|
6
6
|
return true;
|
|
7
7
|
if (action === '__capture_download' || action === '__export_cookies')
|
|
8
8
|
return true;
|
|
9
|
+
if (action === '__page_record')
|
|
10
|
+
return data?.operation === 'start';
|
|
9
11
|
if (action === '__send_request_files')
|
|
10
12
|
return data?.operation !== 'abort';
|
|
11
13
|
if (action === '__browser_enhancement')
|
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
import type { BrowserAccessResult, BrowserActionMap, BrowserJsonValue, BrowserProviderListResult, BrowserProviderLaunchForm, ControlSessionInfo, CookieCopyScope, ManagedBrowserInfo, BrowserReleaseParams, BrowserReleaseResult, PageDownloadParams } from './browserActionProtocol.js';
|
|
1
|
+
import type { BrowserAccessResult, BrowserActionMap, BrowserJsonValue, BrowserProviderListResult, BrowserProviderLaunchForm, ControlSessionInfo, CookieCopyScope, ManagedBrowserInfo, BrowserReleaseParams, BrowserReleaseResult, PageDownloadParams, PageRecordingOptions } from './browserActionProtocol.js';
|
|
2
2
|
import { type AgentServiceActionMap } from './agentServiceProtocol.js';
|
|
3
3
|
import type { BrowserEnhancementRequest, BrowserEnhancementResponse } from './browserEnhancement.js';
|
|
4
4
|
import { type ToolboxServiceActionMap, type ToolboxTaskRequest, type ToolboxTaskResponse } from './toolbox.js';
|
|
5
5
|
export declare const EXTENSION_RPC_VERSION = 1;
|
|
6
|
+
export interface PageUploadTransfer {
|
|
7
|
+
id: string;
|
|
8
|
+
deadline: number;
|
|
9
|
+
files: Array<{
|
|
10
|
+
filename: string;
|
|
11
|
+
bytes: number;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
export interface PageUploadChunkRequest {
|
|
15
|
+
id: string;
|
|
16
|
+
tabId: number;
|
|
17
|
+
fileIndex: number;
|
|
18
|
+
offset: number;
|
|
19
|
+
}
|
|
20
|
+
export interface PageUploadChunk {
|
|
21
|
+
base64: string;
|
|
22
|
+
bytes: number;
|
|
23
|
+
totalBytes: number;
|
|
24
|
+
}
|
|
25
|
+
export declare const PAGE_UPLOAD_TRANSFER_MAX_BYTES: number;
|
|
26
|
+
export declare const PAGE_UPLOAD_FILE_TRANSFER_TIMEOUT_MS = 180000;
|
|
6
27
|
export type OperationRequest<M> = {
|
|
7
28
|
[O in keyof M]: M[O] extends {
|
|
8
29
|
request: infer R;
|
|
@@ -106,8 +127,16 @@ export interface BrowserManagementActionMap {
|
|
|
106
127
|
request: Record<string, never>;
|
|
107
128
|
response: BrowserActionMap['browser_list']['response'];
|
|
108
129
|
};
|
|
109
|
-
|
|
110
|
-
|
|
130
|
+
browser_manage: {
|
|
131
|
+
request: Extract<BrowserActionMap['browser_manage']['request'], {
|
|
132
|
+
operation: 'launch' | 'attach';
|
|
133
|
+
}> | ({
|
|
134
|
+
browser: string;
|
|
135
|
+
} & Extract<BrowserActionMap['browser_manage']['request'], {
|
|
136
|
+
operation: 'close' | 'detach';
|
|
137
|
+
}>);
|
|
138
|
+
response: BrowserActionMap['browser_manage']['response'];
|
|
139
|
+
};
|
|
111
140
|
get_browser_access_url: {
|
|
112
141
|
request: {
|
|
113
142
|
browser: string;
|
|
@@ -120,8 +149,7 @@ export declare const BROWSER_MANAGEMENT_ACTIONS: {
|
|
|
120
149
|
readonly browser_instances: true;
|
|
121
150
|
readonly browser_providers: true;
|
|
122
151
|
readonly browser_list: true;
|
|
123
|
-
readonly
|
|
124
|
-
readonly browser_close: true;
|
|
152
|
+
readonly browser_manage: true;
|
|
125
153
|
readonly get_browser_access_url: true;
|
|
126
154
|
};
|
|
127
155
|
export type BrowserManagementAction = keyof BrowserManagementActionMap;
|
|
@@ -220,6 +248,35 @@ export interface HostToExtensionActionMap {
|
|
|
220
248
|
request: PageDownloadParams;
|
|
221
249
|
response: unknown;
|
|
222
250
|
};
|
|
251
|
+
__page_record: {
|
|
252
|
+
request: {
|
|
253
|
+
operation: 'start';
|
|
254
|
+
recordingId: string;
|
|
255
|
+
tabId: number;
|
|
256
|
+
options: Required<PageRecordingOptions>;
|
|
257
|
+
deadline: number;
|
|
258
|
+
} | {
|
|
259
|
+
operation: 'stop' | 'close';
|
|
260
|
+
recordingId: string;
|
|
261
|
+
} | {
|
|
262
|
+
operation: 'read';
|
|
263
|
+
recordingId: string;
|
|
264
|
+
size: number;
|
|
265
|
+
};
|
|
266
|
+
response: {
|
|
267
|
+
data: string;
|
|
268
|
+
base64Encoded?: boolean;
|
|
269
|
+
eof: boolean;
|
|
270
|
+
} | undefined;
|
|
271
|
+
};
|
|
272
|
+
__page_record_status: {
|
|
273
|
+
request: {
|
|
274
|
+
recordingId: string;
|
|
275
|
+
};
|
|
276
|
+
response: {
|
|
277
|
+
active: boolean;
|
|
278
|
+
};
|
|
279
|
+
};
|
|
223
280
|
__control_cleanup: {
|
|
224
281
|
request: BrowserReleaseParams & {
|
|
225
282
|
tabIds: number[];
|
|
@@ -227,6 +284,10 @@ export interface HostToExtensionActionMap {
|
|
|
227
284
|
};
|
|
228
285
|
response: BrowserReleaseResult;
|
|
229
286
|
};
|
|
287
|
+
__control_release: {
|
|
288
|
+
request: BrowserReleaseParams;
|
|
289
|
+
response: BrowserReleaseResult;
|
|
290
|
+
};
|
|
230
291
|
__control_deactivate: {
|
|
231
292
|
request: {
|
|
232
293
|
tabIds: number[];
|
|
@@ -273,13 +334,17 @@ export declare const HOST_TO_EXTENSION_ACTIONS: {
|
|
|
273
334
|
readonly __preset_browser: true;
|
|
274
335
|
readonly __export_cookies: true;
|
|
275
336
|
readonly __capture_download: true;
|
|
337
|
+
readonly __page_record: true;
|
|
338
|
+
readonly __page_record_status: true;
|
|
276
339
|
readonly __control_cleanup: true;
|
|
340
|
+
readonly __control_release: true;
|
|
277
341
|
readonly __control_deactivate: true;
|
|
278
342
|
readonly __send_request_files: true;
|
|
279
343
|
};
|
|
280
344
|
export declare function isHostToExtensionAction(value: unknown): value is keyof HostToExtensionActionMap;
|
|
281
345
|
/** These services originate in the extension background, not a runtime UI message. */
|
|
282
346
|
export declare const EXTENSION_BACKGROUND_ACTIONS: {
|
|
347
|
+
readonly page_upload_chunk: true;
|
|
283
348
|
readonly preset_installation: true;
|
|
284
349
|
readonly preset_browser_transfer: true;
|
|
285
350
|
readonly app_profile_catalog: true;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { isAgentServiceAction } from './agentServiceProtocol.js';
|
|
2
2
|
import { isToolboxServiceAction, } from './toolbox.js';
|
|
3
3
|
export const EXTENSION_RPC_VERSION = 1;
|
|
4
|
+
export const PAGE_UPLOAD_TRANSFER_MAX_BYTES = 256 * 1024 * 1024;
|
|
5
|
+
export const PAGE_UPLOAD_FILE_TRANSFER_TIMEOUT_MS = 180_000;
|
|
4
6
|
export const BROWSER_MANAGEMENT_ACTIONS = {
|
|
5
7
|
browser_sessions: true,
|
|
6
8
|
browser_instances: true,
|
|
7
9
|
browser_providers: true,
|
|
8
10
|
browser_list: true,
|
|
9
|
-
|
|
10
|
-
browser_close: true,
|
|
11
|
+
browser_manage: true,
|
|
11
12
|
get_browser_access_url: true,
|
|
12
13
|
};
|
|
13
14
|
export function isBrowserManagementAction(value) {
|
|
@@ -34,7 +35,10 @@ export const HOST_TO_EXTENSION_ACTIONS = {
|
|
|
34
35
|
__preset_browser: true,
|
|
35
36
|
__export_cookies: true,
|
|
36
37
|
__capture_download: true,
|
|
38
|
+
__page_record: true,
|
|
39
|
+
__page_record_status: true,
|
|
37
40
|
__control_cleanup: true,
|
|
41
|
+
__control_release: true,
|
|
38
42
|
__control_deactivate: true,
|
|
39
43
|
__send_request_files: true,
|
|
40
44
|
};
|
|
@@ -43,6 +47,7 @@ export function isHostToExtensionAction(value) {
|
|
|
43
47
|
}
|
|
44
48
|
/** These services originate in the extension background, not a runtime UI message. */
|
|
45
49
|
export const EXTENSION_BACKGROUND_ACTIONS = {
|
|
50
|
+
page_upload_chunk: true,
|
|
46
51
|
preset_installation: true,
|
|
47
52
|
preset_browser_transfer: true,
|
|
48
53
|
app_profile_catalog: true,
|
|
@@ -77,9 +82,9 @@ export function getExtensionServiceTimeout(action, data = {}) {
|
|
|
77
82
|
return data.operation === 'detach' ? 60000 : 120000;
|
|
78
83
|
if (action === 'browser_providers')
|
|
79
84
|
return data.operation === 'launch_form' ? 120000 : data.operation === 'list' ? 15000 : 60000;
|
|
80
|
-
if (action === '
|
|
81
|
-
return 120000;
|
|
82
|
-
if (action === '
|
|
85
|
+
if (action === 'browser_manage')
|
|
86
|
+
return data.operation === 'launch' || data.operation === 'attach' ? 120000 : 60000;
|
|
87
|
+
if (action === 'get_browser_access_url')
|
|
83
88
|
return 60000;
|
|
84
89
|
if (action === 'toolbox_plugin_uninstall' || action === 'toolbox_page')
|
|
85
90
|
return 120000;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AddRuleParams, RulesResult } from './browserActionProtocol.js';
|
|
2
|
+
export interface CompiledHeaderRule {
|
|
3
|
+
actionType: 'modifyHeaders';
|
|
4
|
+
filter: string;
|
|
5
|
+
regex: RegExp;
|
|
6
|
+
requestHeaders: Array<{
|
|
7
|
+
header: string;
|
|
8
|
+
operation: 'set';
|
|
9
|
+
value: string;
|
|
10
|
+
}>;
|
|
11
|
+
resourceTypes: string[];
|
|
12
|
+
priority: number;
|
|
13
|
+
description: string;
|
|
14
|
+
}
|
|
15
|
+
export interface StoredHeaderRule extends CompiledHeaderRule {
|
|
16
|
+
ruleId: number;
|
|
17
|
+
enabled: true;
|
|
18
|
+
}
|
|
19
|
+
/** Validate one modifyHeaders rule. Transports keep their own intercept session. */
|
|
20
|
+
export declare function compileHeaderRule(data: AddRuleParams, label?: string): CompiledHeaderRule;
|
|
21
|
+
/** Browser-session header rules. Matching is pure; the transport continues the request. */
|
|
22
|
+
export declare class HeaderRuleSet {
|
|
23
|
+
private rules;
|
|
24
|
+
private nextRuleId;
|
|
25
|
+
get size(): number;
|
|
26
|
+
add(data: AddRuleParams, label?: string): {
|
|
27
|
+
success: boolean;
|
|
28
|
+
ruleId: number;
|
|
29
|
+
affectedCount: number;
|
|
30
|
+
message: string;
|
|
31
|
+
};
|
|
32
|
+
remove(ruleId: number, label?: string): {
|
|
33
|
+
success: boolean;
|
|
34
|
+
ruleId: number;
|
|
35
|
+
affectedCount: number;
|
|
36
|
+
message: string;
|
|
37
|
+
};
|
|
38
|
+
list(): RulesResult;
|
|
39
|
+
/** Return the replacement header list when at least one rule matches. */
|
|
40
|
+
apply(url: string, resourceType: string, headers: ReadonlyArray<{
|
|
41
|
+
name: string;
|
|
42
|
+
value: string;
|
|
43
|
+
}>): Array<{
|
|
44
|
+
name: string;
|
|
45
|
+
value: string;
|
|
46
|
+
}> | undefined;
|
|
47
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const RESOURCE_TYPES = new Set(['main_frame', 'sub_frame', 'xmlhttprequest']);
|
|
2
|
+
const HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
3
|
+
/** Validate one modifyHeaders rule. Transports keep their own intercept session. */
|
|
4
|
+
export function compileHeaderRule(data, label = 'set_rule') {
|
|
5
|
+
if (data?.actionType !== 'modifyHeaders') {
|
|
6
|
+
throw new Error(`${label} supports modifyHeaders request headers only`);
|
|
7
|
+
}
|
|
8
|
+
if (typeof data.filter !== 'string' || !data.filter.trim() || data.filter.length > 2048) {
|
|
9
|
+
throw new Error(`${label} requires a non-empty regex filter (max 2048 characters)`);
|
|
10
|
+
}
|
|
11
|
+
let regex;
|
|
12
|
+
try {
|
|
13
|
+
regex = new RegExp(data.filter);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
throw new Error(`${label} filter is not a valid regex`);
|
|
17
|
+
}
|
|
18
|
+
if (data.responseHeaders?.length || data.initiatorDomains) {
|
|
19
|
+
throw new Error(`${label} does not support responseHeaders or initiatorDomains`);
|
|
20
|
+
}
|
|
21
|
+
if (!Array.isArray(data.requestHeaders) || data.requestHeaders.length === 0) {
|
|
22
|
+
throw new Error(`${label} requires requestHeaders`);
|
|
23
|
+
}
|
|
24
|
+
const requestHeaders = data.requestHeaders.map(header => {
|
|
25
|
+
if (!header ||
|
|
26
|
+
typeof header.header !== 'string' ||
|
|
27
|
+
!HEADER_NAME.test(header.header) ||
|
|
28
|
+
header.operation !== 'set' ||
|
|
29
|
+
typeof header.value !== 'string' ||
|
|
30
|
+
/[\r\n\0]/.test(header.value)) {
|
|
31
|
+
throw new Error(`${label} supports request header set operations with valid names and values`);
|
|
32
|
+
}
|
|
33
|
+
return { header: header.header, operation: 'set', value: header.value };
|
|
34
|
+
});
|
|
35
|
+
const resourceTypes = data.resourceTypes ?? ['main_frame', 'sub_frame', 'xmlhttprequest'];
|
|
36
|
+
if (!Array.isArray(resourceTypes) ||
|
|
37
|
+
resourceTypes.length === 0 ||
|
|
38
|
+
resourceTypes.some(type => !RESOURCE_TYPES.has(type))) {
|
|
39
|
+
throw new Error(`${label} supports main_frame, sub_frame, and xmlhttprequest resource types`);
|
|
40
|
+
}
|
|
41
|
+
const priority = data.priority ?? 1;
|
|
42
|
+
if (!Number.isInteger(priority) || priority < 1) {
|
|
43
|
+
throw new Error(`${label} priority must be a positive integer`);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
actionType: 'modifyHeaders',
|
|
47
|
+
filter: data.filter,
|
|
48
|
+
regex,
|
|
49
|
+
requestHeaders,
|
|
50
|
+
resourceTypes: [...resourceTypes],
|
|
51
|
+
priority,
|
|
52
|
+
description: data.description ?? 'Rule added via MCP/Skill',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Browser-session header rules. Matching is pure; the transport continues the request. */
|
|
56
|
+
export class HeaderRuleSet {
|
|
57
|
+
rules = [];
|
|
58
|
+
nextRuleId = 1;
|
|
59
|
+
get size() {
|
|
60
|
+
return this.rules.length;
|
|
61
|
+
}
|
|
62
|
+
add(data, label = 'set_rule') {
|
|
63
|
+
const rule = {
|
|
64
|
+
...compileHeaderRule(data, label),
|
|
65
|
+
ruleId: this.nextRuleId++,
|
|
66
|
+
enabled: true,
|
|
67
|
+
};
|
|
68
|
+
this.rules.push(rule);
|
|
69
|
+
return {
|
|
70
|
+
success: true,
|
|
71
|
+
ruleId: rule.ruleId,
|
|
72
|
+
affectedCount: 1,
|
|
73
|
+
message: `Rule #${rule.ruleId} added for the current browser session.`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
remove(ruleId, label = 'set_rule') {
|
|
77
|
+
if (!Number.isSafeInteger(ruleId) || ruleId < 1) {
|
|
78
|
+
throw new Error(`${label} requires a positive integer ruleId when enabled is false`);
|
|
79
|
+
}
|
|
80
|
+
const index = this.rules.findIndex(rule => rule.ruleId === ruleId);
|
|
81
|
+
if (index < 0)
|
|
82
|
+
return { success: true, ruleId, affectedCount: 0, message: `Rule #${ruleId} not found.` };
|
|
83
|
+
this.rules.splice(index, 1);
|
|
84
|
+
return { success: true, ruleId, affectedCount: 1, message: `Rule #${ruleId} removed.` };
|
|
85
|
+
}
|
|
86
|
+
list() {
|
|
87
|
+
return {
|
|
88
|
+
enabled: true,
|
|
89
|
+
rules: this.rules.map(({ regex: _regex, ...rule }) => ({ ...rule })),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** Return the replacement header list when at least one rule matches. */
|
|
93
|
+
apply(url, resourceType, headers) {
|
|
94
|
+
const matched = this.rules
|
|
95
|
+
.filter(rule => rule.resourceTypes.includes(resourceType) && rule.regex.test(url))
|
|
96
|
+
.sort((left, right) => left.priority - right.priority || left.ruleId - right.ruleId);
|
|
97
|
+
if (!matched.length)
|
|
98
|
+
return undefined;
|
|
99
|
+
const next = new Map();
|
|
100
|
+
for (const header of headers)
|
|
101
|
+
next.set(header.name.toLowerCase(), { name: header.name, value: header.value });
|
|
102
|
+
for (const rule of matched) {
|
|
103
|
+
for (const header of rule.requestHeaders) {
|
|
104
|
+
next.set(header.header.toLowerCase(), { name: header.header, value: header.value });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return [...next.values()];
|
|
108
|
+
}
|
|
109
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -44,10 +44,13 @@ export * from './pluginPages.js';
|
|
|
44
44
|
export * from './pluginPageRuntime.js';
|
|
45
45
|
export * from './pluginPageHost.js';
|
|
46
46
|
export * from './browserActionProtocol.js';
|
|
47
|
+
export * from './browserManagement.js';
|
|
48
|
+
export * from './cdpRecording.js';
|
|
47
49
|
export * from './browserCapabilities.js';
|
|
48
50
|
export * from './runActions.js';
|
|
49
51
|
export * from './sendRequestFiles.js';
|
|
50
52
|
export * from './sendRequestHeaders.js';
|
|
53
|
+
export * from './headerRules.js';
|
|
51
54
|
export * from './cookie.js';
|
|
52
55
|
export * from './controlledFavicon.js';
|
|
53
56
|
export * from './capture.js';
|
package/dist/index.js
CHANGED
|
@@ -43,10 +43,13 @@ export * from './pluginPages.js';
|
|
|
43
43
|
export * from './pluginPageRuntime.js';
|
|
44
44
|
export * from './pluginPageHost.js';
|
|
45
45
|
export * from './browserActionProtocol.js';
|
|
46
|
+
export * from './browserManagement.js';
|
|
47
|
+
export * from './cdpRecording.js';
|
|
46
48
|
export * from './browserCapabilities.js';
|
|
47
49
|
export * from './runActions.js';
|
|
48
50
|
export * from './sendRequestFiles.js';
|
|
49
51
|
export * from './sendRequestHeaders.js';
|
|
52
|
+
export * from './headerRules.js';
|
|
50
53
|
export * from './cookie.js';
|
|
51
54
|
export * from './controlledFavicon.js';
|
|
52
55
|
export * from './capture.js';
|
package/dist/proxyPermissions.js
CHANGED
|
@@ -88,9 +88,12 @@ export const ACTIONS_SKIP_DOMAIN_CHECK = new Set([
|
|
|
88
88
|
'get_capabilities',
|
|
89
89
|
'__export_cookies',
|
|
90
90
|
'run_actions',
|
|
91
|
-
'
|
|
91
|
+
'__control_release',
|
|
92
92
|
'__control_cleanup',
|
|
93
93
|
'__control_deactivate',
|
|
94
|
+
// The recording handler authorizes the recorded tab and its navigation history.
|
|
95
|
+
'__page_record',
|
|
96
|
+
'__page_record_status',
|
|
94
97
|
'__toolbox_open',
|
|
95
98
|
'__extension_reload',
|
|
96
99
|
'__preset_browser',
|
package/dist/runActions.js
CHANGED
|
@@ -22,7 +22,7 @@ export async function runActionBatch(data, execute, options = {}) {
|
|
|
22
22
|
validationError = `unsupported action "${action}"`;
|
|
23
23
|
else if (action === 'run_actions')
|
|
24
24
|
validationError = `composite action "${action}" is not allowed in run_actions`;
|
|
25
|
-
else if (action === '
|
|
25
|
+
else if (action === 'get_capabilities')
|
|
26
26
|
validationError = `browser-level action "${action}" is not allowed in run_actions`;
|
|
27
27
|
if (validationError)
|
|
28
28
|
return {
|
package/package.json
CHANGED