javascriptc#google-chromegoogle-chrome-extensionchrome-native-messaging

C# host with Chrome Native Messaging Extension


I am trying to get Native Messaging between my chrome extension and my c# application. But below are my questions :

  1. How to open only one Native app at a time ?. Clicking on the extension again will open the Native app again & again.

  2. Can I communicate with an already open native app?

I built my extension and native app using the code in the following question.

Native Messaging Chrome


Solution

  • Native Messaging works by starting a new application process, then communicating with it over STDIO as long as Chrome keeps the connection open. If you don't keep the connection open, you can't "reconnect" to an application. To keep the connection open, you'll probably need to open it from the event script.

    See this question: How to get Chrome Native Messaging to Listen to application? It discusses some of this topic, including C#-specific ways to keep it a single instance.

    Furthermore, consider using alternative solutions, such as web communication (for example, WebSockets) to a local port exposed by your native code, though it creates new security questions (how to make sure it's your extension talking to it?).