browserAction and pageAction.onClicked do not count towards user interaction on Android
Categories
(WebExtensions :: Android, defect, P2)
Tracking
(firefox116 fixed)
| Tracking | Status | |
|---|---|---|
| firefox116 | --- | fixed |
People
(Reporter: csadilek, Assigned: robwu)
References
Details
(Whiteboard: [addons-jira])
Attachments
(1 external file)
From github: https://github.com/mozilla-mobile/fenix/issues/22348.
Steps to reproduce
- Write an add-on that calls
browser.permissions.request(...)inside thebrowser.browserAction.onClickedevent listener (i.e. when the user taps the browser action icon in Menu > Add-ons > MyTestAddOn) (see example below).- The
browser.permissions.requestpromise throws aError: permissions.request may only be called from a user input handlererror.Test Add-on Example
manifest.json:{ "manifest_version": 2, "name": "Test123", "version": "1.0", "background": { "scripts": [ "/background.js" ] }, "browser_action": { "default_title": "Test234" }, "permissions": [ "https://www.example.com/" ], "optional_permissions": [ "<all_urls>" ] }
background.js:console.log("background.js!!!"); browser.browserAction.onClicked.addListener((currentTab) => { console.log("action click!!!"); browser.permissions.request({ origins: ["https://www.example.com/"] }) .then((givenPermission) => { console.log("givenPermission", givenPermission); }) .catch((err) => { console.log("error", err); }); // Output on Firefox for Android: // action click!!! // error [Error: permissions.request may only be called from a user input handler] });Expected behaviour
On Firefox desktop, since the permission for the origin is already provided in the manifest, the promise returns
givenPermission = true.Actual behaviour
On Firefox for Android, the promise throws an error:
Error: permissions.request may only be called from a user input handler.Device name
Google Pixel 4a
Android version
Android 11
Firefox release type
Firefox Nightly
Firefox version
96.0a1 (Build #2015843979)
Device logs
No response
Additional information
No response
┆Issue is synchronized with this Jira Task
Change performed by the Move to Bugzilla add-on.
| Assignee | ||
Comment 1•3 years ago
|
||
This can be fixed by uncommenting this line (and removing the redundant comment):
https://searchfox.org/mozilla-central/rev/eb00c7365e72ac422acd97f6eee3c26926b786cd/mobile/android/components/extensions/ext-browserAction.js#154-155
// NOTE: Firefox Desktop event has inputHandling set to true here.
// inputHandling: true,
We should make a similar change at https://searchfox.org/mozilla-central/rev/eb00c7365e72ac422acd97f6eee3c26926b786cd/mobile/android/components/extensions/ext-pageAction.js#141
We should also have regression tests using permission.request to verify that this logic works on desktop and mobile.
To create that test, create a file test_ext_action_permissions_request.html based on https://searchfox.org/mozilla-central/rev/eb00c7365e72ac422acd97f6eee3c26926b786cd/toolkit/components/extensions/test/mochitest/test_ext_action.html and extend the test by adding a permissions.requestcall in the onClicked listener, followed bypermissions.contains` to verify that the permission has been granted.
Ordinarily, a permission prompt would be shown, but for testing purposes the extensions.webextOptionalPermissionPrompts pref can be set to false in add_setup.
| Assignee | ||
Comment 2•3 years ago
|
||
What I described above is what's needed to verify that the GeckoView side works (in unit tests).
Before this works for users, the A-C/Fenix side needs to be implemented too, which is tracked in bug 1810047.
Comment 3•3 years ago
|
||
The severity field is not set for this bug.
:cpeterson, could you have a look please?
For more information, please visit auto_nag documentation.
Updated•3 years ago
|
Updated•3 years ago
|
Comment 4•3 years ago
|
||
Triage: Arturo mentioned he would like to do a quick investigation to see if this falls under a larger extension meta issue.
Comment 5•3 years ago
|
||
This will be covered as part of supporting MV3 + adding support for run-time permission in Fenix.
| Assignee | ||
Comment 6•3 years ago
|
||
I'm reopening because this bug report has actionable parts that is independent of permissions.request. I've adjusted the bug title accordingly.
I'll also move this to WebExtensions::Android since the change here is fully in the (Android-specific) WebExtensions components, as sketched in comment 1.
Updated•3 years ago
|
| Assignee | ||
Comment 7•3 years ago
|
||
Set inputHandling: true in the onClicked event of the
action/browserAction and pageAction APIs, and add tests.
Besides the usual coverage for the feature here, this patch also
introduces the only Android test for the page_action.show_matches
manifest key and the pageAction.isShown API. These APIs were already
covered by desktop-specific tests in browser/, but had zero test
coverage on Android. Since toolkit mochitests are run on desktop and
Android, this provides better cross-browser coverage.
Comment 9•3 years ago
|
||
| bugherder | ||
| Assignee | ||
Updated•3 years ago
|
Description
•