action.openPopup throws "requires a user gesture" on extension command/shortcut context
Categories
(WebExtensions :: Untriaged, defect)
Tracking
(Not tracked)
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:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1392624
- https://bugzilla.mozilla.org/show_bug.cgi?id=1799344
- https://bugzilla.mozilla.org/show_bug.cgi?id=1817809 (Fenix)
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.
Reporter | ||
Updated•2 years ago
|
Reporter | ||
Updated•2 years ago
|
Reporter | ||
Comment 1•2 years ago
|
||
Unsurprisingly, setting extensions.openPopupWithoutUserGesture.enabled
to true
workarounds the issue, but this isn't the default.
Comment 2•2 years ago
|
||
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.
Comment 3•2 years ago
|
||
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()
.
Description
•