-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix playback speed issue on certain detected media #137
Conversation
src/contents/lib/SpeedController.ts
Outdated
) | ||
|
||
this.elements.forEach((element) => { | ||
inspectMediaElements((element: MediaElement) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a new MutationObserver
each time it is called, which should result in a resource leak.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
src/contents/lib/SpeedController.ts
Outdated
) | ||
|
||
this.elements.forEach((element) => { | ||
inspectMediaElements((element: MediaElement) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using inspectMediaElements
inside setPlaybackRate
will call the function every time the speed should change and attach a new MutationObserver.
Due to this, we might have 100s to 1000s of MutationObservers after long videos which would be a performance issue and we'll also have a memory leak in the callback function as it will be called every time a new element appears for each observer.
I'd suggest instead creating a central inspectMediaElements
in the SpeedController constructor and have it update this.elements
dynamically instead.
Moved inspectMediaElements to the constructor where it dynamically updates this.elements
Hopefully that's what you meant? I'm not really familiar with JS |
Yes looks good now - thank you again for the contribution! |
Fixes #136 where certain media types would not be detected by
document.querySelectorAll("video, audio")