SponsorBlock icon indicating copy to clipboard operation
SponsorBlock copied to clipboard

[BUG] Whitelist not reliably working

Open jogerj opened this issue 4 years ago • 2 comments

SponsorBlock sometimes retrieves an incorrect channel ID for whitelist. The issue is usually reproducible when the user clicks on a video, then without closing/leaving the window opens another video. The channel ID returned would be the previous video's, not the actual video.

Secondly, there's also the problem where SponsorBlock would sometimes store an alias instead of the full 24 character unique ID (see example of config export below). The problem is sometimes YouTube would return the full unique ID instead of the alias.

"whitelistedChannels": [
    "TrashTaste",
  ],

If I manually set through options the channel ID (e.g. replace "TrashTaste" with "UCcmxOGYGF51T1XsqQLewGtQ"), the channel would be correctly identified as part of whitelist. It would be better to always prefer unique IDs over vanity URLs

I've struggled with similar issues upon retrieving channel IDs in another project and I've resorted to the following solution (Source)

const channelId = await async function () {
	const channelUrlLead = ["https://www.youtube.com/channel/", "http://www.youtube.com/channel/"];
	const targets = [location.href];
	for(const t of targets){
		for(const c of channelUrlLead){
			if (t && t.startsWith(c)){
				return t.split(/[?#]/)[0].substr(c.length);
			}
		}
	};
	const resp = await fetch(location.href);
	const doc = new DOMParser().parseFromString(await resp.text(), "text/html");
	try {
		return doc.querySelector("meta[itemprop='channelId']").getAttribute("content");
	} catch (_) {};
}();

This solution tries to find URLs on the page with http(s)://www.youtube.com/channel/ as prefix, otherwise retrieve a copy of the page and grab content attribute from meta. This code however is untested outside YouTube. Performance wise, there's no noticable delay. See this repo for this code being in use

I'm not too familiar with the structure of the project to commit changes myself without breaking things, hopefully this would help.

jogerj avatar Sep 01 '21 02:09 jogerj

Will there be a fix for this? It is really annoying having to re whitelist a channel every few days.

HappyHub1 avatar Mar 16 '22 18:03 HappyHub1

this should have been fixed in #1250 with a consistent channelID stored

mchangrh avatar May 11 '22 02:05 mchangrh