@mearl/browser-core 3.1.8-beta.2 → 3.1.8-beta.4
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.
|
@@ -3,6 +3,7 @@ export interface WebViewNavigationClient {
|
|
|
3
3
|
}
|
|
4
4
|
export interface WebViewNavigationRequest {
|
|
5
5
|
requestId: string;
|
|
6
|
+
redirectedRequestId?: string;
|
|
6
7
|
frameId?: string;
|
|
7
8
|
resourceType?: string;
|
|
8
9
|
responseStatusCode?: number;
|
|
@@ -62,7 +63,7 @@ export interface WebViewFrameEvent {
|
|
|
62
63
|
export declare function createRootWebViewNavigation(options: RootWebViewNavigationOptions): {
|
|
63
64
|
isSameOriginRootNavigation: (params: WebViewNavigationRequest) => boolean;
|
|
64
65
|
preserveNavigationSource: ({ request }: WebViewNavigationRequest) => (() => void);
|
|
65
|
-
prepareShellReload(): (() => void) | undefined;
|
|
66
|
+
prepareShellReload(directNavigationUrl?: string): (() => void) | undefined;
|
|
66
67
|
allowLocalReload(frameId: string, url: string): () => void;
|
|
67
68
|
dispose(): void;
|
|
68
69
|
initialize(tree: WebViewFrameTree): void;
|
|
@@ -58,6 +58,7 @@ export function createRootWebViewNavigation(options) {
|
|
|
58
58
|
let shellReload;
|
|
59
59
|
let mainFrame;
|
|
60
60
|
let rootFrameId;
|
|
61
|
+
let firstWebViewRequestId;
|
|
61
62
|
let committedRoot;
|
|
62
63
|
const directChildFrames = new Set();
|
|
63
64
|
let navigationHops = 0;
|
|
@@ -163,7 +164,7 @@ export function createRootWebViewNavigation(options) {
|
|
|
163
164
|
return {
|
|
164
165
|
isSameOriginRootNavigation,
|
|
165
166
|
preserveNavigationSource,
|
|
166
|
-
prepareShellReload() {
|
|
167
|
+
prepareShellReload(directNavigationUrl) {
|
|
167
168
|
if (disposed ||
|
|
168
169
|
!options.keepSameOriginNavigation ||
|
|
169
170
|
rootFrameId ||
|
|
@@ -172,8 +173,8 @@ export function createRootWebViewNavigation(options) {
|
|
|
172
173
|
!/^(text\/html|application\/xhtml\+xml)$/.test(mainFrame.mimeType ?? ''))
|
|
173
174
|
return;
|
|
174
175
|
const url = new URL(mainFrame.url);
|
|
175
|
-
//
|
|
176
|
-
if (url.
|
|
176
|
+
// A parameterized URL needs evidence of a direct visit to the current document.
|
|
177
|
+
if (url.hash || mainFrame.urlFragment || (url.search && url.href !== directNavigationUrl))
|
|
177
178
|
return;
|
|
178
179
|
const reload = {
|
|
179
180
|
url: url.href,
|
|
@@ -230,6 +231,7 @@ export function createRootWebViewNavigation(options) {
|
|
|
230
231
|
}
|
|
231
232
|
mainFrame = frame;
|
|
232
233
|
rootFrameId = undefined;
|
|
234
|
+
firstWebViewRequestId = undefined;
|
|
233
235
|
committedRoot = undefined;
|
|
234
236
|
directChildFrames.clear();
|
|
235
237
|
}
|
|
@@ -238,6 +240,7 @@ export function createRootWebViewNavigation(options) {
|
|
|
238
240
|
if (frame.id === rootFrameId || frame.name === '__mearl_root__') {
|
|
239
241
|
rootFrameId = frame.id;
|
|
240
242
|
if (/^https?:/.test(frame.url)) {
|
|
243
|
+
firstWebViewRequestId = undefined;
|
|
241
244
|
navigationHops = 0;
|
|
242
245
|
const hasPreviousDocument = committedRoot?.id === frame.id;
|
|
243
246
|
const destination = new URL(frame.url);
|
|
@@ -331,6 +334,7 @@ export function createRootWebViewNavigation(options) {
|
|
|
331
334
|
const reload = shellReload;
|
|
332
335
|
shellReload = undefined;
|
|
333
336
|
if (params.request.method === 'GET' &&
|
|
337
|
+
!params.redirectedRequestId &&
|
|
334
338
|
!params.request.urlFragment &&
|
|
335
339
|
destination.href === reload.url) {
|
|
336
340
|
const headers = await options.shellHeaders(true);
|
|
@@ -365,10 +369,12 @@ export function createRootWebViewNavigation(options) {
|
|
|
365
369
|
if (shellReload?.stage === 'webview' &&
|
|
366
370
|
!responseStage &&
|
|
367
371
|
params.request.method === 'GET' &&
|
|
372
|
+
!params.redirectedRequestId &&
|
|
368
373
|
destination.href === shellReload.url &&
|
|
369
374
|
directChildFrames.has(params.frameId)) {
|
|
370
375
|
// The shell contains a single initial WebView. Register it before its request can redirect.
|
|
371
376
|
rootFrameId = params.frameId;
|
|
377
|
+
firstWebViewRequestId = params.requestId;
|
|
372
378
|
committedRoot = { id: params.frameId, origin: destination.origin };
|
|
373
379
|
shellReload = undefined;
|
|
374
380
|
return false;
|
|
@@ -408,12 +414,14 @@ export function createRootWebViewNavigation(options) {
|
|
|
408
414
|
if (responseStage || params.frameId !== rootFrameId || params.request.method !== 'GET')
|
|
409
415
|
return false;
|
|
410
416
|
const current = new URL(mainFrame.url);
|
|
417
|
+
const redirectedFromFirstRequest = firstWebViewRequestId !== undefined && params.redirectedRequestId === firstWebViewRequestId;
|
|
411
418
|
if (!/^https?:$/.test(current.protocol) ||
|
|
412
|
-
isSameOriginRootNavigation(params) ||
|
|
419
|
+
(!redirectedFromFirstRequest && isSameOriginRootNavigation(params)) ||
|
|
413
420
|
(await options.preserveOrigin?.(current, destination)))
|
|
414
421
|
return false;
|
|
415
422
|
if (navigationHops >= 20)
|
|
416
423
|
return false;
|
|
424
|
+
firstWebViewRequestId = undefined;
|
|
417
425
|
await requestClient.sendCommand('Fetch.fulfillRequest', {
|
|
418
426
|
requestId: params.requestId,
|
|
419
427
|
responseCode: 204,
|
package/package.json
CHANGED