Closed Bug 1386820 Opened 7 years ago Closed 7 years ago

browser.runtime.sendNativeMessage is not a function

Categories

(WebExtensions :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: Manuel.Spam, Unassigned)

Details

Attachments

(1 file)

691 bytes, application/x-xpinstall
Details
I try to use the "sendNativeMessage" function:

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/sendNativeMessage

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)
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)
      alert(a);

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.
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?
Attached file test.xpi
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)
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.
You are trying to use nativeMessaging inside a content script. What is available in a content script is documented here:

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts

Try moving your calls into a background page.
Thanks.

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?
Yes, that's documented here: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts#Communicating_with_background_scripts

Closing this bug based on the use case presented in the test.xpi.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WORKSFORME
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: