'Async requirements and composeAction.openPopup handler

I would like to develop an Thunderbird extension which scans the recipient list and opens under some conditions are popup.

Unfortunately, the address book API is mostly async, so resolving the recipient list is also async code.

After calling this async API, my handler unfortunately losses the input handler attribute and I cannot call anymore composeAction.openPopup:

Error: composeAction.openPopup may only be called from a user input handler

Is there are workaround? Looking at other extensions, they all use browser.windows.create which seems to callable outside input handlers...

Here the relevant parts of my code:

browser.compose.onBeforeSend.addListener(async (tab, details) => {
   
   const canBeSent = await checkMail();
   if (canBeSent) {
      return Promise.resolve();
   }

   browser.composeAction.openPopup(); // does not work because of async

   // further code
} 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source