'Load WebExtensions on GeckoView

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.



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1