Safari Web Extension sendNativeMessage and browser.runtime.connectNative don't work

We have Safari App(!) Extension, the one that has no background page. We want to port it to a Safari Web Extension, so it can run on iOS 15.

The App Extension extensively uses safari.extension.dispatchMessage, and we want to replace it with browser.runtime.sendNativeMessage, which doesn't work at all. There's a couple questions:

  1. How to get a response from browser.runtime.sendNativeMessage
  2. Do we have to use browser.runtime.connectNative? How to use it?
  3. Where is the documentation on all of this?

When you create a Safari web extension in xcode, you're provided with a SafariWebExtensionHandler file. Which has a beginRequest method. When you call browser.runtime.sendNativeMessage from your background script, it calls that function in your swift code.

In order to have access to the sendNativeMessage method in your background script you must add the nativeMessaging permission to the permissions array in your manifest.json.

Safari Web Extension sendNativeMessage and browser.runtime.connectNative don't work
 
 
Q