0

I have this code at the moment:

async function updateAddons(state) {
    const themeSyncAddons = await new Promise((resolve, reject) => chrome.storage.sync.get(['themeSyncAddons'], result => resolve(result.themeSyncAddons)));
  };

And I want to get variable themeSyncAddons in normal code (not async), and execute code with this var. Is it possible?

Norbiros
  • 3
  • 3
  • In Chrome ManifestV2 extensions you can't use `await` unless you promisify the API manually or use an existing library. In ManifestV3 sendMessage is promisified only in Chrome 99 so until then you should promisify it manually. – wOxxOm Feb 21 '22 at 16:40
  • Okay! Thanks very much for response! Okay, so if I can't use it in async function, can I convert this normal function (I'm talking about converting result of `themeSyncAddons`). Or maybe I can do this without `await`? – Norbiros Feb 21 '22 at 17:02
  • There are many ways to use the API, but I don't understand what exactly you want and what exactly is failing. Try adding more info to the question, see [MCVE](/help/mcve). – wOxxOm Feb 21 '22 at 17:08
  • I changed a lot, so maybe now it is more clear... – Norbiros Feb 21 '22 at 17:16
  • It's still unclear why you can't use `async`. Is it because of this: [sendResponse not waiting for async](https://stackoverflow.com/a/53024910)? – wOxxOm Feb 21 '22 at 17:19
  • I'm using async only to get value of `chrome.storage` element. I don't want to use `async`, but I couldn't make better system for getting value of this storage element. This is thing I want to do: `Get Value of storage element >> send chrome message with parameter as value of this element` And I can use it in any way, I only want to make it work :D – Norbiros Feb 21 '22 at 17:25
  • It's still unclear why you can't use async. It's the correct method. You can switch to callbacks of course, as shown in the [documentation](https://developer.chrome.com/docs/extensions/reference/storage/#usage) and use the variable inside the callback. – wOxxOm Feb 21 '22 at 17:28
  • I now realised how stupid was my question. Ahh, sorry for problem. – Norbiros Feb 21 '22 at 17:32

0 Answers0