NavigationPreloadManager.getState()
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
getState()
Return Value
A Promise that resolves with an object that has the following properties:
enabled-
trueif preloading is enabled, andfalseotherwise. headerValue-
A string containing the value that will be sent in the
Service-Worker-Navigation-PreloadHTTP header following a preloadingfetch(). This defaults totrueunless the value was changed usingNavigationPreloadManager.setHeaderValue().
Exceptions
InvalidStateErrorDOMException-
There is no active worker associated with the registration to which this
NavigationPreloadManagerbelongs.
Examples
The code below shows a request for the current state, made once the service worker is ready.
navigator.serviceWorker.ready
.then((registration) => {
return 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
No specification found
No specification data found for api.NavigationPreloadManager.getState.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.
Browser compatibility
BCD tables only load in the browser