Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:27:01+00:00 2026-06-16T01:27:01+00:00

I want to create a bridge which can communicate between my C# application and

  • 0

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:

  1. 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)

  2. Using my C# application I will send some data to the chrome extension (e.g. StartFetchingDocument)

  3. 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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:27:02+00:00Added an answer on June 16, 2026 at 1:27 am

    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:

    var listener = "http://localhost:60024/";
    
    function getCommand(){
    
        var postData = { 
            "action": "getCommand" 
        };
    
        $.post( listener, postData, function(response){
            //Parse response and do whatever c# wants
        });
    }
    
    function send(data){
    
        var postData = {
            "action" : "send",
            "data": data
        };
    
        $.post(listener, postData);
    }
    
    
    setInterval(getCommand, 1000);
    

    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:

    using System;
    using System.Net;
    
    
    namespace HttpListenerTEst
    {
        class Program
        {
            private static HttpListener _listener;
    
            static void Main(string[] args)
            {
                _listener = new HttpListener();
                _listener.Prefixes.Add("http://localhost:60024/");
                _listener.Start();
                _listener.BeginGetContext(new AsyncCallback(Program.ProcessRequest), null);
    
                Console.ReadLine();
            }
    
            static void ProcessRequest(IAsyncResult result)
            {
                HttpListenerContext context = _listener.EndGetContext(result);
                HttpListenerRequest request = context.Request;
    
                //Answer getCommand/get post data/do whatever
    
                _listener.BeginGetContext(new AsyncCallback(Program.ProcessRequest), null);
            }
        }
    }
    

    In the ProcessRequest function you can read post data or send something back.

    Get post data:

            string postData;
            using (var reader = new StreamReader(request.InputStream, request.ContentEncoding))
            {
                postData = reader.ReadToEnd();
                //use your favourite json parser here
            }
    

    and send back some stuff with:

            string responseString           = "This could be json to be parsed by the extension";
    
            HttpListenerResponse response   = context.Response;
            response.ContentType            = "text/html";
    
            byte[] buffer                   = System.Text.Encoding.UTF8.GetBytes(responseString);
            response.ContentLength64        = buffer.Length;
            Stream output                   = response.OutputStream;
    
            output.Write(buffer, 0, buffer.Length);
            output.Close();
    

    Just some quick brainstorming, looking forward to better ideas 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create an application with animate button? how can i do? after click
my first question here. I am trying to create a simple application which takes
I want to create OS X application which shows up and getting focused with
I want create an app for my institute. The problem is: my application will
I have been given a task to create a bridge between C# and Java.
I want create wordpress website into which I want create user management... That means
i want create image animation , i have 50 images with png format now
I want create module which update list of usb devices automatically (not only mass
I have a question about how to structure communication between a (new) Firefox extension
I want create a pdf using iText. The method which does this is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.