2

I just recently started programming a Chrome extension and after trying around a lot and failing, I decided to read almost the entire Docs, maybe should have done that earlier. ¯\_(ツ)_/¯

I decided I want to use Promises and read the page "Using promises".

Where it says:

"Not all methods in extensions APIs support promises. Sometimes that's because we haven't added promise support on the method yet; in many cases it's because using a promise isn't feasible for the method."

It also gives some examples of what API methods can and cannot be used with Promises.

What I could not find was a way to find out which methods support Promises and which do not.

For example: chrome.tabs.create supports Promises, but I cannot seem to find something indicating that in the docs.

First StackOverflow question so pls be gentle with me, help is very appreciated. :P

  • 1
    If the function has a `callback` parameter it's likely that it doesn't support Promises yet (because callbacks were used before promises were a thing). You can also check the return value; a function that supports promises always returns a Promise object. When in doubt, just log the function's return value. –  Apr 01 '21 at 15:22
  • 4
    Callbacks will be supported along with Promise so it's not an indicator. ManifestV3 is still in development so just try to use the API with a Promise and expect things to break. After that either promisify the API yourself or wait until ManifestV3 is finished. – wOxxOm Apr 01 '21 at 15:24
  • 1
    FWIW you can view the current state of some API (as implemented in Chrome Canary or Chromium trunk) in [source code](https://source.chromium.org/search?q=file:extensions%20file:idl%20supportsPromises). – wOxxOm Apr 01 '21 at 15:27
  • Ty @wOxxOm that's's a start at least. Although, I cannot find the aforementioned tabs.create method in the link you posted. – Jan Weßeling Apr 01 '21 at 15:35
  • Look for `returns_async` in the source code for the rest of API. See also https://crbug.com/328932 – wOxxOm Apr 01 '21 at 15:49

1 Answers1

0

The best answer I could find myself is on an old Question with a recent update listing all the supported APIs with reference.