browser.runtime.sendNativeMessage is not a function



a year ago
5 months ago


(Reporter: Manuel.Spam, Unassigned)


Firefox Tracking Flags

(Not tracked)



(1 attachment)

691 bytes, application/x-xpinstall


a year ago
I try to use the "sendNativeMessage" function:

According to the documentation this should be available since Firefox 50.

I have the "nativeMessaging" permission in my Addon and I could use "connectNative" (this is defined).

For "sendNativeMessage", I get the message in the summary. For some reason it doesn't end in the browser console. I had to use "try catch" to get it...
Can you please attach a complete extension that exhibits this problem?
Flags: needinfo?(Manuel.Spam)

Comment 2

a year ago
The extension, I try to create, is still in development and only consists of alerts and debug messages.

I would have to create a simple testcase.

I have the following in my extension:

 for (a in browser.runtime)

And "sendNativeMessage" is not listed with this, so it doesn't get defined.

This is my "permission block":

  "permissions": [
    "nativeMessaging", "<all_urls>"

I can wrap both (permissions and the two lines code) into a small test extension if this helps.

Comment 3

a year ago
OK... I can limit this to the "exportFunction" feature.

What I tried was to get some info from page javascript.

So I exported one function using "exportFunction" to page javascript and this function is meant to use the external native application.

I could use "sendNativeMessage" from outside of my exported function but not in it.

Is this expected behaviour?

Comment 4

a year ago
Created attachment 8893877 [details]

Very simple test addon.

I now finally give up.

Sorry guys, but the error messages, created by the whole "Web Extensions" stuff, are total bu**sh*t. Not fun at all to track down such errors!

If there already is a bug about the error message situation with WebExtensions (just undefined functions, no clear errors in browser console if permission is missing, ...) please tell me or directly add me to the CC list. Thanks.
Flags: needinfo?(Manuel.Spam)

Comment 5

a year ago
Forgot to mention: This also affects "connectNative".
I do not know what I'm doing wrong, but my Addon is not able to use the "nativeMessaging" stuff.

Comment 6

a year ago
You are trying to use nativeMessaging inside a content script. What is available in a content script is documented here:

Try moving your calls into a background page.

Comment 7

a year ago

What I need is communication from the page javascript itself to the external native application.

I tried exporting functions from the content script, but this doesn't seem to work now.

Do I really have to communicate from background script to content script and from there to page javascript or is there any chance for a more direct way?

Comment 8

a year ago
Yes, that's documented here:

Closing this bug based on the use case presented in the test.xpi.
Last Resolved: a year ago
Resolution: --- → WORKSFORME


5 months ago
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.