I came across following lines on the service worker MDN documentation. https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API under service worker usage.
What it is that is causing local storage inaccessible inside service worker
It is designed to be fully async; as a consequence, APIs such as synchronous XHR and localStorage can't be used inside a service worker.