I need to access localstorage or cookie from withi

2019-04-19 06:09发布

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条回答
家丑人穷心不美
2楼-- · 2019-04-19 06:36

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

查看更多
登录 后发表回答