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

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.

Related

chrome.enterprise.deviceAttributes availability for force-installed PWAs in chrome enterprise

I'm trying to determine if I can access any browser api for chrome OS that will allow me to identify the device that its running on when the application has been force-installed in kiosk mode as a PWA.
We're running into exactly the same issue right now. The correct path seems to be to create a PWA and to connect it to a (pre-installed) extension that has access to the enterprise.deviceAttributes:
See https://developers.chrome.com/apps/migration:
"If there is a capability that your Chrome App has that the regular web platform can't provide, it might be available as an extension API. In this case, you use a progressive web app together with an externally connectable extension your web app can send messages to."
enterprise.deviceAttributes are only accessible if the calling App/Site is pre-installed to the device and not loaded dynamically, so it cannot run in the PWA by design.
But with this tutorial, it seems possible:
https://developer.chrome.com/extensions/messaging#external-webpage
We're looking into that right now and will post our progess here.

How to distribute a Native Messaging Host with Chrome Extension

I developed an extension that communicates with a host (also developed by me), as provided by the https://developer.chrome.com/extensions/nativeMessaging example, and it works just fine.
Now I need to distribute my host with my extension and I couldn't find in Distributions how can I package my host along my extension. Are there any examples of how can I do it? Or must I distribute my host elsewhere?
I couldn't find in Distributions how can I package my host along my extension.
Support for this has been requested and turned down by Chrome developers.
I would recommend reading that thread for some insights in how native hosts are supposed to work according to them.
Or must I distribute my host elsewhere?
That's the idea. You need an installer hosted somewhere else.
wOxxOm's proposal is not going to work seamlessly, since a Native host cannot function without registering it with the system (e.g. adding a registry key on Windows) - something an extension cannot trigger.
It's possible you can still follow the bundle-download-open route for an installer, but I imagine it may get frowned upon by Chrome Web Store.

Communication between Chrome extension and running Windows service

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.

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.

Can an extension provide its own location to a native messaging host?

I have an extension that uses native messaging to launch a server. It
sends a message through the native messaging API which launches a host
process; the host process launches an HTTP server on an ephemeral port
and sends the port number back to the extension; the extension then
connects to that port. All of this works fine.
I am attempting to generalize this mechanism in two ways, and cannot
figure out how to do it.
(1) I would like to allow multiple applications to communicate with a
single installed native messaging host. Currently, each application
needs to install its own host which is configured with information
about the application (basically contains all the code for a "server"
for that application). I would like to use a single host which can
serve arbitrary applications.
(2) I would, thus, like to be able to start the process by having the
application connect to the native messaging host and provide it with
the installation directory of the extension. Then I'd like the native
messaging host to be able to read that directory looking for
configuration information, code, etc. so that it can initialize itself
appropriately. Basically, I'd like the native messaging host to be
able to run code and scripts bundled with the extension, in arbitrary
data formats (in my case, probably plain text, JavaScript files, and Java JAR/class
files) to implement the "server" or "native" portion of the
application.
Given that NPAPI plugins are supposed to be re-implemented using the
native messaging API, I am assuming that this is possible and that I
just can't figure out how to do it.
The only approach that I've come up with that might work seems overly
complicated and underperformant -- basically, I believe I could allow
the host to load code from the extension by having the host send a
"request" to the client (by posting a JSON message, with a request ID and a path, say), and having the client use XMLHttpRequest with ArrayBuffer (in the most general case)
to its own chrome-extension:// URL (as obtained by chrome.runtime using the path as the argument to getURL) to
read its files, serializing them back to the host as JSON. Would this
work? Is this the intended approach?