Bug 1693829 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

The ``menu.onClicked`` event allows to open browser action popus. This works:

```
function contextualClickHandler() {
    browser.composeAction.openPopup();
}
browser.menus.create({
    id: "MENU1",
    title: "CLICK ME",
    contexts: ["all"]
});
browser.menus.onClicked.addListener(contextualClickHandler);
```
However, if I want to check something in my local storage before opening the popup, I have to make contextualClickHandler async:

```
async function contextualClickHandler() {
    let data = await browser.storage.local.get();
    // ... do something with data ...
    browser.composeAction.openPopup();
}
browser.menus.create({
    id: "MENU1",
    title: "CLICK ME",
    contexts: ["all"]
});
browser.menus.onClicked.addListener(contextualClickHandler);
```
This throws a `openPopup() is only allowed to execute in a user input handler context`. 

The reason for this is probably, that the event is fired as a callback to `withHandlingUserInput ` (https://searchfox.org/mozilla-central/source/browser/components/extensions/child/ext-menus.js#274) and that does not await the callback, which means the handle is destroyed before the popup is opened.
The ``menu.onClicked`` event allows to open browser action popus. This works:

```
function contextualClickHandler() {
    browser.browserAction.openPopup();
}
browser.menus.create({
    id: "MENU1",
    title: "CLICK ME",
    contexts: ["all"]
});
browser.menus.onClicked.addListener(contextualClickHandler);
```
However, if I want to check something in my local storage before opening the popup, I have to make contextualClickHandler async:

```
async function contextualClickHandler() {
    let data = await browser.storage.local.get();
    // ... do something with data ...
    browser.browserAction.openPopup();
}
browser.menus.create({
    id: "MENU1",
    title: "CLICK ME",
    contexts: ["all"]
});
browser.menus.onClicked.addListener(contextualClickHandler);
```
This throws a `openPopup() is only allowed to execute in a user input handler context`. 

The reason for this is probably, that the event is fired as a callback to `withHandlingUserInput ` (https://searchfox.org/mozilla-central/source/browser/components/extensions/child/ext-menus.js#274) and that does not await the callback, which means the handle is destroyed before the popup is opened.

Back to Bug 1693829 Comment 0