Start a local program from Chrome/Chromium browser - google-chrome

What are the options for executing a local client-side program directly from Chrome/Chromium?
Here's the criteria:
ease of installation
cross-platform support
control over security (no other than the specified program can be
executed)
Currently, I can think of three options
write a Chrome plugin
clients run a local web server
a Java Applet
Are there any other options? The client side runs Javascript and is accessing a RESTful API to receive the data. Or maybe a way to directly execute a local program with the user's consent from Chrome?

Related

Setting cookies to chrome running in headless mode

I am planning to use chrome.exe to take a png snapshot of a web page.
The web page has references to js files that are served by an application server. Application server needs session cookies to authrize and server the pages.
I could not find any options to pass cookies to chrome.ext.
I have searched in google, but most suggestions are pointing to use selenium web driver. Making use of selenium web driver for chrome is making me choose compatible versions only. I have to frequently update the driver if the chrome version changes. It is not acceptable for my use case.
Executing the command mentioned below using java process builder.
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe " -headless -hide-scrollbars -disable-gpu -screenshot=C:\Users\abc\Desktop\tmp\file1.png C:/Users/abc/test.html
I need a way to pass cookies without using any third party libraries (webdriver, puppeteer etc..)

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.

Can you enable chrome.storage and chrome.fileSystem for normal localhost testing?

I'm developing a Chrome App and it's irritating using the suggested workflow of manually refreshing the app every time I make a change. I'd like to use a normal localhost server workflow but I need access to chrome.storage and chrome.fileSystem. Is there a way to enable these features outside of the extensions sandbox?
Is there a way to enable these features outside of the extensions sandbox?
No.
Not directly, anyway.
You could conceivably make a proxy extension/app that will execute privileged commands for you using "externally_connectable" messages.
But that will not help you in development - you'll need to proxy all API calls in a complicated way. It would probably also fail for APIs that require user gestures.
You should instead look into programmatically reloading your app by some external command. This is possible - an extension using management API and a native "proxy" module using WebSockets or Native Messaging can allow you to refresh your app by any event in the system.
It's the approach taken by GhostText, for instance.

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?