NavigationPreloadManager: getState() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2022.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

The getState() method of the NavigationPreloadManager interface returns a Promise that resolves to an object with properties that indicate whether preload is enabled and what value will be sent in the Service-Worker-Navigation-Preload HTTP header.

Syntax

js
getState()

Parameters

None.

Return value

A Promise that resolves with an object that has the following properties:

enabled

true if preloading is enabled, and false otherwise.

headerValue

A string containing the value that will be sent in the Service-Worker-Navigation-Preload HTTP header following a preloading fetch(). This defaults to true unless the value was changed using NavigationPreloadManager.setHeaderValue().

Exceptions

InvalidStateError DOMException

There is no active worker associated with the registration to which this NavigationPreloadManager belongs.

Examples

The code below shows a request for the current state, made once the service worker is ready.

js
navigator.serviceWorker.ready
  .then((registration) => registration.navigationPreload.getState())
  .then((state) => {
    console.log(state.enabled); // boolean
    console.log(state.headerValue); // string
  })
  .catch((e) =>
    console.error(`NavigationPreloadManager not supported: ${e.message}`),
  );

Specifications

Specification
Service Workers Nightly
# dom-navigationpreloadmanager-getstate

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
getState
Chrome – Full support
Chrome 59 (Release date: 2017-06-05)
footnote Full support
Edge – Full support
Edge 18 (Release date: 2018-10-02)
footnote Full support
Firefox – Full support
Firefox 99 (Release date: 2022-04-05)
footnote Full support
Opera – Full support
Opera 46 (Release date: 2017-06-22)
footnote Full support
Safari – Full support
Safari 15.4 (Release date: 2022-03-14)
footnote Full support
Chrome Android – Full support
Chrome Android 59 (Release date: 2017-06-06)
footnote Full support
Firefox for Android – Full support
Firefox for Android 99 (Release date: 2022-04-05)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 59 (Release date: 2017-06-06)
footnote Full support
WebView on iOS – Full support
WebView on iOS 15.4 (Release date: 2022-03-14)
footnote Full support

Legend

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

Full support
Full support