How to connect chrome web extension with localhost server?
<p>I have a google chrome web extension that needs to communicate with a Qt desktop application - but how?</p>

<ul>
<li><p>There is chrome's native messaging, but as I want to support multiple browsers/OS, this would be too much effort because it is only for chrome.</p></li>
<li><p>Then there is <a href="https://stackoverflow.com/questions/12056380/how-can-i-send-a-message-from-google-chrome-extension-to-desktop-application">this</a> post that suggests setting up a local server. This is what I did, see below.</p></li>
</ul>

<p>I have set up a server with Qt with <code>QTcpServer</code> that uses <code>QTcpSocket</code>'s on 127.0.0.1 (localhost). But a web extension can not listen to sockets, only chrome apps <a href="https://developer.chrome.com/apps/app_network" rel="nofollow noreferrer">can</a>. There are 2 possible solutions on my mind:</p>

<ul>
<li><p>As a workaround, I could perhaps write a small chrome app. The Qt application would talk to the chrome extension via the chrome app (chrome apps support sockets). But I think this method is clumsy and not quite elegant. </p></li>
<li><p>On the other hand, I have read about <code>socket.io</code>. 
The idea is: The chrome extension talks via <code>http requests</code> with socket.io, and socket.io talks via sockets with my desktop app. Is this a possible solution?</p></li>
</ul>

<p>What I also tried, is to directly connect to the local server with the following code. In my Qt server application, I see that there is a new connection. But I can not get a response at all (either my Qt code is wrong or it is because extensions can not listen to sockets?)</p>

<pre><code>var xhr = new XMLHttpRequest();
xhr.open("GET", "http://localhost:12345", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
  alert('This is the response from the server: '+ xhr.responseText );
}
</code></pre>