I have a Swift binary helper that works as a native messaging host for Chrome, Edge, and Firefox using stdin/stdout. I want to use the same binary for a Safari Web Extension as well.

Since Safari requires a macOS app as a container for Web Extensions, is there a way to establish native messaging directly from SafariWebExtensionHandler using stdin/stdout? Or does Safari enforce a different communication mechanism?

I’d like to keep the same approach as other browsers. Any guidance on making this work would be appreciated!

Further details regarding my implementation:

I have a Swift binary helper that serves as a native messaging host for Chrome, Edge, and Firefox. These browsers communicate with the helper using stdin/stdout, following the standard native messaging protocol. This setup works well for intercepting extension messages and processing them in my Swift binary.

Now, I want to reuse this same helper binary for a Safari Web Extension. However, I understand that Safari does not support native messaging in the same way as Chrome-based and Firefox extensions. Instead, Safari Web Extensions rely on a macOS app to facilitate communication with native processes.

My current approach:

  • The Safari Web Extension sends messages via SafariWebExtensionHandler (inside the macOS app).

  • The macOS app needs to forward these messages to my existing Swift helper binary.

  • Ideally, I would like to establish a direct connection between SafariWebExtensionHandler and my helper binary via stdin/stdout (just like other browsers).

My questions:

  1. Is it possible for SafariWebExtensionHandler to communicate with a native process using stdin/stdout, similar to how Chrome and Firefox do?

  2. If direct native messaging via stdin/stdout is not supported in Safari, what is the recommended way to connect my macOS app to my existing Swift binary without rewriting the entire communication logic?

  3. Would I need to modify my helper binary significantly, or can the macOS app act as a simple bridge while keeping the stdin/stdout approach intact?

I’m looking for the most efficient way to integrate my existing native messaging host without having to rewrite too much of the existing logic. Any guidance, workarounds, or best practices would be greatly appreciated!

I have a Swift binary helper that works as a native messaging host for Chrome, Edge, and Firefox using stdin/stdout. I want to use the same binary for a Safari Web Extension as well.
 
 
Q