browser.runtime.sendNativeMessage completion handler is never run

I'm working on a Safari Web Extension. I can send a message from the background page to the app extension using browser.runtime.sendNativeMessage, however I'm not able to receive any response.

Similarly, when I run the sample code for Messaging a web extension's native app, this code is executed:

Code Block swift
browser.runtime.sendNativeMessage("application.id", {message: "Hello from background page"}, function(response) {
    console.log("Received sendNativeMessage response:");
    console.log(response);
});

There should be a log on the background page saying "Received sendNativeMessage response:". However it looks like the response handler never runs. Am I missing something ?

Replies

That is expected to work. Can you please file some feedback on Feedback Assistant?

Edit: In the meantime, you could call runtime.connectNative and add a message handler to that port.

Thanks!
Thank you for your reply, I submitted a report. I tried sending messages to a port from the app extension, and indeed it's working (I thought only the app could do that, not the app extension). Thanks for the work-around.

I had a similar issue. In my case I had not added the permission "nativeMessaging" to permissions in manifest. I know it is mistake but someone may do the same mistake since there are no informative logs relating to that.