NavigationPrecommitController: addHandler() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The addHandler() method of the NavigationPrecommitController interface allows you to dynamically add a handler callback function in precommit code, which will then be run after the navigation has committed.

This is useful when the navigation workflow depends on information that is not know until precommit code has started running. If the precommit and (post-commit) handler are independent, the handler can be specified in the in the options.handler argument passed to NavigateEvent.intercept().

Syntax

js
addHandler(handler);

Parameters

handler

A callback function that defines the post-commit navigation handling behavior should be; it returns a promise.

The handler callback is invoked as though it was passed to the NavigateEvent.intercept() method, and will run after the currentEntry property has been updated.

Return value

None (undefined).

Exceptions

InvalidStateError DOMException

Thrown if:

  • The originating NavigateEvent was not intercepted or has been canceled.
  • The Document is not fully active.
SecurityError DOMException

Thrown if the event isTrusted attribute is false.

Examples

For more examples see NavigationPrecommitController.

Basic usage

This example shows a precommitHandler implementation that fetches data for a page and uses addHandler() to add different handlers based on the page type (the implementations of the fetchConfig, setupVideoPlayer() and setupArticleView() are not given).

js
navigation.addEventListener("navigate", (event) => {
  event.intercept({
    async precommitHandler(controller) {
      const pageData = await fetchConfig();
      if (pageData.type === "video") {
        controller.addHandler(() => setupVideoPlayer());
      } else {
        controller.addHandler(() => setupArticleView());
      }
    },
  });
});

Specifications

Specification
HTML
# dom-navigationprecommitcontroller-addhandler

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
addHandler
Chrome – Full support
Chrome 146 (Release date: 2026-03-10)
footnote Full support
Edge – Full support
Edge 146 (Release date: 2026-03-13)
footnote Full support
Firefox – Full support
Firefox 148 (Release date: 2026-02-24)
footnote Full support
Opera – Full support
Opera 130 (Release date: 2026-04-08)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 146 (Release date: 2026-03-10)
footnote Full support
Firefox for Android – Full support
Firefox for Android 148 (Release date: 2026-02-24)
footnote Full support
Opera Android – Full support
Opera Android 97 (Release date: 2026-04-16)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 146 (Release date: 2026-03-10)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

See also