Maybe it would be easier to not experiment with awaits?#203
Conversation
| const current = (await browser.storage.local.get(HISTORY_KEY)) || {}; | ||
| await browser.storage.local.set({ | ||
| [HISTORY_KEY]: [...(current.history || []), entry], | ||
| browser.storage.local.get(HISTORY_KEY, function(current) { |
There was a problem hiding this comment.
I'll need to try this out, local.get is async and returns a promise as per https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/get
MDN also doesn't seem to see to indicate a callback function as the second argument.
There was a problem hiding this comment.
@gyng If you look on bottom of that page, it's actually mentioned there as example: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/get#chrome_examples (with different function syntax, but still).
Or I can rewrite it to promise using then. I'm just suspicious about the await. And there is no other await in your extension ...
... oh. I see. browser.storage.local is supposed to be something else than chrome.storage.local. Weird. It DOES work for me, though (in firefox) ...
There was a problem hiding this comment.
Ok. Another pull request with then pushed.
Seems to solve #159.
Frankly, most likely the actual error is that it should be
current[HISTORY_KEY]instead ofcurrent.history, but maybe it would be safer to get rid of those awaits as well.