You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @jmeistrich, I love what you are doing here with legend-state! Great library 🚀
TL;DR: I was wondering if it is possible to use legend state to persist to the chrome extension local storage as opposed to the web local storage. We might need to write an async version of the local-storage.ts Persistence Plugin accessing chrome.storage.<'local'/'sync'> rather than window.localStorage and then calling the corresponding set/get item functions.
I'm evaluating whether I can integrate legend-state with a Chrome extension I'm building to leverage the offline first behavior in combination with Supabase.
Before opening this discussion I tried a few things including:
Look for similar issues with chrome extensions (none found)
Use local storage which worked fine, but persisted to window.localStorage which isn't accessible from the content script
Use indexeddb which I couldn't get to work. Transaction errors, i.e. [legend-state] Error loading IndexedDB InvalidAccessError: Failed to execute 'transaction' on 'IDBDatabase': The storeNames parameter was empty.TBH, this could be a skill issue on my end, but I couldn't really make sense of the docs. The IndexedDB example doesn't compile (see screenshots below)
Which I can fix by flattening the options/removing the indexedDB prop, but will then get DB access errors. Maybe @jmeistrich has an idea what I'm doing wrong.
Optimally, I would like to use chrome.storage.local or chrome.storage.sync anyway. While the API is mostly the same, it differs a little from the window.localStorage in that:
it's asynchronous
get/set methods have different signatures
it can save primitive/json type data directly without the need for serialization
What would be the easiest way to make this work?
I'm happy to contribute a persist plugin for the chrome storage according to this interface if need be.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi @jmeistrich, I love what you are doing here with legend-state! Great library 🚀
TL;DR: I was wondering if it is possible to use legend state to persist to the chrome extension local storage as opposed to the web local storage. We might need to write an
async
version of thelocal-storage.ts
Persistence Plugin accessingchrome.storage.<'local'/'sync'>
rather thanwindow.localStorage
and then calling the correspondingset/get
item functions.I'm evaluating whether I can integrate legend-state with a Chrome extension I'm building to leverage the offline first behavior in combination with Supabase.
Before opening this discussion I tried a few things including:
window.localStorage
which isn't accessible from the content script[legend-state] Error loading IndexedDB InvalidAccessError: Failed to execute 'transaction' on 'IDBDatabase': The storeNames parameter was empty.
TBH, this could be a skill issue on my end, but I couldn't really make sense of the docs. The IndexedDB example doesn't compile (see screenshots below)Which I can fix by flattening the options/removing the indexedDB prop, but will then get DB access errors. Maybe @jmeistrich has an idea what I'm doing wrong.
Optimally, I would like to use
chrome.storage.local
orchrome.storage.sync
anyway. While the API is mostly the same, it differs a little from thewindow.localStorage
in that:get/set
methods have different signaturesWhat would be the easiest way to make this work?
I'm happy to contribute a persist plugin for the chrome storage according to this interface if need be.
Beta Was this translation helpful? Give feedback.
All reactions