Minor fixes for comms and mutation detectìon
This commit is contained in:
parent
e269ff3d79
commit
78395e3ea0
@ -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]) {
|
||||
|
||||
@ -149,7 +149,11 @@ class CommsClient {
|
||||
|
||||
// send to server
|
||||
if (!context?.borderCrossings?.commsServer) {
|
||||
try {
|
||||
return chrome?.runtime?.sendMessage(null, message, null);
|
||||
} catch (e) {
|
||||
console.warn(`Failed to send message to background script. Error:`, e, 'data:', {message, context});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user