I’m working on an add-on which performs a lookup on my server for some data, and opens a compose window with the containing data. I’ve got everything working as expected, except for error handling. I’d like to show a popup with the error only when a lookup fails. Here’s what I have so far:
browser.messageDisplayAction.onClicked.addListener((tab) =>{
browser.messageDisplay.getDisplayedMessage(tab.id).then((message) => {
httpLookup().then((response) => {
if (response.status == “success”){
browser.compose.beginNew({})
}
else {
browser.messageDisplayAction.setPopup({‘popup’:‘error.html’});
browser.messageDisplayAction.openPopup();
browser.messageDisplayAction.setPopup({‘popup’:null});
}
})
});
})
The issue is that openPopup() is throwing the following error: Error: messageDisplayAction.openPopup may only be called from a user input handler. This error is not thrown when the function is placed on the second line (before getDisplayedMessage) or outside of any asynchronous function.
Is this behaviour even expected? I have no way to not call my server asynchronously so is there any other way I can get the popup loaded?