I’m having trouble getting my JavaScript code to automatically click the skip button on YouTube advertisements. I’ve tried different approaches and even though I can successfully locate the button element in the DOM, the click event doesn’t seem to work. I also experimented with pointer events but still no luck.
(function autoSkipAdvertisement() {
var timer = setInterval(function() {
var adSkipBtn = document.querySelector('.ytp-ad-skip-button');
if (adSkipBtn) {
adSkipBtn.click(); // Try to click the skip button
console.log('Advertisement bypassed!');
clearInterval(timer); // Stop the timer
} else {
console.log('Skip button not found');
}
}, 1000); // Check every second
})();
The button gets detected properly but clicking it programmatically doesn’t trigger the skip action. Has anyone faced this issue before? What am I missing here?
I’ve faced this exact problem before. YouTube filters out programmatic clicks by checking the isTrusted
property of events. When you call click()
in JavaScript, it creates an untrusted event that YouTube ignores. I tried dispatching custom MouseEvent objects with proper coordinates and timing, but YouTube’s detection got even more sophisticated. The site also checks mouse movement patterns and click timing relative to when the button appeared. Your selector approach is correct, but YouTube’s client-side protection makes automated clicking nearly impossible through regular DOM manipulation. YouTube treats any non-human interaction as potential abuse - that’s why your console shows successful detection but nothing actually happens.
YouTube blocks your programmatic clicks because their security system detects they’re not real user interactions. The platform checks if events have the proper chain that comes with genuine clicks and kills synthetic ones at the handler level. I hit this same wall building accessibility tools - even legitimate use cases get blocked because YouTube can’t tell automation from assistive tech. They don’t just check event properties either. They analyze timing patterns, where your cursor is, and keyboard state when the click happens. The skip button works fine on its own, but YouTube’s player wrapper stops the actual ad skip function when it spots automated patterns.
YouTube’s anti-bot detection is brutal now. Even with mouseover simulation and delays, they’re tracking behavioral patterns. I tried this approach and got maybe a week before they caught on with an update. The skip button’s there, but YouTube’s JS framework intercepts clicks and runs them through security validation first.
YouTube blocks automated clicking - they’ve built their system specifically to stop what you’re trying to do. Their event listeners check for real user interactions, so script-generated clicks get filtered out or ignored. Even if your code finds the right element, YouTube’s security will catch that it wasn’t a genuine user click. Plus, YouTube constantly changes their DOM structure and class names, so your selectors will break regularly. Your best bet is a browser extension with proper permissions instead of injected JavaScript, though that’s still sketchy territory with YouTube’s terms of service.