Search code examples
chrome-extension-manifest-v3

List of Promise API in manifest v3


Overview of Manifest V3 states:

  • Promise support has been added to many methods, though callbacks are still supported as an alternative. (We will eventually support promises on all appropriate methods.)

Is there a list of APIs that has been converted to Promise?

For example, the following runs into error:

chrome.contextMenus.removeAll()
.then(() => console.log('done'));

// Uncaught TypeError: Cannot read properties of undefined (reading 'then')

Solution

  • I'm not aware of such a list but the support status for a given method will be shown in an IDE (via a tooltip or a method preview or a "Go to definition" command) if you install the official chrome-types package. Don't confuse it with @types/chrome by DefinitelyTyped offered in many IDE by default. The important difference is that the official package is autogenerated from the source code of Chromium, so it should reflect reality, although theoretically their crawler may have bugs.

    To see which version of Chrome added the support there's no convenient method yet, so you'll have to check the source code directly and use the Blame feature inside.

    Example 1, chrome.contextMenus.removeAll. Search for the method name removeAll using an expression like \bremoveAll\b file:extension.*(json|idl)$ (\b means boundary like a space or a doublequote), you'll see a file named "context_menus", click it, and look at the definition. Only callback is there, no async or Promise, which means it's not converted yet.

    Example 2, chrome.tabs.sendMessage. The definition says returns_async, i.e. it supports Promise.

    • Click the Blame button in the top right corner.
    • When the panel loads, hover the title of a block inside that corresponds to returns_async line.
    • You'll see a bubble with the latest change, at this moment it's "Add promise support to SendMessage native hooks", which luckily describes the thing we look for. Otherwise you would have to dig further by clicking "View blame prior to this change".
    • Right-click the link "Commit xxxxxxx", and copy it, then paste in the addressbar and replace everything except the last long id with chromiumdash.appspot.com/commit/ so in our example it'll be chromiumdash.appspot.com/commit/2cfa204a0da496b42c3a148d014df4aef45c43fc
    • The linked page says it's Chrome 99, so it'd be reasonable to add "minimum_chrome_version": "99" in manifest.json to ensure that users of older browsers won't install the extension and won't receive it in an automatic update. In case you really want to support users of older browsers you'll have to use this method in callback mode or apply your own promisifier.