RTCPeerConnection: icecandidateerror event
Baseline
2026
Newly available
Since April 2026, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The icecandidateerror event is sent to an RTCPeerConnection if an error occurs while performing ICE negotiation through a STUN or TURN server.
This event is not cancelable and does not bubble.
Syntax
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("icecandidateerror", (event) => { })
onicecandidateerror = (event) => { }
Event type
An RTCPeerConnectionIceErrorEvent. Inherits from Event.
Event properties
The RTCPeerConnectionIceErrorEvent interface includes the properties found on the Event interface, as well as the following properties:
addressRead only-
A string providing the local IP address used to communicate with the STUN or TURN server being used to negotiate the connection, or
nullif the local IP address has not yet been exposed as part of a local ICE candidate. errorCodeRead only-
A positive integer value stating the numeric STUN error code returned by the STUN or TURN server. If no host candidate can reach the server, this property is set to the number 701, which is outside the range of valid STUN error codes. This value is reported only once per server URL, and only while the
iceGatheringStateisgathering. errorTextRead only-
A string containing the STUN reason text returned by the STUN or TURN server. If communication with the STUN or TURN server couldn't be established at all, this string will be a browser-specific string explaining the error.
portRead only-
A positive integer value giving the port number over which communication with the STUN or TURN server is taking place, using the IP address given in
address. This isnullif the connection hasn't been established (that is, ifaddressisnull). urlRead only-
A string indicating the URL of the STUN or TURN server with which the error occurred.
Examples
>Basic usage
The following example establishes a handler for icecandidateerror events that occur on the RTCPeerConnection pc. This handler looks specifically for 701 errors that indicate that candidates couldn't reach the STUN or TURN server.
When this happens, the server URL and the error message are passed to a function called reportConnectFail() to log or output the connection failure.
pc.addEventListener("icecandidateerror", (event) => {
if (event.errorCode === 701) {
reportConnectFail(event.url, event.errorText);
}
});
Note that if multiple STUN and/or TURN servers are provided when creating the connection, this error may happen more than once, if more than one of those servers fails. Each provided server is tried until a connection is established.
Specifications
| Specification |
|---|
| WebRTC: Real-Time Communication in Browsers> # dom-rtcpeerconnection-onicecandidateerror> |