Support action.openPopup on Fenix (implement onOpenPopup override of ActionDelegate in A-C)
Categories
(Firefox for Android :: WebExtensions, enhancement, P3)
Tracking
()
People
(Reporter: robwu, Unassigned)
References
Details
(Whiteboard: [addons-jira])
Bug 1530402 introduced support for the browser/page action extension APIs. They have mostly been hooked up. One of the methods, the openPopup method has not correctly been hooked up in A-C, despite the method being supported in GeckoView (unit test: ExtensionActionTest.kt), and supported in TestRunnerActivity (source) and GVE (source).
This report shows the STR and provides guidance on supporting the functionality in A-C / Fenix.
Steps to reproduce
This can manually be confirmed on current Firefox for Android builds:
- Install uBlock Origin (that has a browserAction popup).
- Attach a debugger (enabling ADB debugging, enabling remote debugging in the Firefox app and then via about:debugging on desktop)
- Open any tab (e.g. example.com) to launch the Gecko process.
- Ensure that we can call
browser.browserAction.openPopup. This currently requires a user gesture (until bug 1799344 removes that requirement). There are three ways to meet this requirement:
- Set the
extensions.openPopupWithoutUserGesture.enabledpreference to true,- via the instructions at https://firefox-source-docs.mozilla.org/mobile/android/geckoview/consumer/automation.html
- or by inspecting the main process via
about:debugging(from step 2) and runningServices.prefs.setBoolPref("extensions.openPopupWithoutUserGesture.enabled", true)(if this is your main profile, revert this when you're done by runningServices.prefs.clearUserPref("extensions.openPopupWithoutUserGesture.enabled")
- Or by opening an extension page, registering a
clickevent listener and call theopenPopupmethod from theclickhandler, - Inspect the extension and call
browser.tabs.create({ url: browser.runtime.getURL("manifest.json") })to open a new extension tab. - Inspect that tab in the devtools, and register the listener:
document.body.onclick = () => { browser.browserAction.openPopup(); };. - Interact with the browser manually by tapping in the content area of the tab.
- Once you have enabled the
openPopupAPI (step 4), open the popup by callingbrowser.browserAction.openPopup();(e.g. via the devtools).
Expected behavior
- The extension popup opens.
Actual behavior
- Nothing happens.
Implementation details
To support it on Fenix:
- A-C: Add an
onOpenPopupoverride at https://github.com/mozilla-mobile/firefox-android/blob/9de5ab8cc098674aad5190ce8b00ae6be65e9bd0/android-components/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/webextension/GeckoWebExtension.kt#L177-L204- The implementation should show the popup if it was not visible, and be no-op if it was visible (or reject the call with an error; in this case GeckoView would need to be updated to handle the error).
- Along with the changes in A-C, whatever that's needed to actually hook it up in Fenix.
- Add a unit test at https://github.com/mozilla-mobile/firefox-android/blob/9de5ab8cc098674aad5190ce8b00ae6be65e9bd0/android-components/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/webextension/GeckoWebExtensionTest.kt#L259
Additional notes:
- It would be really nice to be able to open the popup for arbitrary "windows" (tabs / GeckoSession), and not to assume it to be whatever the currently active tab is. That should be fixed along with bug 1817772 (see also: https://bugzilla.mozilla.org/show_bug.cgi?id=1795956#c1 ).
- Not a must-have, but if possible, it would be nice to notify GeckoView/Gecko when the popup has finally been opened (to support bug 1811071).
Updated•3 years ago
|
| Reporter | ||
Comment 1•3 years ago
|
||
This would be a good-first-bug for WebExtension engineers who are looking to contribute to Android-Components / Fenix.
| Reporter | ||
Comment 2•3 years ago
|
||
Not a must-have, but if possible, it would be nice to notify GeckoView/Gecko when the popup has finally been opened (to support bug 1811071).
Updated•1 year ago
|
| Reporter | ||
Comment 4•1 year ago
•
|
||
The code has moved;
Here is the relevant code today:
- Definition of
onOpenPopup: https://searchfox.org/mozilla-central/rev/d5baa11e35e0186c3c867f4948010f0742198467/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/WebExtension.java#1522-1535 - Missing override of
onOpenPopupin Android-Components: https://searchfox.org/mozilla-central/rev/d5baa11e35e0186c3c867f4948010f0742198467/mobile/android/android-components/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/webextension/GeckoWebExtension.kt#178-205 - Unit test to be added at https://searchfox.org/mozilla-central/rev/d5baa11e35e0186c3c867f4948010f0742198467/mobile/android/android-components/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/webextension/GeckoWebExtensionTest.kt#260
If someone is interested in contributing a patch.
$ ./mach bootstrap
...
Choose option 3:
3. GeckoView/Firefox for Android Artifact Mode
Then create a .mozconfig-android file with the output suggested by ./mach bootstrap .
To launch the browser for manual testing, build the application and run as follows (in an Android emulator):
MOZCONFIG=.mozconfig-android ./mach build
MOZCONFIG=.mozconfig-android ./mach run --app=fenix
To run the unit test:
MOZCONFIG=.mozconfig-android ./mach test mobile/android/android-components/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/webextension/GeckoWebExtensionTest.kt
(note: if you cannot see the output, see https://bugzilla.mozilla.org/show_bug.cgi?id=1950183#c2).
| Reporter | ||
Comment 5•1 month ago
|
||
Note: when working on this bug, double check the behavior for PWA and custom tabs.
Incidentally, I recently observed that a browser.tabs.create() call from an extension's background page on startup to trigger the opening of a tab. It is possible that there are more issues, resulting in the need to have a separate bug tracking extension interaction while in a custom tab, without blocking this current bug.
Description
•