Skip to content

Commit

Permalink
make customEvent 'ratechange' work in shadow DOMs (igrigorik#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraig-droid authored Jun 17, 2024
1 parent 5bcfcd2 commit 4ccae47
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,13 @@ function setupListener() {
log("Speed event propagation blocked", 4);
event.stopImmediatePropagation();
}
var video = event.target;
/**
* Normally we'd do 'event.target' here. But that doesn't work with shadow DOMs. For
* an event that bubbles up out of a shadow DOM, event.target is the root of the shadow
* DOM. For 'open' shadow DOMs, event.composedPath()[0] is the actual element that will
* first receive the event, and it's equivalent to event.target in non-shadow-DOM cases.
*/
var video = event.composedPath()[0];

/**
* If the last speed is forced, only update the speed based on events created by
Expand Down Expand Up @@ -745,6 +751,9 @@ function setSpeed(video, speed) {
if (tc.settings.forceLastSavedSpeed) {
video.dispatchEvent(
new CustomEvent("ratechange", {
// bubbles and composed are needed to allow event to 'escape' open shadow DOMs
bubbles: true,
composed: true,
detail: { origin: "videoSpeed", speed: speedvalue }
})
);
Expand Down

0 comments on commit 4ccae47

Please sign in to comment.