Skip to content
Advertisement

Communication between browser extension and windows service

I have a browser extension(For chrome, Firefox, Edge) and now I want to query some info from the extension to the windows service which is running on the same machine.

I need to pass some strings from the extension and the windows service will process these strings and return the processed strings.

I have tried WebAssembly but it does not suit our need because it is compiled code and not running in the background. Also, there are some windows specific headers in the service, and web assembly does not support these headers.

so any idea how can we achieve that?

I will be very thankful to the StackOverflow community.

Advertisement

Answer

You can use native messaging (Chrome docs / MDN)

Create an executable like this:

JavaScript

Register the path of the relevent manifest file using the relevant registry key (probably using an installer to install both the executable and the manifest file + registry key)

And it is relatively simple to call from the chrome extension side:

JavaScript

Or re-running the executable every time (you can remove the loop in the executable if you use this):

JavaScript

Alternatively, you can run a HTTP server on some arbitrary (but unchanging) port which does this processing, and your web extension can simply POST data to `http://localhost:${port}`. You should probably allow the host/port to be changed in the config.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement