Skip to content

[Tech review] BiDi - Add pages for navigation and page load events of browsingContext module#44571

Open
dipikabh wants to merge 5 commits into
mdn:mainfrom
dipikabh:bidi-browsingcontext-nav-events
Open

[Tech review] BiDi - Add pages for navigation and page load events of browsingContext module#44571
dipikabh wants to merge 5 commits into
mdn:mainfrom
dipikabh:bidi-browsingcontext-nav-events

Conversation

@dipikabh

Copy link
Copy Markdown
Contributor

Description

This PR adds pages for the following navigation and page load events:

  • browsingContext.navigationStarted
  • browsingContext.navigationCommitted
  • browsingContext.domContentLoaded
  • browsingContext.load
  • browsingContext.navigationFailed
  • browsingContext.fragmentNavigated
  • browsingContext.historyUpdated

Note

browsingContext.navigationAborted is not documented yet. The BCD key is also missing for this event. I'll cover it when there is an implementation.

Spec links

Related issue

Doc issue: mdn/mdn#339

@dipikabh dipikabh requested review from a team as code owners June 25, 2026 00:32
@dipikabh dipikabh requested review from hamishwillee and pepelsbey and removed request for a team June 25, 2026 00:32
@github-actions github-actions Bot added Content:WebDriver WebDriver docs size/l [PR only] 501-1000 LoC changed labels Jun 25, 2026
@dipikabh dipikabh requested review from a team and removed request for hamishwillee and pepelsbey June 25, 2026 00:33
Comment on lines +33 to +34
- `userContext` {{optional_inline}}
- : A string that contains the ID of the [user context](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser#user_contexts) in which the HTML document is being parsed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking to leave this field out, but I noticed in the implementation tracker that Firefox support is coming in 154. So I've included it, though examples of all events in this PR are currently missing this field.

I would have asked for clarification on when this field is included vs. omitted in the payload - but from the comment in the spreadsheet, it seems that this field will eventually become required.

But let me know, if in the meantime, any more details need to be added here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is similar to #44121 (review) , it might be better to leave those out until they are mandatory in the spec.

We implemented it in Firefox 154, but AFAIK Chrome doesn't support it yet.

Comment on lines +44 to +55
```json
{
"type": "event",
"method": "browsingContext.navigationFailed",
"params": {
"context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa",
"navigation": "a1b2c3d4-5678-90ab-cdef-1234567890ab",
"timestamp": 1712345678901,
"url": "https://not-a-valid-domain.example"
}
}
```

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to reproduce this. I used https://not-a-valid-domain.example as the URL but this returned:

"error": "unknown error",
"message": "Error: NS_ERROR_UNKNOWN_HOST",

as a browsingContext.navigate command error rather than firing the browsingContext.navigationFailed event. The stacktrace showed #onNavigationCommitted being called.

Is the example documented here good enough? Any other variables I can tweak to trigger the event?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A navigation to an unknown host is not going to trigger navigationFailed, you can find the list of scenarios in the following comment: https://bugzilla.mozilla.org/show_bug.cgi?id=1846601#c9

The easiest to explain might be onbeforeunload where the user (or the test) rejects the unload?

Note that based on the HTML spec, there are some situations where we shouldn't emit navigationStarted (step 9 and 12 of https://html.spec.whatwg.org/#beginning-navigation, navigation started is step 18) but I'm not sure we implement that properly at the moment. I would maybe not mention navigationStarted here.

On my side: I will file a bug for your initial scenario. I'm not sure exactly how we should handle navigating to this https://not-a-valid-domain.example URL, but normally unknown error should be reserved for failed navigations, so that error looks fishy and in any case the error message means we didn't handle the navigation properly.

@juliandescottes juliandescottes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(answers for the inline questions, reviewing the rest of the PR still, thanks!)

Comment on lines +33 to +34
- `userContext` {{optional_inline}}
- : A string that contains the ID of the [user context](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser#user_contexts) in which the HTML document is being parsed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is similar to #44121 (review) , it might be better to leave those out until they are mandatory in the spec.

We implemented it in Firefox 154, but AFAIK Chrome doesn't support it yet.

Comment on lines +44 to +55
```json
{
"type": "event",
"method": "browsingContext.navigationFailed",
"params": {
"context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa",
"navigation": "a1b2c3d4-5678-90ab-cdef-1234567890ab",
"timestamp": 1712345678901,
"url": "https://not-a-valid-domain.example"
}
}
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A navigation to an unknown host is not going to trigger navigationFailed, you can find the list of scenarios in the following comment: https://bugzilla.mozilla.org/show_bug.cgi?id=1846601#c9

The easiest to explain might be onbeforeunload where the user (or the test) rejects the unload?

Note that based on the HTML spec, there are some situations where we shouldn't emit navigationStarted (step 9 and 12 of https://html.spec.whatwg.org/#beginning-navigation, navigation started is step 18) but I'm not sure we implement that properly at the moment. I would maybe not mention navigationStarted here.

On my side: I will file a bug for your initial scenario. I'm not sure exactly how we should handle navigating to this https://not-a-valid-domain.example URL, but normally unknown error should be reserved for failed navigations, so that error looks fishy and in any case the error message means we didn't handle the navigation properly.

@juliandescottes juliandescottes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just some comments on my end, will take another look once they are addressed.

- : A string that contains the [UUID](/en-US/docs/Glossary/UUID) that uniquely identifies this navigation.
This ID matches the `navigation` value in the response of the [`browsingContext.navigate`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/navigate) and [`browsingContext.reload`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/reload) commands.
- `timestamp`
- : A non-negative integer that represents the time in UTC when the event was fired, as milliseconds elapsed since the [epoch](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#the_epoch_timestamps_and_invalid_date).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it confusing to mention UTC here? This is just a number of ms since epoch, timezones should not matter.

- : A string that contains the ID of the context in which the HTML document is being parsed.
- `navigation`
- : A string that contains the [UUID](/en-US/docs/Glossary/UUID) that uniquely identifies this navigation.
This ID matches the `navigation` value in the response of the [`browsingContext.navigate`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/navigate) and [`browsingContext.reload`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/reload) commands.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general note, navigation (and navigation events) can be triggered by other means than calling navigate or reload. Maybe hint at that by saying "if the navigation was started through a command". Otherwise it might give the impression that the navigation id is not going to be set for navigations which were not initiated by the command?

Could also be nice to mention that the navigation id is shared by all the events related to this navigation: that is all browsingContext navigation events, as well as the network events.


## Description

In the lifecycle of a failed navigation, this event fires after [`browsingContext.navigationStarted`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/navigationStarted) when the navigation cannot be completed.

@juliandescottes juliandescottes Jun 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot be completed is too vague, but at the same time I don't have a good short definition for this. Based on the list of examples, we could say that the navigation is blocked (could be for security/csp reason, because the user canceled the unload prompt...)

Maybe having navigationAborted documented could help a bit, Chrome implements it AFAIK. This one is triggered when we abort a document load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebDriver WebDriver docs size/l [PR only] 501-1000 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants