From 60f940f4db671191ccf1db8a781494da4f4e5320 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Mon, 12 Apr 2021 19:01:28 +0200 Subject: [PATCH] try/catch in aspect ratio getter --- src/ext/lib/video-data/PlayerData.ts | 13 +++++++++---- src/ext/lib/video-data/VideoData.ts | 7 ++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ext/lib/video-data/PlayerData.ts b/src/ext/lib/video-data/PlayerData.ts index 12f7771..f623fd1 100644 --- a/src/ext/lib/video-data/PlayerData.ts +++ b/src/ext/lib/video-data/PlayerData.ts @@ -72,11 +72,16 @@ class PlayerData { * Gets player aspect ratio. If in full screen, it returns screen aspect ratio unless settings say otherwise. */ get aspectRatio() { - if (this.dimensions.fullscreen && !this.settings.getSettingsForSite()?.usePlayerArInFullscreen) { - return window.innerWidth / window.innerHeight; - } + try { + if (this.dimensions?.fullscreen && !this.settings.getSettingsForSite()?.usePlayerArInFullscreen) { + return window.innerWidth / window.innerHeight; + } - return this.dimensions.width / this.dimensions.height; + return this.dimensions.width / this.dimensions.height; + } catch (e) { + console.error('cannot determine aspect ratio!', e); + return 1; + } } constructor(videoData) { diff --git a/src/ext/lib/video-data/VideoData.ts b/src/ext/lib/video-data/VideoData.ts index f493e79..b7d4416 100644 --- a/src/ext/lib/video-data/VideoData.ts +++ b/src/ext/lib/video-data/VideoData.ts @@ -49,7 +49,12 @@ class VideoData { get aspectRatio() { - return this.video.videoWidth / this.video.videoHeight; + try { + return this.video.videoWidth / this.video.videoHeight; + } catch (e) { + console.error('cannot determine stream aspect ratio!', e); + return 1; + } } constructor(video, settings, pageInfo){