Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 738
odieatla Avatar asked Sep 30 '26 10:09

odieatla


1 Answers

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.

like image 114
Graham Miln Avatar answered Oct 02 '26 05:10

Graham Miln



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!