Closed Bug 1818959 Opened 2 years ago Closed 2 years ago

action.openPopup throws "requires a user gesture" on extension command/shortcut context

Categories

(WebExtensions :: Untriaged, defect)

Firefox 110
Desktop
Linux
defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: zopieux, Unassigned)

References

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0

Steps to reproduce:

Registering an extension with a configured command shortcut:

"commands": {
"invoke": {
"description": "Invoke",
"suggested_key": {
"default": "Ctrl+Shift+F"
}
}
}

as well as a browser action popup:

"browser_action": {
"default_icon": "icon-128.png",
"default_title": "Test",
"default_popup": "popup.html"
},

In backgrounds script, attempt to open the popup from some onCommand listener:

browser.commands.onCommand.addListener(function (command) {
await tabs = browser.tabs.query({ active: true, currentWindow: true })
await browser.browserAction.openPopup({
windowId: tabs[0].windowId,
})
})

Related:

Actual results:

The code throws:

Error: openPopup requires a user gesture

Expected results:

While this isn't a “gesture” aka a click per-se, this is definitely a user intent which is directly pertaining to the extension, since this is the shortcut key for a command registered on the extension. I believe Firefox should allow opening the extension popup in this context, though maybe only for the window in which the command was invoked – which is what I'm trying to do anyway.

OS: Unspecified → Linux
Hardware: Unspecified → Desktop
See Also: → 1392624, 1799344

Unsurprisingly, setting extensions.openPopupWithoutUserGesture.enabled to true workarounds the issue, but this isn't the default.

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Product: Firefox → WebExtensions

The commands.onCommand event does offer the user interaction.

But your code calls await browser.tabs.query() before invoking browser.browserAction.openPopup(). That consumes the user interaction, similar to bug 1800401.

The browserAction.openPopup does not require the windowId parameter, and defaults to the active window. So you should be able to call openPopup without calling tabs.query().

Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → INVALID
See Also: → 1800401
You need to log in before you can comment on or make changes to this bug.