Talk to MacOSX app from Chrome Extension

Deadly 提交于 2020-05-16 21:48:06

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/38446438/talk-to-macosx-app-from-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!