diff --git a/src/bidiMapper/modules/context/BrowsingContextImpl.ts b/src/bidiMapper/modules/context/BrowsingContextImpl.ts index ab03243ebe..dd2b08d3af 100644 --- a/src/bidiMapper/modules/context/BrowsingContextImpl.ts +++ b/src/bidiMapper/modules/context/BrowsingContextImpl.ts @@ -73,6 +73,9 @@ export class BrowsingContextImpl { readonly #eventManager: EventManager; readonly #realmStorage: RealmStorage; #loaderId?: Protocol.Network.LoaderId; + // Used when no loaderId is available, e.g. for same-document navigations. Updated on + // each navigation. + #fakeNavigationId: string = uuidv4(); #cdpTarget: CdpTarget; #maybeDefaultRealm?: Realm; readonly #logger?: LoggerFn; @@ -333,6 +336,8 @@ export class BrowsingContextImpl { // previous page are detached and realms are destroyed. // Remove children from context. this.#deleteAllChildren(); + // Reset the fake navigation ID. + this.#fakeNavigationId = uuidv4(); }); this.#cdpTarget.cdpClient.on('Page.navigatedWithinDocument', (params) => { @@ -349,13 +354,15 @@ export class BrowsingContextImpl { method: ChromiumBidi.BrowsingContext.EventNames.FragmentNavigated, params: { context: this.id, - navigation: null, + navigation: this.#fakeNavigationId, timestamp, url: this.#url, }, }, this.id ); + // Reset the fake navigation ID. + this.#fakeNavigationId = uuidv4(); }); this.#cdpTarget.cdpClient.on('Page.frameStartedLoading', (params) => { @@ -368,6 +375,8 @@ export class BrowsingContextImpl { method: ChromiumBidi.BrowsingContext.EventNames.NavigationStarted, params: { context: this.id, + // No `navigation` available yet, but `fakeNavigationId` cannot be used, as it + // can be a real navigation. navigation: null, timestamp: BrowsingContextImpl.getTimestamp(), url: '', @@ -414,7 +423,7 @@ export class BrowsingContextImpl { method: ChromiumBidi.BrowsingContext.EventNames.DomContentLoaded, params: { context: this.id, - navigation: this.#loaderId ?? null, + navigation: this.#loaderId, timestamp, url: this.#url, }, @@ -431,7 +440,7 @@ export class BrowsingContextImpl { method: ChromiumBidi.BrowsingContext.EventNames.Load, params: { context: this.id, - navigation: this.#loaderId ?? null, + navigation: this.#loaderId, timestamp, url: this.#url, }, @@ -667,9 +676,9 @@ export class BrowsingContextImpl { return { // Missing `loaderId` means same-document navigation. However, WebDriver BiDi spec - // requires a unique navigation ID for each navigation, so generate a new one. - // Note: this navigation is not shared with the network domain. - navigation: cdpNavigateResult.loaderId ?? uuidv4(), + // requires a unique navigation ID for each navigation, so use `fakeNavigationId` + // which is unique for each navigation. + navigation: cdpNavigateResult.loaderId ?? this.#fakeNavigationId, // Url can change due to redirect get the latest one. url: wait === BrowsingContext.ReadinessState.None ? url : this.#url, };