Seeking Guidance on Native App messaging in Firefox Android Add-On Development 1

I am working on an extension/add-on Firefox for android. Our extension wants to communicate with a native app and fetch data from there. I tried nativeMessaging but it is not supported by Firefox. . While researching, I came across articles discussing Firefox’s 120 build, which is expected to provide enhanced support for add-ons. However, I couldn’t find any information regarding native app messaging in these resources. I’m seeking assistance or guidance from someone who may have insights into this matter.

Hey @diwakar, welcome to the Mozilla Discourse!

You’re correct that the Native Messaging API isn’t supported on Android.

That said, it may be possible for you to achieve your desired result by exposing a local HTTP server in your Android app and having your extension communicate with the app via HTTP requests. If you choose to explore this route, please be careful. It’s possible that another other application on the device may attempt to impersonate either your extension or your Android app.

Another option is to have both your extension and app route messages to each other through a backend server. If you already have systems in place to validate that connections from your Android app and extension are valid, this approach may be preferable since it potentially avoids having to setup up a secure messaging channel between app an extension on device.

1 Like

I have successfully deployed a frontend app to Firefox on Android with WebSocket using the CivetWeb library built using the NDK. Configuring CivetWeb is easy if you know how to build using NDK. SSL can be enabled too, but it is unnecessary for localhost.

The current drawback is that CivetWeb does not work past NDK 23. NDK 21 is recommended.

Ultimately I would recommend that you write your app for Java/Kotlin though, if you need native code. It is the officially supported way.

Or use the non-Firefox WebView.

This I haven’t tested, but it might be possible to have some communication by using the WebView to fetch updates on the frontend on Firefox and pass them through JNI.