From 565e18e8a36eeb54a277994221d8cd45ebb3752f Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 17 Sep 2019 13:49:50 -0600 Subject: [PATCH] Handle WebRTC security errors as non-fatal Fixes https://github.com/vector-im/riot-web/issues/10898 In some restricted modes of Firefox, the WebRTC classes aren't super available: accessing them can cause SecurityErrors to be raised. In these conditions, we should just disable WebRTC support instead of falling apart. --- src/webrtc/call.js | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/webrtc/call.js b/src/webrtc/call.js index 8aa4d2841..d0f5311e8 100644 --- a/src/webrtc/call.js +++ b/src/webrtc/call.js @@ -1370,24 +1370,36 @@ module.exports.createNewMatrixCall = function(client, roomId, options) { return getUserMedia.apply(w.navigator, arguments); }; } - webRtc.RtcPeerConnection = ( - w.RTCPeerConnection || w.webkitRTCPeerConnection || w.mozRTCPeerConnection - ); - webRtc.RtcSessionDescription = ( - w.RTCSessionDescription || w.webkitRTCSessionDescription || - w.mozRTCSessionDescription - ); - webRtc.RtcIceCandidate = ( - w.RTCIceCandidate || w.webkitRTCIceCandidate || w.mozRTCIceCandidate - ); - webRtc.vendor = null; - if (w.mozRTCPeerConnection) { - webRtc.vendor = "mozilla"; - } else if (w.webkitRTCPeerConnection) { - webRtc.vendor = "webkit"; - } else if (w.RTCPeerConnection) { - webRtc.vendor = "generic"; + + // Firefox throws on so little as accessing the RTCPeerConnection when operating in + // a secure mode. There's some information at https://bugzilla.mozilla.org/show_bug.cgi?id=1542616 + // though the concern is that the browser throwing a SecurityError will brick the + // client creation process. + try { + webRtc.RtcPeerConnection = ( + w.RTCPeerConnection || w.webkitRTCPeerConnection || w.mozRTCPeerConnection + ); + webRtc.RtcSessionDescription = ( + w.RTCSessionDescription || w.webkitRTCSessionDescription || + w.mozRTCSessionDescription + ); + webRtc.RtcIceCandidate = ( + w.RTCIceCandidate || w.webkitRTCIceCandidate || w.mozRTCIceCandidate + ); + webRtc.vendor = null; + if (w.mozRTCPeerConnection) { + webRtc.vendor = "mozilla"; + } else if (w.webkitRTCPeerConnection) { + webRtc.vendor = "webkit"; + } else if (w.RTCPeerConnection) { + webRtc.vendor = "generic"; + } + } catch (e) { + logger.error("Failed to set up WebRTC object: possible browser interference?"); + logger.error(e); + return null; } + if (!webRtc.RtcIceCandidate || !webRtc.RtcSessionDescription || !webRtc.RtcPeerConnection || !webRtc.getUserMedia) { return null; // WebRTC is not supported.