Triggering Click Event on YouTube Skip Ad Button

tmp7
Jan 2

I have this one Chrome extension that I developed for personal use. It injects a code to a website to add a custom keyboard shortcuts for quickly accessing a specific feature.

Then, one day I wonder if I can skip a YouTube video ad using it. 

It's not that simple, apparently. 

There's a way to end a video ad by setting the current video time to infinity. The problem is what comes after: the skip ad button.


Note: this is for educational purpose and not for encouraging a certain behaviour.


Click Event

Interestingly enough, dispatching a click event doesn't trigger a click for that button.

skipAdButton?.click();
skipAdButton?.dispatchEvent(new Event(eventType, { bubbles: true }));

I even tried dispatching all type of events from that button up to the video container. Still, no luck. I wonder how they programmed something like that?

Focus Event and Accessibility

For the last resort, I tried triggering a focus event to that button, then I pressed Enter manually. 

It works! But that's not a surprise. 

It is expected for such a big application that accessibility is important and I can skip the video ad with just a keyboard.

skipAdButton?.focus();

After that, it ended up my curiosity and I sought no further way to tinker with it. It's a good experience though. Maybe they check for the focus event? Or perhaps I should just trigger a keyboard event, specifically the Enter key?


***

Posted in:
Newer posts

Comments