I didn’t end up getting this to work reliably via a Chrome extension content script — YouTube seems to check isTrusted
on clicks, which makes synthetic extension clicks unreliable.
Instead, I switched to a Tampermonkey userscript, which can run directly in the page context and works fine for automatically skipping ads.
Here’s the script I’m using now:
// ==UserScript==
// @name AutoSkipYT
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Skips YouTube ads automatically
// @author jagwired
// @match *://*.youtube.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const CHECK_INTERVAL = 500; // ms between checks
function skipAd() {
const skipButtons = [
'.ytp-ad-skip-button-modern',
'.ytp-skip-ad-button',
'button[aria-label^="Skip ad"]'
];
for (const selector of skipButtons) {
const button = document.querySelector(selector);
if (button && button.offsetParent !== null) {
button.click();
return;
}
}
// Seek through unskippable ads
const video = document.querySelector('video');
if (video && document.querySelector('.ad-showing, .ad-interrupting')) {
video.currentTime = video.duration - 0.1;
}
}
setInterval(skipAd, CHECK_INTERVAL);
document.addEventListener('yt-navigate-finish', skipAd);
})();
Notes:
This script clicks the skip button when it appears.
If the ad is unskippable, it jumps the video to the end of the ad.
Because it runs in page context, it works without hitting YouTube’s synthetic click checks.
If you still want a Chrome extension version, you’d likely need to inject the script into the page so that clicks are isTrusted
. But if you just want it to work, this userscript gets the job done.