I have a google chrome web extension that needs to communicate with a Qt desktop application - but how?
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.
Then there is this post that suggests setting up a local server. This is what I did, see below.
I have set up a server with Qt with QTcpServer
that uses QTcpSocket
's on 127.0.0.1 (localhost). But a web extension can not listen to sockets, only chrome apps can. There are 2 possible solutions on my mind:
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.
On the other hand, I have read about
socket.io
. The idea is: The chrome extension talks viahttp requests
with socket.io, and socket.io talks via sockets with my desktop app. Is this a possible solution?
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?)
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 );
}