browser.runtime.sendNativeMessage is not a function

RESOLVED WORKSFORME

Status

RESOLVED WORKSFORME
a year ago
2 months ago

People

(Reporter: Manuel.Spam, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

691 bytes, application/x-xpinstall
Details
(Reporter)

Description

a year ago
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)
(Reporter)

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)
      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.
(Reporter)

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?
(Reporter)

Comment 4

a year ago
Created attachment 8893877 [details]
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)
(Reporter)

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:

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

Try moving your calls into a background page.
(Reporter)

Comment 7

a year ago
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?

Comment 8

a year ago
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
Last Resolved: a year ago
Resolution: --- → WORKSFORME

Updated

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