Native messaging host communication

Hello!
We have a Firefox extension which communicates to a native messaging host declared in its manifest. We’ve noticed one weird moment about how the browser sends messages to the native host. For some reason, it spawns a new process for each new message. Is that expected behavior?
The flow looks something like this on the extension side:

  • background script initiates port by calling “browser.runtime.connectNative”
  • native messaging host process starts up
  • and then the extension uses “browser.runtime.sendNativeMessage” to send messages. Each of these calls result in a new native host process (with a new uid, this is occurring on macOS).

Is this supposed to happen or it it possible to send messages to the existing instance on native messaging host?
This is mainly a concern for optimization. not to start all the routines on the native messaging host side.
Thanks!

If you use runtime.connectNative you would use the Port it returns to then send messages to the instance that started. runtime.sendNativeMessage is essentially a shorthand for doing connectNative and then sending a single message.

1 Like

Hey, @freaktechnik. thanks for a prompt response! Indeed, this works as intended with this correction. It keeps the process alive and reuses the first instance spawned after establishing the connection.