Chrome extension - WebSocket No Connection Made

601 views
Skip to first unread message

איתמר פרץ

unread,
Aug 19, 2014, 6:56:46 PM8/19/14
to chromium-...@chromium.org
I'm using WebSocket in order to send data from chrome extension to local Java application.
The JS code in the chrome application is :

    var ws = new WebSocket("ws://127.0.0.1:8080/");
    
    ws.onopen = function() {
    alert("Opened!");
    ws.send("Hello Server");
    };
    
    ws.onmessage = function (evt) {
    alert("Message: " + evt.data);
    };
    
    ws.onclose = function() {
    alert("Closed!");
    };
    
    ws.onerror = function(err) {
    alert("Error: " + err);
    };

The problem comes up when no connection is ever made .I've tested the server side by simply running the JS code above , with no connection to any Chrome extension, simply through Chrome browser, and it has worked just fine.

I'd like to know why I cannot create WebSocket connection from Chrome addon, and I'd be grateful if anyone could point me to the solution.
Thanks in advance.

Dave Cooliave

unread,
Aug 22, 2014, 11:16:04 PM8/22/14
to chromium-...@chromium.org, itama...@gmail.com
The code should work. I also use WebSockets in one of my addons. One reason it might be failing is the URL request is being redirected by a proxy switcher extension (e.g. FoxyProxy). I haven't found a single proxy switcher that can handle "ws://" URLs properly.

PhistucK

unread,
Aug 23, 2014, 3:19:59 AM8/23/14
to איתמר פרץ, Chromium-extensions
Did you add the domain (without the port) to the permission key in the manifest?


PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/dbf1168e-f21a-42f9-a186-dc6b0689ddfe%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Reply all
Reply to author
Forward
0 new messages