From 78395e3ea065ab56d50b428c47c84b94a4f85e31 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sat, 6 Jun 2026 03:29:46 +0200 Subject: [PATCH] =?UTF-8?q?Minor=20fixes=20for=20comms=20and=20mutation=20?= =?UTF-8?q?detect=C3=ACon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ext/module/EventBus.ts | 7 +++++-- src/ext/module/comms/CommsClient.ts | 6 +++++- src/ext/module/video-data/VideoData.ts | 12 +++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/ext/module/EventBus.ts b/src/ext/module/EventBus.ts index 92d818d..51ea35d 100644 --- a/src/ext/module/EventBus.ts +++ b/src/ext/module/EventBus.ts @@ -106,7 +106,7 @@ export default class EventBus { } send(command: string, commandData: any, context: EventBusContext = {}) { - context = this.cloneContext(context); // Firefox throws an error if we don't clone the context. + // context = this.cloneContext(context); // Firefox throws an error if we don't clone the context. if (context.visitedBusses?.includes(this.uuid)) { console.warn('this bus was already visited before. Doing nothing.'); @@ -116,7 +116,10 @@ export default class EventBus { console.warn('this command was already sent'); return; } - context.visitedBusses = [...context.visitedBusses ?? [], this.uuid]; + + // we want to avoid re-assigning context.visitedBusses if possible + // in order to reduce the amount of garbage that needs to be collected. + context.visitedBusses ? context.visitedBusses.push(this.uuid) : context.visitedBusses = [this.uuid]; // execute commands we have subscriptions for if (this.commands?.[command]) { diff --git a/src/ext/module/comms/CommsClient.ts b/src/ext/module/comms/CommsClient.ts index 3bffaa5..1078644 100644 --- a/src/ext/module/comms/CommsClient.ts +++ b/src/ext/module/comms/CommsClient.ts @@ -149,7 +149,11 @@ class CommsClient { // send to server if (!context?.borderCrossings?.commsServer) { - return chrome?.runtime?.sendMessage(null, message, null); + try { + return chrome?.runtime?.sendMessage(null, message, null); + } catch (e) { + console.warn(`Failed to send message to background script. Error:`, e, 'data:', {message, context}); + } } } diff --git a/src/ext/module/video-data/VideoData.ts b/src/ext/module/video-data/VideoData.ts index d671bc1..ff57740 100644 --- a/src/ext/module/video-data/VideoData.ts +++ b/src/ext/module/video-data/VideoData.ts @@ -47,6 +47,7 @@ class VideoData { videoLoaded: boolean = false; videoDimensionsLoaded: boolean = false; active: boolean = false; + private preventVideoOffsetValidation: boolean = false; //#endregion //#region misc stuff @@ -511,6 +512,10 @@ class VideoData { if (this.destroyed) { return; } + if (!mutationList) { + this.logger.warn('onVideoMutation', 'mutation was triggered, but mutationList is missing. Something is fishy. Mutation will be ignored. Observer:', observer); + return; + } // verify that mutation didn't remove our class. Some pages like to do that. let confirmAspectRatioRestore = false; @@ -530,7 +535,7 @@ class VideoData { return; } - for(const mutation of mutationList) { + for (const mutation of mutationList) { if (mutation.type === 'attributes') { if( mutation.attributeName === 'class' && mutation.oldValue.indexOf(this.baseCssName) !== -1 @@ -590,7 +595,9 @@ class VideoData { // sometimes something fucky wucky happens and mutations aren't detected correctly, so we // try to get around that + this.preventVideoOffsetValidation = true; setTimeout( () => { + this.preventVideoOffsetValidation = false; this.validateVideoOffsets(); }, 100); } @@ -611,6 +618,9 @@ class VideoData { } validateVideoOffsets() { + if (this.preventVideoOffsetValidation) { + return; + } // validate if current video still exists. If not, we destroy current object try { if (! document.body.contains(this.video)) {