I'm writing browser extensions for Firefox, Chrome and Safari. When attempting to connect to a WebSocket server using the Safari Extension where there is NO server listening on a particular port, my Safari extension doesn't throw an exception, nor does it call onerror. Instead, the Safari extension's onclose handler is being called. I'm also seeing this message in the console:
[Error] WebSocket network error: The operation couldn’t be completed. Connection refused (global.html, line 0)
On Firefox and Chrome, it seems to handle it properly AFAIK and calls 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 like "global-handler". I put exception handlers in each of the WebSocket handlers and also the function that has the code that creates the WebSocket, but I am not seeing any exceptions caught.
Is this a known problem? Is there a way to find out if the connection failed?
Edit: This happens on a simple web page in Safari as well:
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");
};