Communication between Chrome extension and running Windows service - google-chrome

I am developing chrome extension which needs to communicate with my running service. I tried to use Chrome Native messaging, but I didn't manage to make the extension communicate with running service.
I did manage to communicate with native (not already running app), as described here:
Google chrome native messaging

It's impossible for Native Messaging to "connect" to an already-running process.
Therefore, you have to either use something else (a local WebSockets server in your service is a good alternative idea) or make the Native Messaging host be some sort of "proxy": you can start a new one from Chrome, and it uses some other channel to communicate with the already-running service.

Related

Is it possible to use Google Chrome as a proxy server?

In my particular network environment the Google chrome executable can access via an authenticated outgoing proxy server external web sites. Other executables however (when pointing to that outgoing proxy) are not able to do so.
I now have the idea to use Chrome itself as a local proxy for other executables like git or pip. - Is this possible, say, with a Chrome extension or with a tool that uses Chrome in a headless mode to connect to the Internet?
To clarify, I am not asking how to configure the proxy settings inside Chrome - I have successfully done this. I am asking how I can set up Chrome to receive HTTP(S) requests from other local programs and pass the requests on as an intermediate proxy (to the outgoing proxy specified in Chrome's settings).
On its own, no: Chrome will not open a port that other software can connect to. Even WebRTC requires an intermediate server to begin a peer to peer connection between browsers.
However Chrome supports Native Messaging, which means it will execute a specific native application that already exists on the system.
With this set up you can have:
a native application that accepts incoming connections and forwards data to the extension.
the extension listens to messages from the application and sends them via Chrome elsewhere on the internet.

How Google Chrome extension check if a specific app installed on the client machine or not?

i want to know if it is possible for google chrome extension to check if there is already a native app installed on the client machine or not
So we established that you control both the extension and the native app.
Note that the extension cannot access the filesystem to check for existence of files; presumably, you also want to detect the presence of the app even if it's not running, and ideally be able to launch it if it isn't.
The best way to check that the app is installed is to provide a Native Messaging host in the app. The installer would then add a registry key to let Chrome know that the native host is present, and you can connect to it.
Now, there are some considerations:
You can't check the presence of the native host without trying to launch it.
The process launched that way lives only as long as its communication port is opened in the extension.
The communication channel between the extension and the app is the STDIO.
It would not be wise to just declare your main Windows Forms app as the native host. You should write a separate utility app that can communicate according to the Native Messaging protocol (even if to just answer "I'm here"). If needed, it can launch the main app and/or communicate with it as needed using other channels. You could also just launch the main app from your native host and then communicate with it using WebSockets.

How to access installed apps through browser

1password's chrome extension checks to see if the app is installed on your desktop before you can actually do anything.
I was wondering on how could I implement something similar?
This is probably implemented using the Native Messaging API.
Alternatively, the app can simply have a web server / websockets server open on the local machine, but it would mean the connection will only work while the app is running.

What is Native Messaging between applications and how does it work?

The Chrome developer docs refer to something called Native Messaging to communicate with other desktop applications directly from the Chrome extension or app.
How can I tell when a desktop app has such native messaging available and what kind of communication it can accept? Is there a way to get the application to expose what it will communicate about?
If I needed to talk to the original developers of that desktop app, is this even the most common terminology (native messaging) so they understand what I am referring to?
Does native messaging function the same on both Windows and Mac?
An extension can only communicate with a native desktop application if that application is registered as a "native messaging host". This means that there must be some manifest file at a pre-defined, platform-specific location that declares that the application has "native messaging" capabilities and which extensions are allowed to communicate with this native messaging host.
So, by default, it is extremely unlikely that any of your desktop apps support native messaging. This term is a specific to Chrome/Chromium, and might not be understood by developers who are not familiar with Chrome/Chromium. Though every competent developer should be able to get native messaging to work after reading the documentation of native messaging.
Currently, the only supported way of communicating with native applications is through the standard input and output pipes (stdin / stdout) via a simple yet strict protocol. If the desktop app has a command-line interface, then you can easily write a proxy application that serves as a native messaging host and interacts with the desktop application. It is essentially the bridge between your Chrome extension and some other application. This proxy application can be written in any language that supports stdin/stdout, and it does not require any cooperation from the original developers of the desktop app.
The native messaging protocol is the same across all platforms, but you have to take the endianness of the system into account, and the locations of the manifest file also platform-dependent.

Phonegap Bonjour/Zeroconf or Websocket IP Discovery from HTML5

I am trying to implement a Phonegap (HTML5) application which connects to a Websocket server (running in an embedded device, also has Bonjour service) to exchange data within home network.
I would like to know the best possible way of detecting the server IP using Phonegap. I have explored and found that Titanium and Quickconnect support Bonjour. But I would like to stick to Phonegap for various other reasons.
Any alternative way of detecting the server IP within the local network is also okay.
Need your suggestion.
There are two iOS Bonjour plugin implementations for Phonegap (Cordova) on Github:
https://github.com/jarnoh/cordova-dnssd
https://github.com/SayGoSolutions/Cordova-BonjourBrowserProxy
Unfortunately I haven't found a cross-platform implementation.