3

In a browser extension we store a serialized JSON in the browser local storage. using storage.local.set({ accounts: JSON.stringify() })
When loading the data from the storage again using storage.local.get we use JSON.parse to deserialze the data. This works fine in Chrome and Firefox.
It seems Orion is automatically parse the JSON and return an object (this breaks code that assumes it has to parse the JSON).

Code that writes to the storage: https://github.com/getAlby/lightning-browser-extension/blob/master/src/common/lib/cache.ts#L14-L16

Code that reads from the storage: https://github.com/getAlby/lightning-browser-extension/blob/master/src/common/lib/cache.ts#L6-L9

Everything works if I check the type of the stored data:
accountsCache = typeof result.accounts === 'string' ? JSON.parse(result.accounts) : result.accounts;

I assume this should behave the same as in Chrome of Firefox

Steps to reproduce:

write to storage.local and read from storage in an extension:

browser.storage.local.set({ accounts: JSON.stringify({foo: 'bar'}) });`
const result = await browser.storage.local.get(['accounts']);
console.log(result.accounts); // this should be a string and not an object
JSON.parse(result.accounts);

Expected behavior:
expected the storage.local.set and storage.local.get function to behave the same as in other browsers and return the JSON string.

Orion, OS version; hardware type:
Version 0.99.121-beta (WebKit 614.1.20)
MacBook Air (macOS Monterey 12.5.1 build 21G83)

    25 days later

    There seems to also be an issue with browser.storage.sync

    The extension writes an object to a sync storage key. After a restart(!), when accessed it again Orion returns a JSON encoded string. Other browsers return the object.

    before:

    AFTER a RESTART:

    Seems to me that there is an issue with the browser.storage functions. It seems the data does not really persist or load correct.

    • Vlad replied to this.

      bumi Thanks for the debugging effort. Planned for 124.

      • bumi replied to this.

        Vlad oh that's awesome! let me know if I can help something or do more debugging.

          btw. I think the same problem is also for the iOS version - there I just could not debug it but the result/observed problem looks similar

          a month later

          Is there already any update on this? let me know if I can help with testing or something.

          • Vlad replied to this.
            5 days later

            Vlad <3 can't wait 🙂 thanks for the update. does that also include iOS?
            anyway if I can do or test something let me know.

              a month later

              @bumi I have not been able to get Alby to work in Orion, is there any trick?

              • Vlad replied to this.
                7 months later
                9 days later
                No one is typing