files/en-us/web/api/navigationpreloadmanager/getstate/index.md
{{APIRef("Service Workers API")}}{{SecureContext_Header}}{{AvailableInWorkers}}
The getState() method of the {{domxref("NavigationPreloadManager")}} interface returns a {{jsxref("Promise")}} that resolves to an object with properties that indicate whether preload is enabled and what value will be sent in the {{HTTPHeader("Service-Worker-Navigation-Preload")}} HTTP header.
getState()
None.
A {{jsxref("Promise")}} that resolves with an object that has the following properties:
enabled
true if preloading is enabled, and false otherwise.headerValue
Service-Worker-Navigation-Preload HTTP header following a preloading {{domxref("Window/fetch", "fetch()")}}.
This defaults to true unless the value was changed using {{domxref("NavigationPreloadManager.setHeaderValue()")}}.InvalidStateError {{domxref("DOMException")}}
The code below shows a request for the current state, made once the service worker is ready.
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}}
{{Compat}}