x0a / uBO-YouTube

Easier way to exempt your favorite YouTube channels from adblocking.
GNU General Public License v3.0
124 stars 8 forks source link

Advertisers-muting resulted in video autoplaying in inactive tabs (Firefox) #18

Closed seafang closed 3 years ago

seafang commented 3 years ago

In Firefox (I believe in Chrome as well) I can open multiple tabs by clicking links with MMB (middle mouse button). These tabs would be inactive, and won't start playing until I put them in-focus.

However, if I set certain advertisers to be muted, and video in any inactive tab (from whitelisted channels) happen to begin with ad from these advertisers, add-on's muting action would lead to these particular tabs auto-playing immediately in the background.

Is it possible to mute (and possibly auto-skipping blacklisted advertiser as well) only when the tab is in focus (instead of as soon as they are opened)?

x0a commented 3 years ago

Hey, thanks for the report. I classified this as a bug to start with (could be a bug, haven't had time to test in Firefox)

Just to clarify (correct me if I'm wrong), you want to preserve the default behavior of not doing/playing anything until the page is first put in focus. Then afterwards perform any extension related actions like auto-skipping, muting once the ad starts playing?

Have you tried 'Anti-startle mode' in https://youtube.com/ubo-yt#ads ?

seafang commented 3 years ago

Yes. If videos in these tabs begin with non-muted ads, their behavior will be normal, i.e. nothing will be played until I put them in focus, both the ads and the videos themselves. It's only when they have muted ads, which then the extension would immediately mute these tabs as soon as they are opened, in turn leading to the muted ads (and afterwards the videos) start playing in the background.

I've noticed that sometimes the videos themselves in these inactive tabs would be played muted. Since I've never put them in focus in the first place, I don't know if the ad prior to the video is muted or skipped. This only happens very occasionally (and only in inactive tabs), and since I have way more ads being set as muted than skipped, it could be skipped ad that trigger this.

I don't have anti-startle mode enabled, I would do so now and see how it works. But I suspect anti-startle mode may not be able to fully resolve the issue, as skipping blacklisted ad by the extension might have similar issue. Or, maybe, in that case, extending the functionality of anti-startle mode to skipped ads as well can be a feasible work-around (or at least temporary solution)? I don't know much about how the extension works, it's just a random thought.

x0a commented 3 years ago

Thanks for the response.

Yeah that makes sense. What's happening is that we added some built-in adblocking due to another issue where ads were being blocked entirely, and part of that means that when an ad should not be playing it is force skipped automatically, and YouTube automatically plays the following video.

Pausing after a muted ad (if the tab is not in focus) is the intended purpose of Anti-Startle mode, but I found that this wasn't working properly in Firefox (definitely a bug) and pushed an update accordingly in https://github.com/x0a/uBO-YouTube/commit/faccadf9cdcf01ce5467e369224844ae77b8acc3 . Turns out Firefox responds much faster to muting/unmuting the tab than Chrome so the following check that is supposed to pause the video thinks the tab is not muted, so it doesn't auto-pause the video. The slight tweak should fix that.

But let me know if the behavior still continues after turning on Anti-Startle mode. I'll add an option at some point to prevent automatic skipping if the tab is not in focus, maybe in a week or two.

seafang commented 3 years ago

Thanks for the follow-up! Anti-Startle mode works well so far, video would be paused accordingly in inactive tab.

Though in the last few days I've noticed a new issue (sorry for keep bringing in new issues). While ad at the start of a video would play or be skipped normally, almost all ads in the middle of any video would be skipped. Sometimes the end screen of the ad is still there, so I can confirm that the advertisers are not on my blacklist. All these skipped ad would not be shown in the 'Recent ads' list (even though I've seen some of their end screens. On the list there are only ads from the start of videos). I've turned off all options temporarily (including Anti-Startle mode) and the issue persist, so it has nothing to do with any of the option.

This is a newly-emerged issue from the last few days, could coincide with the recent update of the extension, or uBlock might have recently done something that broke the extension again.

x0a commented 3 years ago

I've been trying to re-create the issue and have only been able to reproduce it exactly once. I'm going to be trying to reproduce this over the next few days.

Does this happen on all whitelisted channels? And does it happen all the time?

Thanks

seafang commented 3 years ago

Yes, it was at its peak when I made the previous comment, 100% of mid-video ads were skipped on all whitelisted channels. It has become slightly better in the last few days, very occasionally some ads were able to slip through, but this was very random and >80-90% of ads were still skipped (without appearing on the Recent ads list of course). I haven't yet encounter a video which all the mid-video ads managed to be played normally, at most only one out of them was able to slip through.

One thing to note is that I've muted the majority of the common advertisers (i.e. I would rarely encounter non-muted ad in the first place). It's possible that muted ad was part of the issue.

Thank you again for the follow-up!

x0a commented 3 years ago

I believe I finally figured out the cause of the bug. It has to do with the hookLinks function which tries to detect in advance if the user is navigating away from a whitelisted page. It works by listening for click events on anchor tags i.e. <a href='...' />

The problem was a lot of interactive buttons on YouTube (like the Like/Dislike/Reply buttons) are basically href-less links, so clicking them does not actually navigate to a different page but hookLinks thinks we just navigated to null which is not whitelisted. So the built-in adblocker would be turned on with interactions like Liking the video or replying to a comment.

Should be fixed with a simple null/empty string check.

v0.11.8 is already available in Mozilla Addons. Try reloading your extensions and verify that this fixes the problem.

Thanks again

seafang commented 3 years ago

Everything has been working just fine so far. No issue for muting / skipping / pausing ads. Thank you!!