Skip to content

How to load a remote extension in geckoview? #240

Open

Description

@baseplate-admin

Hi, i have this following kotlin code

  sRuntime.getWebExtensionController().ensureBuiltIn(
            EXTENSION_LOCATION,
            "uBlock0@raymondhill.net"
        ).accept(
            { extension ->
                // Use Log to print information about the installed extension
                Log.i("MessageDelegate", "Extension installed: " + extension)
            },
            { e ->
                // Handle error if registering the WebExtension fails
                Log.e("MessageDelegate", "Error registering WebExtension", e)
            }
        )

and this location.

But this doesn't register and the log has some weird things in it:

E/GeckoConsole( 5168): _g
I/GeckoConsole( 5168): 1716030203919    addons.webextension.uBlock0@raymondhill.net     WARN    Loading extension 'uBlock0@raymondhill.net': Reading manifest: Warning processing permissions: Error processing permissions.2: Value "menus" must either: must either [must either [must either [be one of ["idle"], be one of ["activeTab"], be one of ["cookies"], be one of ["scripting"], or be one of ["webRequest", "webRequestAuthProvider", "webRequestBlocking", "webRequestFilterResponse", "webRequestFilterResponse.serviceWorkerScript"]], must either [be one of ["mozillaAddons"], be one of ["geckoViewAddons", "nativeMessagingFromContent"], be one of ["activityLog"], be one of ["networkStatus"], or be one of ["telemetry"]], be one of ["alarms", "storage", "unlimitedStorage"], be one of ["contextualIdentities"], be one of ["declarativeNetRequestWithHostAccess"], be one of ["dns"], or be one of ["theme"]], must either [must either [be one of ["idle"], be one of ["activeTab"], be one of ["cookies"], be one of ["scripting"], or be one of ["webRequest", "
I/GeckoConsole( 5168): 1716030203920    addons.webextension.uBlock0@raymondhill.net     WARN    Loading extension 'uBlock0@raymondhill.net': Reading manifest: Warning processing commands: An unexpected property was found in the WebExtension manifest.
E/MessageDelegate( 5168): Error registering WebExtension
E/MessageDelegate( 5168): java.lang.Exception: Unexpected error: Error: Extension is invalid
E/MessageDelegate( 5168):       at org.mozilla.geckoview.WebExtensionController$$ExternalSyntheticLambda15.onException(Unknown Source:0)
E/MessageDelegate( 5168):       at org.mozilla.geckoview.GeckoResult.lambda$map$1(GeckoResult.java:419)
E/MessageDelegate( 5168):       at org.mozilla.geckoview.GeckoResult$$ExternalSyntheticLambda9.onException(Unknown Source:2)
E/MessageDelegate( 5168):       at org.mozilla.geckoview.GeckoResult.lambda$thenInternal$6(GeckoResult.java:593)
E/MessageDelegate( 5168):       at org.mozilla.geckoview.GeckoResult.$r8$lambda$nsAzyhhKgAo0Ha3SEAUSdsKADo8(Unknown Source:0)
E/MessageDelegate( 5168):       at org.mozilla.geckoview.GeckoResult$$ExternalSyntheticLambda5.run(Unknown Source:8)
E/MessageDelegate( 5168):       at org.mozilla.geckoview.GeckoResult.lambda$dispatchLocked$7(GeckoResult.java:792)
E/MessageDelegate( 5168):       at org.mozilla.geckoview.GeckoResult$$ExternalSyntheticLambda1.run(Unknown Source:2)
E/MessageDelegate( 5168):       at android.os.Handler.handleCallback(Handler.java:958)
E/MessageDelegate( 5168):       at android.os.Handler.dispatchMessage(Handler.java:99)
E/MessageDelegate( 5168):       at android.os.Looper.loopOnce(Looper.java:205)
E/MessageDelegate( 5168):       at android.os.Looper.loop(Looper.java:294)
E/MessageDelegate( 5168):       at android.app.ActivityThread.main(ActivityThread.java:8177)
E/MessageDelegate( 5168):       at java.lang.reflect.Method.invoke(Native Method)
E/MessageDelegate( 5168):       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/MessageDelegate( 5168):       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:97

Is there any way i can load extensions such as ublock Origin into my android GeckoView?

thanks a lot in advance

Activity

  1. decryptable commented on Jan 12, 2025

    @decryptable

    Have you found a solution yet? I'm also having the same problem. I tried several solutions and suggestions from different forums, but I haven't been able to resolve it.

  2. baseplate-admin commented on Jan 12, 2025

    @baseplate-admin
    Author

    Have you found a solution yet? I'm also having the same problem. I tried several solutions and suggestions from different forums, but I haven't been able to resolve it.

    Yep,

    Please check out this code, and it has to have this folder too

  3. decryptable commented on Jan 15, 2025

    @decryptable

    From what I've seen, it looks like it's the same as my project in how it's done. What exactly is the main problem?

  4. baseplate-admin commented on Jan 15, 2025

    @baseplate-admin
    Author

    Does your app include ublock orgin folder?

  5. Decapitated commented on Jul 1, 2025

    @Decapitated

    I had the same problem as OP. After some searching, I found this Reddit comment.

    So basically,

    // Install uBlock Origin and assign a PrompDelegate.
    geckoRuntime!!.webExtensionController.promptDelegate = BlockifyPromptDelegate()
    geckoRuntime!!.webExtensionController
        .install("resource://android/assets/ublock_origin-1.64.0.xpi")
        .accept(
            { extension ->
                Log.i("MessageDelegate", "Extension installed: $extension")
            },
            { e ->
                Log.e("MessageDelegate", "Error registering WebExtension", e)
            }
        )
    
    // Give uBlock Origin permission.
    class BlockifyPromptDelegate : WebExtensionController.PromptDelegate {
        override fun onInstallPromptRequest(
            extension: WebExtension,
            permissions: Array<out String?>,
            origins: Array<out String?>
        ): GeckoResult<WebExtension.PermissionPromptResponse?>? {
            val name = extension.metaData.name
            if(name != null && name == "uBlock Origin") {
                Log.i("PromptDelegate", "Allow uBlock Origin")
                return GeckoResult.fromValue(WebExtension.PermissionPromptResponse(true, true))
            }
            return super.onInstallPromptRequest(extension, permissions, origins)
        }
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions