Closed Bug 1811608 Opened 2 years ago Closed 1 year ago

browserAction and pageAction.onClicked do not count towards user interaction on Android

Categories

(WebExtensions :: Android, defect, P2)

All
Android
defect

Tracking

(firefox116 fixed)

RESOLVED FIXED
116 Branch
Tracking Status
firefox116 --- fixed

People

(Reporter: csadilek, Assigned: robwu)

References

Details

(Whiteboard: [addons-jira])

Attachments

(1 file)

From github: https://github.com/mozilla-mobile/fenix/issues/22348.

Steps to reproduce

  1. Write an add-on that calls browser.permissions.request(...) inside the browser.browserAction.onClicked event listener (i.e. when the user taps the browser action icon in Menu > Add-ons > MyTestAddOn) (see example below).
  2. The browser.permissions.request promise throws a Error: permissions.request may only be called from a user input handler error.

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.

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 apermissions.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.

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.

The severity field is not set for this bug.
:cpeterson, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(cpeterson)
Flags: needinfo?(cpeterson)
Severity: -- → S2

Triage: Arturo mentioned he would like to do a quick investigation to see if this falls under a larger extension meta issue.

Flags: needinfo?(amejiamarmol)

This will be covered as part of supporting MV3 + adding support for run-time permission in Fenix.

Status: NEW → RESOLVED
Closed: 1 year ago
Duplicate of bug: 1810047
Flags: needinfo?(amejiamarmol)
Resolution: --- → DUPLICATE

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.

Assignee: nobody → rob
Severity: S2 → S3
Status: RESOLVED → REOPENED
Component: WebExtensions → Android
No longer duplicate of bug: 1810047
Priority: -- → P2
Product: Fenix → WebExtensions
Resolution: DUPLICATE → ---
Summary: browserAction not seen as user interaction for permissions.request → browserAction and pageAction.onClicked do not count towards user interaction on Android
Whiteboard: [addons-jira]

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.

Pushed by rob@robwu.nl: https://hg.mozilla.org/integration/autoland/rev/3fce34e4fcd9 Set inputHandling in browser/pageAction.onClicked on Android +tests r=extension-reviewers,amejiamarmol,geckoview-reviewers,willdurand
Regressions: 1839890
Status: REOPENED → RESOLVED
Closed: 1 year ago1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 116 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: