odieatla
odieatla

Reputation: 1079

catch error thrown by Safari using javascript

I was developing a web app using web socket and it works fine on all major browsers but Safari. Then I did a little digging and find out although WebSocket is supported in Safari 7 but it doesn't work well with SSL. It keeps giving me error message in the error console like this:

WebSocket network error: OSStatus Error -9807: Invalid certificate chain.

I want to catch this error and then do some workaround. However I think it's an error from Safari and I tried try/catch when I initialized the WebSocket, it didn't fall into catch statement.

So I wonder if I can catch this kind of error which comes from Browser?

Any help would be great!

Thanks!

Upvotes: 3

Views: 1323

Answers (1)

Graham Miln
Graham Miln

Reputation: 2792

The onclose property of the WebSocket is called when WebSocket network error: OSStatus Error -9807: Invalid certificate chain occurs.

By attaching a function to onclose it is possible to detect the WebSocket failing to connect due to an unsupported or failed SSL/TLS connection.

As noted in the comments, onerror is not called for SSL/TLS connection errors on Safari v9 (Mac) or before.

Upvotes: 2

Related Questions