I need to access localstorage or cookie from withi

2019-04-19 05:55发布

问题:

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 ?

回答1:

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'}).