4

I have a chrome extension running in my browser. I also have a Mac OSX app I wrote in Swift/Objective-c in Xcode. I am wondering how this chrome extension can talk to the Mac OSX app on the same computer.

I am aware of the Chrome Extension API, but do not know how I can capture the information from that is sent by Chrome in Swift. Does anyone know how to do this?

Thanks

hockeybro
  • 981
  • 1
  • 13
  • 41

1 Answers1

5

There are two broad approaches you can take.

  1. Native Messaging API. This does have the limitation that Chrome must launch the process (and communicate to it via STDIO) - you cannot attach to an existing process. The upside - the communication channel is pretty secure.

  2. Your native app can expose a web server (or better yet, a WebSockets server) on a local port. The extension can then try to connect to this port and talk to your app. The downside is that anything (at least on the machine) can connect to your native app.

    This is a frequently used approach; for example, 1Password or various IDE integrations work this way.

You could combine the two approaches to launch the app with a "launcher" Native Host if it's not running.

Community
  • 1
  • 1
Xan
  • 74,770
  • 16
  • 179
  • 206
  • 1
    If I wanted to do option 1, what would I need to configure on the Mac OSX native app side? – hockeybro Jul 19 '16 at 18:37
  • It should talk over STDIO conforming to Native Messaging protocol as defined in the docs. – Xan Jul 19 '16 at 18:38
  • @Xan @hockeybro Any luck finding how to get macos to see the messages via stdio? Ive tried many attempts using `FileHandle.standardInput` but no luck – daihovey May 31 '18 at 16:19
  • 1
    @daidai Did you ever make it work ? I want to use the Native Messaging API but I can't find docs on how to do it from MacOS /Swift – marcos1490 Apr 30 '20 at 21:55