@mearl/browser-core 3.0.11 → 3.1.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/dist/browserActionProtocol.d.ts +132 -39
- 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/extensionAgentAccess.js +2 -0
- package/dist/extensionServiceProtocol.d.ts +48 -5
- package/dist/extensionServiceProtocol.js +7 -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/rootWebViewNavigation.d.ts +2 -0
- package/dist/rootWebViewNavigation.js +112 -17
- package/dist/runActions.js +1 -1
- package/package.json +1 -1
|
@@ -119,7 +119,11 @@ export interface NetworkControlSelection {
|
|
|
119
119
|
}
|
|
120
120
|
export type BrowserStatus = 'connected' | 'pairing' | 'running_disconnected' | 'stopped';
|
|
121
121
|
export type BrowserTransport = 'extension' | 'cdp' | 'provider';
|
|
122
|
-
|
|
122
|
+
/** Localized overrides for Provider UI text, keyed by locale or language. */
|
|
123
|
+
export interface BrowserProviderLocales<Field extends string> {
|
|
124
|
+
locales?: Record<string, Partial<Record<Field, string>>>;
|
|
125
|
+
}
|
|
126
|
+
export interface BrowserPairingInfo extends BrowserProviderLocales<'label'> {
|
|
123
127
|
kind: 'qr';
|
|
124
128
|
url: string;
|
|
125
129
|
/** Optional human-readable or provider-specific pairing code. */
|
|
@@ -153,10 +157,12 @@ export type BrowserDetails = Record<string, BrowserJsonValue> & {
|
|
|
153
157
|
count: number;
|
|
154
158
|
};
|
|
155
159
|
};
|
|
156
|
-
export interface BrowserReference {
|
|
160
|
+
export interface BrowserReference extends BrowserProviderLocales<'label'> {
|
|
157
161
|
kind: string;
|
|
158
162
|
id: string;
|
|
159
163
|
label?: string;
|
|
164
|
+
/** Show this identifier in the collapsed browser row. */
|
|
165
|
+
summary?: boolean;
|
|
160
166
|
}
|
|
161
167
|
export interface BrowserInfoBase {
|
|
162
168
|
browserId: string;
|
|
@@ -183,7 +189,7 @@ export interface BrowserInfoBase {
|
|
|
183
189
|
export type BrowserScreenshotKind = 'native' | 'reconstructed' | 'none';
|
|
184
190
|
export type BrowserControlSessionMode = 'mearl' | 'external';
|
|
185
191
|
/** Browser-targeted actions that an external provider may implement. */
|
|
186
|
-
export type BrowserCapabilityAction = ExtensionBrowserAction | 'page_download';
|
|
192
|
+
export type BrowserCapabilityAction = ExtensionBrowserAction | 'page_download' | 'browser_release';
|
|
187
193
|
/** Capabilities advertised by an external browser-control provider. */
|
|
188
194
|
export interface BrowserCapabilities {
|
|
189
195
|
actions: BrowserCapabilityAction[];
|
|
@@ -191,6 +197,8 @@ export interface BrowserCapabilities {
|
|
|
191
197
|
screenshot: BrowserScreenshotKind;
|
|
192
198
|
/** Fixed per instance. Omitted means Mearl sessions; external delegates task control. */
|
|
193
199
|
controlSessionMode?: BrowserControlSessionMode;
|
|
200
|
+
/** Provider returns dialog receipts from page_snapshot and accepts page_press dialogId. */
|
|
201
|
+
nativeDialogs?: true;
|
|
194
202
|
}
|
|
195
203
|
export interface RegularBrowserInfo extends BrowserInfoBase {
|
|
196
204
|
type: 'regular';
|
|
@@ -288,6 +296,52 @@ export interface BrowserArtifact {
|
|
|
288
296
|
/** Global browser route is attached by the unified client. */
|
|
289
297
|
browserId?: string;
|
|
290
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);
|
|
291
345
|
export interface PageDownloadParams {
|
|
292
346
|
tabId: number;
|
|
293
347
|
trigger: Omit<PageClickParams, 'tabId'>;
|
|
@@ -326,7 +380,34 @@ export interface BrowserCloseParams {
|
|
|
326
380
|
browser: string;
|
|
327
381
|
deleteProfile?: boolean;
|
|
328
382
|
}
|
|
329
|
-
|
|
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);
|
|
410
|
+
interface BrowserProviderSchemaBase extends BrowserProviderLocales<'title' | 'description' | 'placeholder'> {
|
|
330
411
|
title?: string;
|
|
331
412
|
description?: string;
|
|
332
413
|
default?: BrowserJsonValue;
|
|
@@ -354,17 +435,13 @@ export type BrowserProviderInputSchema = (BrowserProviderSchemaBase & {
|
|
|
354
435
|
maxLength?: number;
|
|
355
436
|
pattern?: string;
|
|
356
437
|
placeholder?: string;
|
|
357
|
-
options?: readonly
|
|
358
|
-
value: string;
|
|
359
|
-
label: string;
|
|
360
|
-
description?: string;
|
|
361
|
-
disabled?: boolean;
|
|
362
|
-
}[];
|
|
438
|
+
options?: readonly BrowserProviderInputOption[];
|
|
363
439
|
}) | (BrowserProviderSchemaBase & {
|
|
364
440
|
type: 'number';
|
|
365
441
|
integer?: boolean;
|
|
366
442
|
minimum?: number;
|
|
367
443
|
maximum?: number;
|
|
444
|
+
placeholder?: string;
|
|
368
445
|
}) | (BrowserProviderSchemaBase & {
|
|
369
446
|
type: 'boolean';
|
|
370
447
|
}) | (BrowserProviderSchemaBase & {
|
|
@@ -381,10 +458,18 @@ export interface BrowserProviderObjectSchema extends BrowserProviderSchemaBase {
|
|
|
381
458
|
not?: BrowserProviderObjectSchema;
|
|
382
459
|
additionalProperties?: boolean;
|
|
383
460
|
}
|
|
461
|
+
export interface BrowserProviderInputOption extends BrowserProviderLocales<'label' | 'description'> {
|
|
462
|
+
value: string;
|
|
463
|
+
label: string;
|
|
464
|
+
description?: string;
|
|
465
|
+
disabled?: boolean;
|
|
466
|
+
}
|
|
384
467
|
export interface BrowserProviderDefinition {
|
|
385
468
|
provider: BrowserProviderIdentity;
|
|
386
|
-
browserType: {
|
|
469
|
+
browserType: BrowserProviderLocales<'name'> & {
|
|
387
470
|
name: string;
|
|
471
|
+
/** Operation exposed for the Provider's instance entry point. Defaults to launch. */
|
|
472
|
+
openOperation?: 'launch' | 'attach';
|
|
388
473
|
controlSessionModes?: readonly BrowserControlSessionMode[];
|
|
389
474
|
documentationUrl?: string;
|
|
390
475
|
inputSchema: BrowserProviderObjectSchema;
|
|
@@ -395,7 +480,7 @@ export interface BrowserProviderDefinition {
|
|
|
395
480
|
launchForm?: BrowserProviderLaunchForm;
|
|
396
481
|
};
|
|
397
482
|
}
|
|
398
|
-
export interface BrowserProviderLaunchFormVariant {
|
|
483
|
+
export interface BrowserProviderLaunchFormVariant extends BrowserProviderLocales<'title' | 'description'> {
|
|
399
484
|
id: string;
|
|
400
485
|
title: string;
|
|
401
486
|
description?: string;
|
|
@@ -404,7 +489,7 @@ export interface BrowserProviderLaunchFormVariant {
|
|
|
404
489
|
refreshOn?: readonly string[];
|
|
405
490
|
dynamicFields?: readonly string[];
|
|
406
491
|
}
|
|
407
|
-
export interface BrowserProviderLaunchForm {
|
|
492
|
+
export interface BrowserProviderLaunchForm extends BrowserProviderLocales<'message'> {
|
|
408
493
|
inputSchema: BrowserProviderObjectSchema;
|
|
409
494
|
variants?: readonly BrowserProviderLaunchFormVariant[];
|
|
410
495
|
variant?: string;
|
|
@@ -784,7 +869,7 @@ export interface SetCookieResult {
|
|
|
784
869
|
export interface RequestPermissionParams {
|
|
785
870
|
domain: string;
|
|
786
871
|
}
|
|
787
|
-
export type RunActionName = Exclude<ExtensionBrowserAction, 'run_actions' | '
|
|
872
|
+
export type RunActionName = Exclude<ExtensionBrowserAction, 'run_actions' | 'get_capabilities'>;
|
|
788
873
|
export interface ActionStep {
|
|
789
874
|
action: RunActionName;
|
|
790
875
|
data?: Record<string, unknown>;
|
|
@@ -847,27 +932,36 @@ export interface BrowserActionMap {
|
|
|
847
932
|
request: SelectBrowserParams;
|
|
848
933
|
response: SelectBrowserResult;
|
|
849
934
|
};
|
|
850
|
-
|
|
851
|
-
request:
|
|
852
|
-
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
|
+
};
|
|
853
949
|
};
|
|
854
|
-
|
|
855
|
-
request:
|
|
950
|
+
session_manage: {
|
|
951
|
+
request: SessionManageParams;
|
|
856
952
|
response: {
|
|
857
953
|
session: ControlSessionInfo;
|
|
858
|
-
} | ExternalBrowserControlResult
|
|
954
|
+
} | (Omit<ExternalBrowserControlResult, 'operation'> & {
|
|
955
|
+
operation: 'handoff' | 'resume' | 'end';
|
|
956
|
+
});
|
|
859
957
|
};
|
|
860
958
|
page_download: {
|
|
861
959
|
request: PageDownloadParams;
|
|
862
960
|
response: PageDownloadResult;
|
|
863
961
|
};
|
|
864
|
-
|
|
865
|
-
request:
|
|
866
|
-
response:
|
|
867
|
-
};
|
|
868
|
-
browser_close: {
|
|
869
|
-
request: BrowserCloseParams;
|
|
870
|
-
response: unknown;
|
|
962
|
+
page_record: {
|
|
963
|
+
request: PageRecordParams;
|
|
964
|
+
response: PageRecordResult;
|
|
871
965
|
};
|
|
872
966
|
page_screenshot: {
|
|
873
967
|
request: PageScreenshotParams;
|
|
@@ -983,11 +1077,11 @@ export interface BrowserActionMap {
|
|
|
983
1077
|
export type BrowserAction = keyof BrowserActionMap;
|
|
984
1078
|
export type BrowserActionRequest<A extends BrowserAction> = BrowserActionMap[A]['request'];
|
|
985
1079
|
export type BrowserActionResponse<A extends BrowserAction> = BrowserActionMap[A]['response'] & {
|
|
986
|
-
/** Routing and execution state;
|
|
1080
|
+
/** Routing and execution state; session_manage returns the full tab inventory. */
|
|
987
1081
|
session?: Omit<ControlSessionInfo, 'tabs'>;
|
|
988
1082
|
};
|
|
989
1083
|
export type BrowserCommandAction = Exclude<BrowserAction, 'browser_select_browser'>;
|
|
990
|
-
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'>;
|
|
991
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"];
|
|
992
1086
|
export type TabIdRequiredAction = (typeof TAB_ID_REQUIRED_ACTIONS)[number];
|
|
993
1087
|
export declare function actionRequiresTabId(action: unknown): action is TabIdRequiredAction;
|
|
@@ -1008,11 +1102,11 @@ export declare const BROWSER_ACTIONS: {
|
|
|
1008
1102
|
readonly send_request: true;
|
|
1009
1103
|
readonly browser_list: true;
|
|
1010
1104
|
readonly browser_select_browser: true;
|
|
1011
|
-
readonly
|
|
1012
|
-
readonly
|
|
1105
|
+
readonly browser_manage: true;
|
|
1106
|
+
readonly session_list: true;
|
|
1107
|
+
readonly session_manage: true;
|
|
1013
1108
|
readonly page_download: true;
|
|
1014
|
-
readonly
|
|
1015
|
-
readonly browser_close: true;
|
|
1109
|
+
readonly page_record: true;
|
|
1016
1110
|
readonly page_screenshot: true;
|
|
1017
1111
|
readonly tab_open: true;
|
|
1018
1112
|
readonly tab_close: true;
|
|
@@ -1054,11 +1148,11 @@ export declare const BROWSER_COMMAND_ACTIONS: {
|
|
|
1054
1148
|
readonly get_capabilities: true;
|
|
1055
1149
|
readonly send_request: true;
|
|
1056
1150
|
readonly browser_list: true;
|
|
1057
|
-
readonly
|
|
1058
|
-
readonly
|
|
1151
|
+
readonly browser_manage: true;
|
|
1152
|
+
readonly session_list: true;
|
|
1153
|
+
readonly session_manage: true;
|
|
1059
1154
|
readonly page_download: true;
|
|
1060
|
-
readonly
|
|
1061
|
-
readonly browser_close: true;
|
|
1155
|
+
readonly page_record: true;
|
|
1062
1156
|
readonly page_screenshot: true;
|
|
1063
1157
|
readonly tab_open: true;
|
|
1064
1158
|
readonly tab_close: true;
|
|
@@ -1099,7 +1193,6 @@ export declare const EXTENSION_BROWSER_ACTIONS: {
|
|
|
1099
1193
|
readonly get_rules: true;
|
|
1100
1194
|
readonly get_capabilities: true;
|
|
1101
1195
|
readonly send_request: true;
|
|
1102
|
-
readonly browser_release: true;
|
|
1103
1196
|
readonly page_screenshot: true;
|
|
1104
1197
|
readonly tab_open: true;
|
|
1105
1198
|
readonly tab_close: true;
|
|
@@ -1130,6 +1223,7 @@ export declare const EXTENSION_BROWSER_ACTIONS: {
|
|
|
1130
1223
|
};
|
|
1131
1224
|
export declare const BROWSER_CAPABILITY_ACTIONS: {
|
|
1132
1225
|
readonly page_download: true;
|
|
1226
|
+
readonly browser_release: true;
|
|
1133
1227
|
readonly tab_checkpoint: true;
|
|
1134
1228
|
readonly capture_checkpoint: true;
|
|
1135
1229
|
readonly get_requests: true;
|
|
@@ -1141,7 +1235,6 @@ export declare const BROWSER_CAPABILITY_ACTIONS: {
|
|
|
1141
1235
|
readonly get_rules: true;
|
|
1142
1236
|
readonly get_capabilities: true;
|
|
1143
1237
|
readonly send_request: true;
|
|
1144
|
-
readonly browser_release: true;
|
|
1145
1238
|
readonly page_screenshot: true;
|
|
1146
1239
|
readonly tab_open: true;
|
|
1147
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
|
+
}
|
|
@@ -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,4 +1,4 @@
|
|
|
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';
|
|
@@ -106,8 +106,16 @@ export interface BrowserManagementActionMap {
|
|
|
106
106
|
request: Record<string, never>;
|
|
107
107
|
response: BrowserActionMap['browser_list']['response'];
|
|
108
108
|
};
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
browser_manage: {
|
|
110
|
+
request: Extract<BrowserActionMap['browser_manage']['request'], {
|
|
111
|
+
operation: 'launch' | 'attach';
|
|
112
|
+
}> | ({
|
|
113
|
+
browser: string;
|
|
114
|
+
} & Extract<BrowserActionMap['browser_manage']['request'], {
|
|
115
|
+
operation: 'close' | 'detach';
|
|
116
|
+
}>);
|
|
117
|
+
response: BrowserActionMap['browser_manage']['response'];
|
|
118
|
+
};
|
|
111
119
|
get_browser_access_url: {
|
|
112
120
|
request: {
|
|
113
121
|
browser: string;
|
|
@@ -120,8 +128,7 @@ export declare const BROWSER_MANAGEMENT_ACTIONS: {
|
|
|
120
128
|
readonly browser_instances: true;
|
|
121
129
|
readonly browser_providers: true;
|
|
122
130
|
readonly browser_list: true;
|
|
123
|
-
readonly
|
|
124
|
-
readonly browser_close: true;
|
|
131
|
+
readonly browser_manage: true;
|
|
125
132
|
readonly get_browser_access_url: true;
|
|
126
133
|
};
|
|
127
134
|
export type BrowserManagementAction = keyof BrowserManagementActionMap;
|
|
@@ -220,6 +227,35 @@ export interface HostToExtensionActionMap {
|
|
|
220
227
|
request: PageDownloadParams;
|
|
221
228
|
response: unknown;
|
|
222
229
|
};
|
|
230
|
+
__page_record: {
|
|
231
|
+
request: {
|
|
232
|
+
operation: 'start';
|
|
233
|
+
recordingId: string;
|
|
234
|
+
tabId: number;
|
|
235
|
+
options: Required<PageRecordingOptions>;
|
|
236
|
+
deadline: number;
|
|
237
|
+
} | {
|
|
238
|
+
operation: 'stop' | 'close';
|
|
239
|
+
recordingId: string;
|
|
240
|
+
} | {
|
|
241
|
+
operation: 'read';
|
|
242
|
+
recordingId: string;
|
|
243
|
+
size: number;
|
|
244
|
+
};
|
|
245
|
+
response: {
|
|
246
|
+
data: string;
|
|
247
|
+
base64Encoded?: boolean;
|
|
248
|
+
eof: boolean;
|
|
249
|
+
} | undefined;
|
|
250
|
+
};
|
|
251
|
+
__page_record_status: {
|
|
252
|
+
request: {
|
|
253
|
+
recordingId: string;
|
|
254
|
+
};
|
|
255
|
+
response: {
|
|
256
|
+
active: boolean;
|
|
257
|
+
};
|
|
258
|
+
};
|
|
223
259
|
__control_cleanup: {
|
|
224
260
|
request: BrowserReleaseParams & {
|
|
225
261
|
tabIds: number[];
|
|
@@ -227,6 +263,10 @@ export interface HostToExtensionActionMap {
|
|
|
227
263
|
};
|
|
228
264
|
response: BrowserReleaseResult;
|
|
229
265
|
};
|
|
266
|
+
__control_release: {
|
|
267
|
+
request: BrowserReleaseParams;
|
|
268
|
+
response: BrowserReleaseResult;
|
|
269
|
+
};
|
|
230
270
|
__control_deactivate: {
|
|
231
271
|
request: {
|
|
232
272
|
tabIds: number[];
|
|
@@ -273,7 +313,10 @@ export declare const HOST_TO_EXTENSION_ACTIONS: {
|
|
|
273
313
|
readonly __preset_browser: true;
|
|
274
314
|
readonly __export_cookies: true;
|
|
275
315
|
readonly __capture_download: true;
|
|
316
|
+
readonly __page_record: true;
|
|
317
|
+
readonly __page_record_status: true;
|
|
276
318
|
readonly __control_cleanup: true;
|
|
319
|
+
readonly __control_release: true;
|
|
277
320
|
readonly __control_deactivate: true;
|
|
278
321
|
readonly __send_request_files: true;
|
|
279
322
|
};
|
|
@@ -6,8 +6,7 @@ export const BROWSER_MANAGEMENT_ACTIONS = {
|
|
|
6
6
|
browser_instances: true,
|
|
7
7
|
browser_providers: true,
|
|
8
8
|
browser_list: true,
|
|
9
|
-
|
|
10
|
-
browser_close: true,
|
|
9
|
+
browser_manage: true,
|
|
11
10
|
get_browser_access_url: true,
|
|
12
11
|
};
|
|
13
12
|
export function isBrowserManagementAction(value) {
|
|
@@ -34,7 +33,10 @@ export const HOST_TO_EXTENSION_ACTIONS = {
|
|
|
34
33
|
__preset_browser: true,
|
|
35
34
|
__export_cookies: true,
|
|
36
35
|
__capture_download: true,
|
|
36
|
+
__page_record: true,
|
|
37
|
+
__page_record_status: true,
|
|
37
38
|
__control_cleanup: true,
|
|
39
|
+
__control_release: true,
|
|
38
40
|
__control_deactivate: true,
|
|
39
41
|
__send_request_files: true,
|
|
40
42
|
};
|
|
@@ -77,9 +79,9 @@ export function getExtensionServiceTimeout(action, data = {}) {
|
|
|
77
79
|
return data.operation === 'detach' ? 60000 : 120000;
|
|
78
80
|
if (action === 'browser_providers')
|
|
79
81
|
return data.operation === 'launch_form' ? 120000 : data.operation === 'list' ? 15000 : 60000;
|
|
80
|
-
if (action === '
|
|
81
|
-
return 120000;
|
|
82
|
-
if (action === '
|
|
82
|
+
if (action === 'browser_manage')
|
|
83
|
+
return data.operation === 'launch' || data.operation === 'attach' ? 120000 : 60000;
|
|
84
|
+
if (action === 'get_browser_access_url')
|
|
83
85
|
return 60000;
|
|
84
86
|
if (action === 'toolbox_plugin_uninstall' || action === 'toolbox_page')
|
|
85
87
|
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',
|
|
@@ -45,6 +45,7 @@ export interface WebViewFrameTree {
|
|
|
45
45
|
urlFragment?: string;
|
|
46
46
|
name?: string;
|
|
47
47
|
parentId?: string;
|
|
48
|
+
mimeType?: string;
|
|
48
49
|
};
|
|
49
50
|
childFrames?: WebViewFrameTree[];
|
|
50
51
|
}
|
|
@@ -61,6 +62,7 @@ export interface WebViewFrameEvent {
|
|
|
61
62
|
export declare function createRootWebViewNavigation(options: RootWebViewNavigationOptions): {
|
|
62
63
|
isSameOriginRootNavigation: (params: WebViewNavigationRequest) => boolean;
|
|
63
64
|
preserveNavigationSource: ({ request }: WebViewNavigationRequest) => (() => void);
|
|
65
|
+
prepareShellReload(): (() => void) | undefined;
|
|
64
66
|
allowLocalReload(frameId: string, url: string): () => void;
|
|
65
67
|
dispose(): void;
|
|
66
68
|
initialize(tree: WebViewFrameTree): void;
|
|
@@ -55,6 +55,7 @@ async function readDocumentBody(client, requestId) {
|
|
|
55
55
|
export function createRootWebViewNavigation(options) {
|
|
56
56
|
let handoff;
|
|
57
57
|
let localReload;
|
|
58
|
+
let shellReload;
|
|
58
59
|
let mainFrame;
|
|
59
60
|
let rootFrameId;
|
|
60
61
|
let committedRoot;
|
|
@@ -70,16 +71,24 @@ export function createRootWebViewNavigation(options) {
|
|
|
70
71
|
expiry = undefined;
|
|
71
72
|
};
|
|
72
73
|
const isSameOriginRootNavigation = (params) => {
|
|
73
|
-
if (!options.keepSameOriginNavigation ||
|
|
74
|
+
if (!options.keepSameOriginNavigation ||
|
|
75
|
+
!mainFrame ||
|
|
76
|
+
!committedRoot ||
|
|
74
77
|
params.frameId !== committedRoot.id ||
|
|
75
|
-
params.resourceType !== 'Document' ||
|
|
76
|
-
params.
|
|
77
|
-
|
|
78
|
+
params.resourceType !== 'Document' ||
|
|
79
|
+
params.request.method !== 'GET' ||
|
|
80
|
+
params.responseStatusCode != null ||
|
|
81
|
+
params.responseErrorReason != null ||
|
|
82
|
+
!/^https?:/.test(params.request.url) ||
|
|
83
|
+
!/^https?:/.test(mainFrame.url))
|
|
78
84
|
return false;
|
|
79
85
|
const destination = new URL(params.request.url);
|
|
80
|
-
return !destination.pathname.startsWith(DOCUMENT_PREFIX) &&
|
|
81
|
-
!(localReload &&
|
|
82
|
-
|
|
86
|
+
return (!destination.pathname.startsWith(DOCUMENT_PREFIX) &&
|
|
87
|
+
!(localReload &&
|
|
88
|
+
localReload.frameId === params.frameId &&
|
|
89
|
+
localReload.url === destination.href) &&
|
|
90
|
+
destination.origin === committedRoot.origin &&
|
|
91
|
+
destination.origin === new URL(mainFrame.url).origin);
|
|
83
92
|
};
|
|
84
93
|
const preserveNavigationSource = ({ request }) => {
|
|
85
94
|
const source = {
|
|
@@ -87,8 +96,10 @@ export function createRootWebViewNavigation(options) {
|
|
|
87
96
|
headers: Object.fromEntries(Object.entries(request.headers ?? {}).filter(([name]) => /^(referer|origin)$/i.test(name))),
|
|
88
97
|
};
|
|
89
98
|
handoff = source;
|
|
90
|
-
return () => {
|
|
91
|
-
handoff
|
|
99
|
+
return () => {
|
|
100
|
+
if (handoff === source)
|
|
101
|
+
handoff = undefined;
|
|
102
|
+
};
|
|
92
103
|
};
|
|
93
104
|
const deliverDocument = async (params, requestClient, headers, readBody) => {
|
|
94
105
|
const destination = new URL(params.request.url);
|
|
@@ -152,13 +163,38 @@ export function createRootWebViewNavigation(options) {
|
|
|
152
163
|
return {
|
|
153
164
|
isSameOriginRootNavigation,
|
|
154
165
|
preserveNavigationSource,
|
|
166
|
+
prepareShellReload() {
|
|
167
|
+
if (disposed ||
|
|
168
|
+
!options.keepSameOriginNavigation ||
|
|
169
|
+
rootFrameId ||
|
|
170
|
+
!mainFrame ||
|
|
171
|
+
!/^https?:/.test(mainFrame.url) ||
|
|
172
|
+
!/^(text\/html|application\/xhtml\+xml)$/.test(mainFrame.mimeType ?? ''))
|
|
173
|
+
return;
|
|
174
|
+
const url = new URL(mainFrame.url);
|
|
175
|
+
// Reload URLs with parameters or fragments through the normal top navigation, including login callbacks.
|
|
176
|
+
if (url.search || url.hash || mainFrame.urlFragment)
|
|
177
|
+
return;
|
|
178
|
+
const reload = {
|
|
179
|
+
url: url.href,
|
|
180
|
+
expiresAt: Date.now() + DOCUMENT_TTL_MS,
|
|
181
|
+
stage: 'request',
|
|
182
|
+
};
|
|
183
|
+
shellReload = reload;
|
|
184
|
+
return () => {
|
|
185
|
+
if (shellReload === reload)
|
|
186
|
+
shellReload = undefined;
|
|
187
|
+
};
|
|
188
|
+
},
|
|
155
189
|
allowLocalReload(frameId, url) {
|
|
156
190
|
const destination = new URL(url);
|
|
157
191
|
destination.hash = '';
|
|
158
192
|
const reload = { frameId, url: destination.href };
|
|
159
193
|
localReload = reload;
|
|
160
|
-
return () => {
|
|
161
|
-
localReload
|
|
194
|
+
return () => {
|
|
195
|
+
if (localReload === reload)
|
|
196
|
+
localReload = undefined;
|
|
197
|
+
};
|
|
162
198
|
},
|
|
163
199
|
dispose() {
|
|
164
200
|
disposed = true;
|
|
@@ -166,15 +202,17 @@ export function createRootWebViewNavigation(options) {
|
|
|
166
202
|
clearDocument();
|
|
167
203
|
handoff = undefined;
|
|
168
204
|
localReload = undefined;
|
|
205
|
+
shellReload = undefined;
|
|
169
206
|
directChildFrames.clear();
|
|
170
207
|
},
|
|
171
208
|
initialize(tree) {
|
|
172
209
|
mainFrame = tree.frame;
|
|
173
210
|
const root = tree.childFrames?.find(child => child.frame.name === '__mearl_root__')?.frame;
|
|
174
211
|
rootFrameId = root?.id;
|
|
175
|
-
committedRoot =
|
|
176
|
-
|
|
177
|
-
|
|
212
|
+
committedRoot =
|
|
213
|
+
root && /^https?:/.test(root.url)
|
|
214
|
+
? { id: root.id, origin: new URL(root.url).origin }
|
|
215
|
+
: undefined;
|
|
178
216
|
directChildFrames.clear();
|
|
179
217
|
for (const child of tree.childFrames ?? [])
|
|
180
218
|
directChildFrames.add(child.frame.id);
|
|
@@ -184,6 +222,12 @@ export function createRootWebViewNavigation(options) {
|
|
|
184
222
|
if (method === 'Page.frameNavigated' && params.frame) {
|
|
185
223
|
const frame = params.frame;
|
|
186
224
|
if (!frame.parentId) {
|
|
225
|
+
if (shellReload?.stage === 'commit' && shellReload.url === frame.url) {
|
|
226
|
+
shellReload.stage = 'webview';
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
shellReload = undefined;
|
|
230
|
+
}
|
|
187
231
|
mainFrame = frame;
|
|
188
232
|
rootFrameId = undefined;
|
|
189
233
|
committedRoot = undefined;
|
|
@@ -198,7 +242,8 @@ export function createRootWebViewNavigation(options) {
|
|
|
198
242
|
const hasPreviousDocument = committedRoot?.id === frame.id;
|
|
199
243
|
const destination = new URL(frame.url);
|
|
200
244
|
committedRoot = { id: frame.id, origin: destination.origin };
|
|
201
|
-
if (hasPreviousDocument &&
|
|
245
|
+
if (hasPreviousDocument &&
|
|
246
|
+
!destination.pathname.startsWith(DOCUMENT_PREFIX) &&
|
|
202
247
|
/^https?:/.test(mainFrame.url) &&
|
|
203
248
|
destination.origin === new URL(mainFrame.url).origin) {
|
|
204
249
|
if (frame.urlFragment !== undefined)
|
|
@@ -280,8 +325,58 @@ export function createRootWebViewNavigation(options) {
|
|
|
280
325
|
}
|
|
281
326
|
return true;
|
|
282
327
|
}
|
|
283
|
-
if (
|
|
284
|
-
|
|
328
|
+
if (shellReload && Date.now() >= shellReload.expiresAt)
|
|
329
|
+
shellReload = undefined;
|
|
330
|
+
if (shellReload?.stage === 'request' && !responseStage && params.frameId === mainFrame?.id) {
|
|
331
|
+
const reload = shellReload;
|
|
332
|
+
shellReload = undefined;
|
|
333
|
+
if (params.request.method === 'GET' &&
|
|
334
|
+
!params.request.urlFragment &&
|
|
335
|
+
destination.href === reload.url) {
|
|
336
|
+
const headers = await options.shellHeaders(true);
|
|
337
|
+
if (!headers ||
|
|
338
|
+
disposed ||
|
|
339
|
+
params.frameId !== mainFrame?.id ||
|
|
340
|
+
mainFrame.url !== reload.url)
|
|
341
|
+
return false;
|
|
342
|
+
reload.stage = 'commit';
|
|
343
|
+
shellReload = reload;
|
|
344
|
+
try {
|
|
345
|
+
await requestClient.sendCommand('Fetch.fulfillRequest', {
|
|
346
|
+
requestId: params.requestId,
|
|
347
|
+
responseCode: 200,
|
|
348
|
+
responseHeaders: [
|
|
349
|
+
{ name: 'Content-Type', value: 'text/html; charset=utf-8' },
|
|
350
|
+
{ name: 'Cache-Control', value: 'no-store' },
|
|
351
|
+
...headers,
|
|
352
|
+
{ name: 'Server-Timing', value: 'mearl-device-shell-start' },
|
|
353
|
+
],
|
|
354
|
+
body: SHELL_BODY,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
if (shellReload === reload)
|
|
359
|
+
shellReload = undefined;
|
|
360
|
+
throw error;
|
|
361
|
+
}
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (shellReload?.stage === 'webview' &&
|
|
366
|
+
!responseStage &&
|
|
367
|
+
params.request.method === 'GET' &&
|
|
368
|
+
destination.href === shellReload.url &&
|
|
369
|
+
directChildFrames.has(params.frameId)) {
|
|
370
|
+
// The shell contains a single initial WebView. Register it before its request can redirect.
|
|
371
|
+
rootFrameId = params.frameId;
|
|
372
|
+
committedRoot = { id: params.frameId, origin: destination.origin };
|
|
373
|
+
shellReload = undefined;
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
if (!responseStage &&
|
|
377
|
+
params.request.method === 'GET' &&
|
|
378
|
+
params.frameId === localReload?.frameId &&
|
|
379
|
+
destination.href === localReload.url) {
|
|
285
380
|
localReload = undefined;
|
|
286
381
|
return false;
|
|
287
382
|
}
|
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