I wish to make a fetch call after the push event for fetching the notif data through an internal api with user specific params which are stored in the localstorage or cookie such as usertype or country id .. how do i do this ?
Note: localStorage works in a similar way to service worker cache, but it is synchronous, so not allowed in service workers.
In addition, the reliance on document means that cookies cannot be accessed by service workers which cannot access the document object. The Cookie Store API provides an updated method of managing cookies.
If you need to store data that is accessible for both the server and the client, use cookies. Otherwise, use local storage. If you need to store larger data, use local storage. If you need to store data that does not expire, use local storage.
No, localStorage and sessionStorage are both undefined in a webworker process. You would have to call postMessage() back to the Worker's originating code, and have that code store the data in localStorage.
You cannot use Local Storage in service workers. It was decided that service workers should not have access to any synchronous APIs. You can use IndexedDB instead, or communicate with the controlled page using postMessage()
.
By default, cookies are not included with fetch
requests, but you can include them as follows: fetch(url, {credentials: 'include'})
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With