@mearl/browser-core 3.1.8 → 3.1.10
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/rootWebViewNavigation.d.ts +4 -1
- package/dist/rootWebViewNavigation.js +23 -20
- package/dist/toolbox.d.ts +38 -2
- package/dist/toolbox.js +3 -0
- package/package.json +1 -1
|
@@ -63,7 +63,10 @@ export interface WebViewFrameEvent {
|
|
|
63
63
|
export declare function createRootWebViewNavigation(options: RootWebViewNavigationOptions): {
|
|
64
64
|
isSameOriginRootNavigation: (params: WebViewNavigationRequest) => boolean;
|
|
65
65
|
preserveNavigationSource: ({ request }: WebViewNavigationRequest) => (() => void);
|
|
66
|
-
prepareShellReload(
|
|
66
|
+
prepareShellReload(currentUrl: string): {
|
|
67
|
+
url: string;
|
|
68
|
+
cancel(): void;
|
|
69
|
+
} | undefined;
|
|
67
70
|
allowLocalReload(frameId: string, url: string): () => void;
|
|
68
71
|
dispose(): void;
|
|
69
72
|
initialize(tree: WebViewFrameTree): void;
|
|
@@ -58,7 +58,6 @@ export function createRootWebViewNavigation(options) {
|
|
|
58
58
|
let shellReload;
|
|
59
59
|
let mainFrame;
|
|
60
60
|
let rootFrameId;
|
|
61
|
-
let firstWebViewRequestId;
|
|
62
61
|
let committedRoot;
|
|
63
62
|
const directChildFrames = new Set();
|
|
64
63
|
let navigationHops = 0;
|
|
@@ -164,27 +163,33 @@ export function createRootWebViewNavigation(options) {
|
|
|
164
163
|
return {
|
|
165
164
|
isSameOriginRootNavigation,
|
|
166
165
|
preserveNavigationSource,
|
|
167
|
-
prepareShellReload(
|
|
166
|
+
prepareShellReload(currentUrl) {
|
|
168
167
|
if (disposed ||
|
|
169
168
|
!options.keepSameOriginNavigation ||
|
|
170
169
|
rootFrameId ||
|
|
171
170
|
!mainFrame ||
|
|
171
|
+
!/^https?:/.test(currentUrl) ||
|
|
172
172
|
!/^https?:/.test(mainFrame.url) ||
|
|
173
173
|
!/^(text\/html|application\/xhtml\+xml)$/.test(mainFrame.mimeType ?? ''))
|
|
174
174
|
return;
|
|
175
|
-
const url = new URL(
|
|
176
|
-
|
|
177
|
-
if (url.hash || mainFrame.urlFragment || (url.search && url.href !== directNavigationUrl))
|
|
175
|
+
const url = new URL(currentUrl);
|
|
176
|
+
if (url.origin !== new URL(mainFrame.url).origin)
|
|
178
177
|
return;
|
|
178
|
+
const fragment = url.hash;
|
|
179
|
+
url.hash = '';
|
|
179
180
|
const reload = {
|
|
180
181
|
url: url.href,
|
|
182
|
+
fragment,
|
|
181
183
|
expiresAt: Date.now() + DOCUMENT_TTL_MS,
|
|
182
184
|
stage: 'request',
|
|
183
185
|
};
|
|
184
186
|
shellReload = reload;
|
|
185
|
-
return
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
return {
|
|
188
|
+
url: reload.url,
|
|
189
|
+
cancel() {
|
|
190
|
+
if (shellReload === reload)
|
|
191
|
+
shellReload = undefined;
|
|
192
|
+
},
|
|
188
193
|
};
|
|
189
194
|
},
|
|
190
195
|
allowLocalReload(frameId, url) {
|
|
@@ -231,7 +236,6 @@ export function createRootWebViewNavigation(options) {
|
|
|
231
236
|
}
|
|
232
237
|
mainFrame = frame;
|
|
233
238
|
rootFrameId = undefined;
|
|
234
|
-
firstWebViewRequestId = undefined;
|
|
235
239
|
committedRoot = undefined;
|
|
236
240
|
directChildFrames.clear();
|
|
237
241
|
}
|
|
@@ -240,7 +244,6 @@ export function createRootWebViewNavigation(options) {
|
|
|
240
244
|
if (frame.id === rootFrameId || frame.name === '__mearl_root__') {
|
|
241
245
|
rootFrameId = frame.id;
|
|
242
246
|
if (/^https?:/.test(frame.url)) {
|
|
243
|
-
firstWebViewRequestId = undefined;
|
|
244
247
|
navigationHops = 0;
|
|
245
248
|
const hasPreviousDocument = committedRoot?.id === frame.id;
|
|
246
249
|
const destination = new URL(frame.url);
|
|
@@ -332,16 +335,14 @@ export function createRootWebViewNavigation(options) {
|
|
|
332
335
|
shellReload = undefined;
|
|
333
336
|
if (shellReload?.stage === 'request' && !responseStage && params.frameId === mainFrame?.id) {
|
|
334
337
|
const reload = shellReload;
|
|
338
|
+
const frame = mainFrame;
|
|
335
339
|
shellReload = undefined;
|
|
336
340
|
if (params.request.method === 'GET' &&
|
|
337
341
|
!params.redirectedRequestId &&
|
|
338
342
|
!params.request.urlFragment &&
|
|
339
343
|
destination.href === reload.url) {
|
|
340
344
|
const headers = await options.shellHeaders(true);
|
|
341
|
-
if (!headers ||
|
|
342
|
-
disposed ||
|
|
343
|
-
params.frameId !== mainFrame?.id ||
|
|
344
|
-
mainFrame.url !== reload.url)
|
|
345
|
+
if (!headers || disposed || mainFrame !== frame)
|
|
345
346
|
return false;
|
|
346
347
|
reload.stage = 'commit';
|
|
347
348
|
shellReload = reload;
|
|
@@ -353,7 +354,12 @@ export function createRootWebViewNavigation(options) {
|
|
|
353
354
|
{ name: 'Content-Type', value: 'text/html; charset=utf-8' },
|
|
354
355
|
{ name: 'Cache-Control', value: 'no-store' },
|
|
355
356
|
...headers,
|
|
356
|
-
{
|
|
357
|
+
{
|
|
358
|
+
name: 'Server-Timing',
|
|
359
|
+
value: reload.fragment
|
|
360
|
+
? `mearl-device-shell-start;desc="${encodeURIComponent(reload.fragment)}"`
|
|
361
|
+
: 'mearl-device-shell-start',
|
|
362
|
+
},
|
|
357
363
|
],
|
|
358
364
|
body: SHELL_BODY,
|
|
359
365
|
});
|
|
@@ -372,9 +378,8 @@ export function createRootWebViewNavigation(options) {
|
|
|
372
378
|
!params.redirectedRequestId &&
|
|
373
379
|
destination.href === shellReload.url &&
|
|
374
380
|
directChildFrames.has(params.frameId)) {
|
|
375
|
-
//
|
|
381
|
+
// Register the shell's initial WebView before applying the regular navigation rules.
|
|
376
382
|
rootFrameId = params.frameId;
|
|
377
|
-
firstWebViewRequestId = params.requestId;
|
|
378
383
|
committedRoot = { id: params.frameId, origin: destination.origin };
|
|
379
384
|
shellReload = undefined;
|
|
380
385
|
return false;
|
|
@@ -414,14 +419,12 @@ export function createRootWebViewNavigation(options) {
|
|
|
414
419
|
if (responseStage || params.frameId !== rootFrameId || params.request.method !== 'GET')
|
|
415
420
|
return false;
|
|
416
421
|
const current = new URL(mainFrame.url);
|
|
417
|
-
const redirectedFromFirstRequest = firstWebViewRequestId !== undefined && params.redirectedRequestId === firstWebViewRequestId;
|
|
418
422
|
if (!/^https?:$/.test(current.protocol) ||
|
|
419
|
-
|
|
423
|
+
isSameOriginRootNavigation(params) ||
|
|
420
424
|
(await options.preserveOrigin?.(current, destination)))
|
|
421
425
|
return false;
|
|
422
426
|
if (navigationHops >= 20)
|
|
423
427
|
return false;
|
|
424
|
-
firstWebViewRequestId = undefined;
|
|
425
428
|
await requestClient.sendCommand('Fetch.fulfillRequest', {
|
|
426
429
|
requestId: params.requestId,
|
|
427
430
|
responseCode: 204,
|
package/dist/toolbox.d.ts
CHANGED
|
@@ -59,9 +59,36 @@ export interface ToolboxToolInvokeOptions {
|
|
|
59
59
|
command: string;
|
|
60
60
|
input?: Record<string, unknown>;
|
|
61
61
|
}
|
|
62
|
-
export
|
|
63
|
-
|
|
62
|
+
export declare const TOOLBOX_RESULT_CHUNK_BYTES: number;
|
|
63
|
+
export declare const TOOLBOX_RESULT_MAX_BYTES: number;
|
|
64
|
+
export interface ToolboxResultReference {
|
|
65
|
+
kind: 'resource';
|
|
66
|
+
resultId: string;
|
|
67
|
+
bytes: number;
|
|
68
|
+
sha256: string;
|
|
69
|
+
chunks: number;
|
|
70
|
+
}
|
|
71
|
+
export interface ToolboxResultChunk extends Omit<ToolboxResultReference, 'kind'> {
|
|
72
|
+
index: number;
|
|
73
|
+
data: string;
|
|
64
74
|
}
|
|
75
|
+
export type ToolboxJsonReply = {
|
|
76
|
+
kind: 'value';
|
|
77
|
+
value: unknown;
|
|
78
|
+
} | ToolboxResultReference;
|
|
79
|
+
export type ToolboxToolInvokeResult = {
|
|
80
|
+
result: unknown;
|
|
81
|
+
} | {
|
|
82
|
+
resource: ToolboxResultReference;
|
|
83
|
+
};
|
|
84
|
+
export type ToolboxResultRequest = {
|
|
85
|
+
resultId: string;
|
|
86
|
+
} & ({
|
|
87
|
+
operation: 'result_chunk';
|
|
88
|
+
index: number;
|
|
89
|
+
} | {
|
|
90
|
+
operation: 'result_release';
|
|
91
|
+
});
|
|
65
92
|
export interface ToolboxTaskOptions {
|
|
66
93
|
id: string;
|
|
67
94
|
taskId: string;
|
|
@@ -182,6 +209,14 @@ export interface ToolboxServiceActionMap {
|
|
|
182
209
|
request: ToolboxToolInvokeOptions;
|
|
183
210
|
response: ToolboxToolInvokeResult;
|
|
184
211
|
};
|
|
212
|
+
toolbox_tool_result: {
|
|
213
|
+
request: {
|
|
214
|
+
id: string;
|
|
215
|
+
} & ToolboxResultRequest;
|
|
216
|
+
response: ToolboxResultChunk | {
|
|
217
|
+
released: true;
|
|
218
|
+
};
|
|
219
|
+
};
|
|
185
220
|
toolbox_task: {
|
|
186
221
|
request: ToolboxTaskRequest;
|
|
187
222
|
response: ToolboxTaskOperations[keyof ToolboxTaskOperations]['response'];
|
|
@@ -200,6 +235,7 @@ export declare const TOOLBOX_SERVICE_ACTIONS: {
|
|
|
200
235
|
readonly toolbox_skill_set_enabled: true;
|
|
201
236
|
readonly toolbox_tool_page_chunk: true;
|
|
202
237
|
readonly toolbox_tool_invoke: true;
|
|
238
|
+
readonly toolbox_tool_result: true;
|
|
203
239
|
readonly toolbox_task: true;
|
|
204
240
|
};
|
|
205
241
|
export declare function isToolboxServiceAction(value: unknown): value is ToolboxServiceAction;
|
package/dist/toolbox.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export const TOOLBOX_RESULT_CHUNK_BYTES = 192 * 1024;
|
|
2
|
+
export const TOOLBOX_RESULT_MAX_BYTES = 24 * 1024 * 1024;
|
|
1
3
|
export const TOOLBOX_SERVICE_ACTIONS = {
|
|
2
4
|
toolbox_page: true,
|
|
3
5
|
toolbox_state: true,
|
|
@@ -8,6 +10,7 @@ export const TOOLBOX_SERVICE_ACTIONS = {
|
|
|
8
10
|
toolbox_skill_set_enabled: true,
|
|
9
11
|
toolbox_tool_page_chunk: true,
|
|
10
12
|
toolbox_tool_invoke: true,
|
|
13
|
+
toolbox_tool_result: true,
|
|
11
14
|
toolbox_task: true,
|
|
12
15
|
};
|
|
13
16
|
export function isToolboxServiceAction(value) {
|
package/package.json
CHANGED