fix: properly patch private-window localStorage and cookie logic - #36
Merged
Conversation
- 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>
Contributor
|
🎉 This PR is included in version 1.5.1-canary.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
APPLY_LS,REMOVE_LS,GET_LS) from bare calls to try/catch wrappers that return structured results. Added a module-levelprivateWindowStorage: Map<number, Map<string, string>>as an in-memory fallback — whenQuotaExceededError/SecurityErrorsignals 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.getTabCookieStoreIdnow warns when an incognito tab's store can't be found instead of silently returningundefinedand targeting the wrong store.typeof localStorage === "undefined"checks (which pass in private mode —localStorageexists but throws) withtry/catchingetEffectiveProfile,getForceProfile, andsetForceProfile.reason: "storage_unavailable"response code wired throughbuildScriptErrorResponse→logIncognitoLocalStorageErrorso 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, soQuotaExceededErrorwas 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— cleantest/unit/entrypoints/background.test.tsproves the memory fallback for all three operations, isolation per tabId, and the apply→get→remove round-trip through memorytest/unit/logic/featureFlags.test.tsextended with private-window localStorage throwing scenariostest/unit/logic/parameters/parameterApplicator.test.tsextended with incognito cookie storeId andstorage_unavailablewarning tests