@mearl/browser-core 3.0.11 → 3.0.12
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.
|
@@ -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;
|
|
@@ -326,7 +332,7 @@ export interface BrowserCloseParams {
|
|
|
326
332
|
browser: string;
|
|
327
333
|
deleteProfile?: boolean;
|
|
328
334
|
}
|
|
329
|
-
interface BrowserProviderSchemaBase {
|
|
335
|
+
interface BrowserProviderSchemaBase extends BrowserProviderLocales<'title' | 'description' | 'placeholder'> {
|
|
330
336
|
title?: string;
|
|
331
337
|
description?: string;
|
|
332
338
|
default?: BrowserJsonValue;
|
|
@@ -354,17 +360,13 @@ export type BrowserProviderInputSchema = (BrowserProviderSchemaBase & {
|
|
|
354
360
|
maxLength?: number;
|
|
355
361
|
pattern?: string;
|
|
356
362
|
placeholder?: string;
|
|
357
|
-
options?: readonly
|
|
358
|
-
value: string;
|
|
359
|
-
label: string;
|
|
360
|
-
description?: string;
|
|
361
|
-
disabled?: boolean;
|
|
362
|
-
}[];
|
|
363
|
+
options?: readonly BrowserProviderInputOption[];
|
|
363
364
|
}) | (BrowserProviderSchemaBase & {
|
|
364
365
|
type: 'number';
|
|
365
366
|
integer?: boolean;
|
|
366
367
|
minimum?: number;
|
|
367
368
|
maximum?: number;
|
|
369
|
+
placeholder?: string;
|
|
368
370
|
}) | (BrowserProviderSchemaBase & {
|
|
369
371
|
type: 'boolean';
|
|
370
372
|
}) | (BrowserProviderSchemaBase & {
|
|
@@ -381,9 +383,15 @@ export interface BrowserProviderObjectSchema extends BrowserProviderSchemaBase {
|
|
|
381
383
|
not?: BrowserProviderObjectSchema;
|
|
382
384
|
additionalProperties?: boolean;
|
|
383
385
|
}
|
|
386
|
+
export interface BrowserProviderInputOption extends BrowserProviderLocales<'label' | 'description'> {
|
|
387
|
+
value: string;
|
|
388
|
+
label: string;
|
|
389
|
+
description?: string;
|
|
390
|
+
disabled?: boolean;
|
|
391
|
+
}
|
|
384
392
|
export interface BrowserProviderDefinition {
|
|
385
393
|
provider: BrowserProviderIdentity;
|
|
386
|
-
browserType: {
|
|
394
|
+
browserType: BrowserProviderLocales<'name'> & {
|
|
387
395
|
name: string;
|
|
388
396
|
controlSessionModes?: readonly BrowserControlSessionMode[];
|
|
389
397
|
documentationUrl?: string;
|
|
@@ -395,7 +403,7 @@ export interface BrowserProviderDefinition {
|
|
|
395
403
|
launchForm?: BrowserProviderLaunchForm;
|
|
396
404
|
};
|
|
397
405
|
}
|
|
398
|
-
export interface BrowserProviderLaunchFormVariant {
|
|
406
|
+
export interface BrowserProviderLaunchFormVariant extends BrowserProviderLocales<'title' | 'description'> {
|
|
399
407
|
id: string;
|
|
400
408
|
title: string;
|
|
401
409
|
description?: string;
|
|
@@ -404,7 +412,7 @@ export interface BrowserProviderLaunchFormVariant {
|
|
|
404
412
|
refreshOn?: readonly string[];
|
|
405
413
|
dynamicFields?: readonly string[];
|
|
406
414
|
}
|
|
407
|
-
export interface BrowserProviderLaunchForm {
|
|
415
|
+
export interface BrowserProviderLaunchForm extends BrowserProviderLocales<'message'> {
|
|
408
416
|
inputSchema: BrowserProviderObjectSchema;
|
|
409
417
|
variants?: readonly BrowserProviderLaunchFormVariant[];
|
|
410
418
|
variant?: string;
|
|
@@ -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/package.json
CHANGED