From 03f37fa1a3151c8d471f2821e3a8cd89ee45aae1 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Mon, 29 Mar 2021 23:30:54 +0200 Subject: [PATCH] long live ResizeObserver, let's ditch MutationObserver five-ever --- src/ext/lib/video-data/PlayerData.ts | 8 ++++---- src/ext/lib/video-data/VideoData.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ext/lib/video-data/PlayerData.ts b/src/ext/lib/video-data/PlayerData.ts index 4c63d8a..bd34ae1 100644 --- a/src/ext/lib/video-data/PlayerData.ts +++ b/src/ext/lib/video-data/PlayerData.ts @@ -65,7 +65,7 @@ class PlayerData { extensionMode: any; dimensions: any; private playerIdElement: any; - private observer: MutationObserver; + private observer: ResizeObserver; //#endregion constructor(videoData) { @@ -141,7 +141,7 @@ class PlayerData { try { if (BrowserDetect.firefox) { - this.observer = new MutationObserver( + this.observer = new ResizeObserver( _.debounce( // don't do this too much: this.onPlayerDimensionsChanged, 250, // do it once per this many ms @@ -154,7 +154,7 @@ class PlayerData { } else { // Chrome for some reason insists that this.onPlayerDimensionsChanged is not a function // when it's not wrapped into an anonymous function - this.observer = new MutationObserver( + this.observer = new ResizeObserver( _.debounce( // don't do this too much: (m,o) => this.onPlayerDimensionsChanged(m,o), 250, // do it once per this many ms @@ -172,7 +172,7 @@ class PlayerData { attributeOldValue: true, }; - this.observer.observe(this.element, observerConf); + this.observer.observe(this.element); } catch (e) { console.error("failed to set observer",e ) } diff --git a/src/ext/lib/video-data/VideoData.ts b/src/ext/lib/video-data/VideoData.ts index 4de39ca..6086930 100644 --- a/src/ext/lib/video-data/VideoData.ts +++ b/src/ext/lib/video-data/VideoData.ts @@ -25,7 +25,7 @@ class VideoData { //#region misc stuff vdid: string; video: any; - observer: MutationObserver; + observer: ResizeObserver; extensionMode: any; userCssClassName: string; validationId: number; @@ -182,7 +182,7 @@ class VideoData { // INIT OBSERVERS try { if (BrowserDetect.firefox) { - this.observer = new MutationObserver( + this.observer = new ResizeObserver( _.debounce( this.onVideoDimensionsChanged, 250, @@ -195,7 +195,7 @@ class VideoData { } else { // Chrome for some reason insists that this.onPlayerDimensionsChanged is not a function // when it's not wrapped into an anonymous function - this.observer = new MutationObserver( + this.observer = new ResizeObserver( _.debounce( (m, o) => { this.onVideoDimensionsChanged(m, o) @@ -211,7 +211,7 @@ class VideoData { } catch (e) { console.error('[VideoData] Observer setup failed:', e); } - this.observer.observe(this.video, observerConf); + this.observer.observe(this.video); // INIT AARD this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting