0

I'm working with GeckoView and met problem with installing AddOns. As suggested on Documentation, I've provided XPI compatible with Android, but nothing changes. Copying file to Assets doesn't make a change. Browser doesn't acknowledge WebExtension.

private fun setupGeckoView() {
        geckoSession?.permissionDelegate = object : GeckoSession.PermissionDelegate {
            override fun onContentPermissionRequest(
                session: GeckoSession,
                perm: GeckoSession.PermissionDelegate.ContentPermission
            ): GeckoResult<Int>? {
                return super.onContentPermissionRequest(session, perm)
            }
        }

        geckoView = findViewById(R.id.geckoView)
        val runtime = GeckoRuntime.create(this)

        runtime.settings.consoleOutputEnabled = true
        runtime.webExtensionController.promptDelegate = PromptListener(runtime.webExtensionController)
        runtime.webExtensionController
            .install("https://addons.mozilla.org/android/downloads/file/3719055/youtube_high_definition-85.0.0-an+fx.xpi")

        geckoSession.open(runtime)
        geckoView.setSession(geckoSession)

        geckoSession.loadUri("https://www.youtube.com")
    }
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gv.webapp">

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.webapp">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!--<provider
            android:authorities="com.gv.webapp"
            android:name="com.gv.webapp.Provider">
            <grant-uri-permission android:path="string"
                android:pathPattern="string"
                android:pathPrefix="string" />
        </provider>-->
    </application>

</manifest>

I'm checking logs and the result is confusing. I've got prompt that WebExtension is installed, but when I looking at controller.list() it's empty.

KwarcPL
  • 67
  • 7

1 Answers1

0

You may be missing a PermissionDelegate:

geckoSession?.permissionDelegate = object : GeckoSession.PermissionDelegate {
    override fun onContentPermissionRequest(
        session: GeckoSession,
        perm: GeckoSession.PermissionDelegate.ContentPermission
    ): GeckoResult<Int>? {
        return super.onContentPermissionRequest(session, perm)
    }
}

Permission delegate allows you to handle requests from Gecko for any permission that needs handling.

D.H.
  • 186
  • 14
  • Adding ```PermissionDelegate``` helped, but I still didn't get any message on console regarding AddOn. So I've hooked PromptDelegate ```runtime.webExtensionController.promptDelegate = PromptListener()```. Now I know that GeckoView is trying to load WebExtension, but it's still not running for some reason. When I tried to check if everything is OK with ```runtime.webExtensionController.list()``` I got empty list. – KwarcPL Feb 17 '22 at 18:43
  • Could you update your original question with the manifest? And the JS your are trying to attach? Will take a look – D.H. Feb 17 '22 at 19:55
  • I've updated my OP. – KwarcPL Feb 19 '22 at 13:51
  • @KwarcPL oh not the Android manifest - the extension manifest - each JS extension requires a manifest - did make one? Take a look at this page: https://firefox-source-docs.mozilla.org/mobile/android/geckoview/consumer/web-extensions.html – D.H. Feb 20 '22 at 18:04
  • I'm loading XPI directly from Firefox page. So I believe XPI is all right. – KwarcPL Feb 27 '22 at 11:14