Skip to content

Maybe it would be easier to not experiment with awaits? #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hkmaly
Copy link

@hkmaly hkmaly commented Apr 1, 2023

Seems to solve #159.

Frankly, most likely the actual error is that it should be current[HISTORY_KEY] instead of current.history, but maybe it would be safer to get rid of those awaits as well.

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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

@hkmaly hkmaly Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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) ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Another pull request with then pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants