I am writing browser extensions for Firefox, Chrome and Safari. When I try to connect to a WebSocket server using the Safari extension, where there is no server listening on a specific port, my Safari extension does not throw an exception and does not raise an onerror. Instead, the Safari onclose extension handler is called. I also see this message in the console:
[Error] WebSocket network error: The operation couldn’t be completed. Connection refused (global.html, line 0)
In Firefox and Chrome, it seems to handle AFAIK correctly and raise an onerror.
I'm just doing something like this:
var socket = new WebSocket('ws://127.0.0.1:'+inPort, inHandlerName);
socket.binaryType = "arraybuffer";
then declare handlers for onopen, onclose, onerror and onmessage. inPort is 9000, and inHandlerName is a string of type "global-handler". I put exception handlers in each of the WebSocket handlers, as well as a function that has code that creates the WebSocket, but I don't see any exceptions.
Is this a known issue? Is there a way to find out if a connection has occurred?
Edit: This also happens on a simple web page in Safari:
var theSocket = new WebSocket('ws://127.0.0.1:9000', 'global-message');
theSocket.onopen = function()
{
console.log("onopen");
};
theSocket.onerror = function()
{
console.log("onerror");
};
theSocket.onmessage = function()
{
console.log("onmessage");
};
theSocket.onclose = function()
{
console.log("onclose");
};
source
share