Skip to content

fix: properly patch private-window localStorage and cookie logic - #36

Merged
JesseKoldewijn merged 3 commits into
developfrom
fix/private-window-storage-logic
Aug 27, 2026
Merged

fix: properly patch private-window localStorage and cookie logic#36
JesseKoldewijn merged 3 commits into
developfrom
fix/private-window-storage-logic

Conversation

@JesseKoldewijn

@JesseKoldewijn JesseKoldewijn commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • localStorage injection (background.ts): Changed all three injected MAIN-world scripts (APPLY_LS, REMOVE_LS, GET_LS) from bare calls to try/catch wrappers that return structured results. Added a module-level privateWindowStorage: Map<number, Map<string, string>> as an in-memory fallback — when QuotaExceededError/SecurityError signals storage is blocked (Safari private mode, storage-disabled Chrome), writes land in memory and reads fall back to memory. The tab-close listener already in place now also clears per-tab memory.
  • Cookie store silent fallback (parameterApplicator.ts): getTabCookieStoreId now warns when an incognito tab's store can't be found instead of silently returning undefined and targeting the wrong store.
  • featureFlags.ts localStorage guard: Replaced typeof localStorage === "undefined" checks (which pass in private mode — localStorage exists but throws) with try/catch in getEffectiveProfile, getForceProfile, and setForceProfile.
  • New reason: "storage_unavailable" response code wired through buildScriptErrorResponselogIncognitoLocalStorageError so callers see a clear message about the in-memory fallback being used.

What PR #35 missed

PR #35 (commit bdd9cae) only added diagnostics for localStorage — the injected scripts still had no try/catch, so QuotaExceededError was misclassified and there was no recovery. This PR adds the actual fallback.

Test plan

  • yarn test — 1010 tests, all passing (39 test files)
  • yarn type-check — clean
  • New test/unit/entrypoints/background.test.ts proves the memory fallback for all three operations, isolation per tabId, and the apply→get→remove round-trip through memory
  • test/unit/logic/featureFlags.test.ts extended with private-window localStorage throwing scenarios
  • test/unit/logic/parameters/parameterApplicator.test.ts extended with incognito cookie storeId and storage_unavailable warning tests

JesseKoldewijn and others added 3 commits August 27, 2026 16:06
- Replace bare injected localStorage scripts with try/catch wrappers
  that return structured results; add in-memory fallback (per-tab Map)
  when QuotaExceededError/SecurityError signals storage is unavailable
- Expose handleApplyLS/handleRemoveLS/handleGetLS as named exports for
  direct unit-testing without message-routing overhead
- Clean up per-tab memory in the existing tabs.onRemoved listener
- Add storage_unavailable reason code and surface it via
  logIncognitoLocalStorageError in parameterApplicator
- Warn when getTabCookieStoreId cannot locate the incognito cookie store
  instead of silently falling back to the wrong store
- Replace typeof localStorage === "undefined" guards in featureFlags.ts
  with try/catch so private-window throws are caught rather than
  propagating uncaught
- Add test/unit/entrypoints/background.test.ts proving memory fallback
  behaviour; extend featureFlags and parameterApplicator tests with
  private-window scenarios

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sonarjs/no-undefined-argument — call isStorageUnavailableError() with
no argument instead of explicitly passing undefined.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ator test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

CI Summary

Coverage Reports

Type Download
Unit Tests Download
E2E Tests (development) Download

Build Artifacts

Profile Download
development Download

Note: Artifacts expire after 7 days.

@JesseKoldewijn
JesseKoldewijn merged commit 45bb2e2 into develop Aug 27, 2026
7 checks passed
@agnostic-devkit-release

Copy link
Copy Markdown

🎉 This PR is included in version 1.5.1-canary.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant