From 566e52f1dd38944498f1fc03bc81a1668e169bf7 Mon Sep 17 00:00:00 2001 From: Matthias Seemann <296476+semmel@users.noreply.github.com> Date: Thu, 3 Aug 2023 21:23:27 +0200 Subject: [PATCH] Tolerate inaccessible localStorage When reading from localStorage, treat security exceptions like absent values. This supports running in third-party contexts when cross-origin cookies are blocked by the browser. --- .../src/OpenViduInternal/WebRtcStats/WebRtcStats.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openvidu-browser/src/OpenViduInternal/WebRtcStats/WebRtcStats.ts b/openvidu-browser/src/OpenViduInternal/WebRtcStats/WebRtcStats.ts index adc9572a..9f798295 100644 --- a/openvidu-browser/src/OpenViduInternal/WebRtcStats/WebRtcStats.ts +++ b/openvidu-browser/src/OpenViduInternal/WebRtcStats/WebRtcStats.ts @@ -121,7 +121,13 @@ export class WebRtcStats { } public initWebRtcStats(): void { - const webrtcObj = localStorage.getItem(this.STATS_ITEM_NAME); + let webrtcObj = null; + // When cross-site (aka third-party) cookies are blocked by the browser, + // accessing localStorage in a third-party iframe throws a DOMException. + try { + webrtcObj = localStorage.getItem(this.STATS_ITEM_NAME); + } + catch(e){} if (!!webrtcObj) { this.webRtcStatsEnabled = true;