I want to create a bridge which can communicate between my C# application and extension.
Here is the explanation of what I actually want:
I have created an extension which will get details of HTML element.
But starts every time I start Chrome. Instead of doing this, is there any way I can send a message to my chrome extension to get HTML element details and then send it back to C# application?
I am able to pass information to C# using ‘XMLHttpRequest’ but issue is, it got started when my page gets loaded.
Let me explain to you what I want:
-
When I open my chrome, my extension will start automatically and also my background.cs(background page) will start. (Here I want some client-server kind of communication)
-
Using my C# application I will send some data to the chrome extension (e.g. StartFetchingDocument)
-
Once my extention gets this message (i.e. StartFetchingDocument), then my extension should inject contect-sctipt.js to the selected tab.
I know the rest of what I need to send that data back to C#, but here I got stuck only at this one stage – how to send data from C# to my extension (background page).
Hm…there’s probably better ways, but an easy way might be opening an HttpListener in your c# app and communicate with it from the extension like this:
In the example i’m using jQuery.post, which can be added to the extension context, but you could use XMLHttpRequest if you like it better. And on the c# side:
In the ProcessRequest function you can read post data or send something back.
Get post data:
and send back some stuff with:
Just some quick brainstorming, looking forward to better ideas 🙂