Skip to content

Instantly share code, notes, and snippets.

@EduardoAC
Last active February 11, 2024 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EduardoAC/9bef28da89d3a1144d98a312acd6164d to your computer and use it in GitHub Desktop.
Save EduardoAC/9bef28da89d3a1144d98a312acd6164d to your computer and use it in GitHub Desktop.
Example retrieving language from client-side cookie when initialising service worker
try {
const languageCookieFromWebApp: chrome.cookies.Cookie | null =
await chrome.cookies.get({
url: `${your - webApp - url}`, // Remember taht URL change for localhost and live
name: "{your-webApp-name}-language",
});
if (languageCookieFromWebApp) {
const language = languageCookieFromWebApp.value
if (language) {
chrome.storage.local.set({ language });
}
}
} catch (error: unknown) {
console.error("Failed to initialise isSkimlinksEmployee cookie in cache", error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment