Skip to main content

One post tagged with "Authentication"

View all tags

Chrome Extension Service Worker Can't Read Login Token? Cross-Context Token Sync

· 3 min read

TL;DR

Chrome extension uses a sidepanel as the UI. User logs in, token goes to localStorage. But the Service Worker (background script) has no localStorage — calling it throws ReferenceError. Fix: after login, send the token to the Service Worker via chrome.runtime.sendMessage, which writes it to chrome.storage.local. Sidepanel reads localStorage, Service Worker reads chrome.storage.local.