refactor: replace chrome storage api with wxt's storage api
Implements: https://github.com/supermemoryai/supermemory/issues/527
This is the initial PR. I also have some ideas to implement storage.watch() from WXT in places where an explicit refresh is currently required for changes to reflect. This can be improved by adding some reactivity. I’ll be creating the next PR shortly.
Thanks @lirena00 for the heads-up.
And I would request @MaheshtheDev or @lirena00 to test it once more in their local before merging to main
How to use the Graphite Merge Queue
Add the label Main to this PR to add it to the merge queue.
You must have a Graphite account in order to use the merge queue. Sign up using this link.
An organization admin has enabled the Graphite Merge Queue in this repository.
Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.
Apologies for the delay in my response to work on this issue, I was caught up with some personal things. I've reviewed the code, and it looks great and it does exactly what I intended. The only part missing is the .watch() functionality, which you've already noted you're working on. Since @MaheshtheDev and @Dhravya are the maintainers, I'll defer to them for the final review and approval. Thanks for the work on this!
Code Review: Refactor to WXT Storage API
Overview
This PR successfully migrates from Chrome's direct storage API to WXT's abstracted storage layer. Overall, this is a positive change that improves code maintainability and follows WXT best practices.
✅ Strengths
1. Improved Type Safety
- Storage items now have explicit TypeScript types (
UserData,Project,TwitterAuthTokens) - Eliminates string-based key lookups prone to typos
- Clear separation between local and session storage
2. Better Abstraction
- Centralized storage definitions in
utils/storage.ts - Cleaner API with
getValue(),setValue(),removeValue() - Consistent fallback values (e.g.,
autoSearchEnableddefaults tofalse)
3. Code Quality Improvements
- Reduced boilerplate with Promise.all() for concurrent operations
- Better error handling in
setupStorageListener()(apps/browser-extension/entrypoints/content/shared.ts:119) - More readable variable names (e.g.,
autoSearchvsautoSearchEnabled)
⚠️ Issues & Concerns
1. Missing Import Statement (CRITICAL)
File: apps/browser-extension/utils/storage.ts:5
import { storage } from '#imports';
Issue: The #imports alias may not resolve correctly depending on build configuration. This could cause runtime errors.
Recommendation:
- Verify this works in both dev and production builds
- Consider using explicit WXT storage import:
import { storage } from 'wxt/storage' - Test the extension build thoroughly
2. Breaking Change in captureTwitterTokens() (HIGH)
File: apps/browser-extension/utils/twitter-auth.ts:17
Issue: Function signature changed from synchronous to async:
// Before
export function captureTwitterTokens(...): boolean
// After
export async function captureTwitterTokens(...): Promise<boolean>
Impact: All callers must now use await or handle the Promise. If any caller wasn't updated, this could cause silent failures.
Recommendation:
- Verify ALL call sites handle the async nature (check background script, service workers)
- Use grep to find:
captureTwitterTokens(
3. Test Coverage (HIGH)
Issue: No test files found in apps/browser-extension/. This refactor involves:
- Storage layer abstraction
- Async/await conversions
- Error handling changes
Recommendation:
- Add unit tests for storage helpers (
getTwitterTokens(),setTwitterTokens()) - Add integration tests for auth flows
- Test error scenarios (missing tokens, storage failures)
4. Trailing Whitespace (LOW)
File: apps/browser-extension/utils/storage.ts:121
Empty line at end of file - might fail linting.
🔒 Security
✅ No Security Concerns
- Bearer tokens remain in local storage (appropriate for extensions)
- Twitter tokens properly moved to session storage (cleared on browser close)
- No credential leakage in error messages
⚡ Performance
✅ Improvements
- Concurrent storage reads with
Promise.all()(apps/browser-extension/entrypoints/popup/App.tsx:103) - Reduced sequential waits
⚠️ Consideration
WXT storage adds abstraction overhead, but negligible for this use case.
🧪 Testing Recommendations
Manual Testing Required
- Sign in/out flow - Verify token storage/removal
- Settings toggles - Test auto-search and auto-capture prompts
- Twitter integration - Verify bookmark imports work
- Project selection - Test default project persistence
- Extension reload - Verify state persists correctly
Automated Testing Needed
- Storage layer unit tests
- Mock WXT storage in tests
- Edge cases (null values, corrupted data)
📝 Suggested Improvements
1. Add JSDoc Comments
/**
* Retrieves the stored bearer token for API authentication
* @returns Promise resolving to the token string, or undefined if not set
* @throws {AuthenticationError} If token is required but missing
*/
export const bearerToken = storage.defineItem<string>("local:bearer-token")
2. Add Migration Logic
If users have existing data in Chrome storage, consider adding migration:
// Migrate old chrome.storage data to WXT storage
async function migrateFromChromeStorage() {
const oldToken = await chrome.storage.local.get(['bearer-token'])
if (oldToken && !(await bearerToken.getValue())) {
await bearerToken.setValue(oldToken['bearer-token'])
}
}
3. Error Handling in Storage Operations
Add try-catch blocks where storage failures could break UX:
try {
await bearerToken.setValue(token)
} catch (error) {
console.error('Failed to store token:', error)
// Show user-friendly error message
}
🎯 Action Items Before Merge
- ✅ MUST: Verify
#importsalias works in production build - ✅ MUST: Confirm all
captureTwitterTokens()callers are async-aware - ✅ SHOULD: Add basic storage tests
- ✅ SHOULD: Test extension thoroughly with existing user data
- ✅ NICE: Run linter to catch trailing whitespace
📊 Final Verdict
Recommendation: ✅ Approve with Minor Changes
This is a solid refactor that improves maintainability. Address the critical import and async concerns, then merge.
Risk Level: 🟡 Medium (async breaking changes require thorough testing)
Reviewed by: Claude Code Review Date: 2025-11-09
Reg the claude's review