Skip to content

Fix localStorage access crash under browser Tracking Prevention#27

Draft
kenpower with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-client-storage-access
Draft

Fix localStorage access crash under browser Tracking Prevention#27
kenpower with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-client-storage-access

Conversation

Copilot AI commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Browsers with Tracking Prevention (Edge) or ITP (Safari) throw when localStorage is accessed in cross-origin contexts (e.g. after redirect from the external auth service), crashing the app before the user can log in.

Changes

  • src/lib/login.js — Added exported safeLocalStorageGet / safeLocalStorageSet helpers that catch storage-access exceptions and warn to console; replaced bare localStorage calls in loginUser() with these wrappers. Exported so other modules can reuse them.
  • src/Signin.svelte — Wrapped localStorage.setItem("google-token", ...) in handleGoogleCredential with try/catch (inline <svelte:head> script cannot use ES module imports, so the guard is applied directly).
// Before — throws in Edge/Safari with Tracking Prevention active
localStorage.setItem("user", JSON.stringify(newOrExistingUser));

// After — degrades gracefully; user is sent through auth flow on next load
safeLocalStorageSet("user", JSON.stringify(newOrExistingUser));

When storage is blocked, the app logs a warning and falls through to the normal auth redirect rather than crashing.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: kenpower <105429+kenpower@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug in client storage access due to tracking prevention Fix localStorage access crash under browser Tracking Prevention Mar 19, 2026
Copilot AI requested a review from kenpower March 19, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants