WebSocket.onerror

The WebSocket interface's onerror event handler property is a function which gets called when an error occurs on the WebSocket.

You can also add an error event handler using addEventListener().

Syntax

webSocket.onerror = eventHandler;

Value

A function or event handler which is executed whenever an error event occurs on the WebSocket connection.

Example

webSocket.onerror = function(event) {
  console.error("WebSocket error observed:", event);
};

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
onerror
5
12
7
10
12.1
5
≤37
18
7
12.1
4.2
1.0

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onerror