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.
pull/816/head
Matthias Seemann 2023-08-03 21:23:27 +02:00 committed by GitHub
parent 918bf0ae6d
commit 566e52f1dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -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;