Skip to content

Commit

Permalink
Use same fake navigation id for same document navigation events
Browse files Browse the repository at this point in the history
  • Loading branch information
sadym-chromium committed May 31, 2024
1 parent 3992546 commit 3a105a6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/bidiMapper/modules/context/BrowsingContextImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand All @@ -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: '',
Expand Down Expand Up @@ -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,
},
Expand All @@ -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,
},
Expand Down Expand Up @@ -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,
};
Expand Down

0 comments on commit 3a105a6

Please sign in to comment.