-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blocking YouTube Video ads with Electron Ad-Blocker #2458
Comments
Hi @sgebr01, Could you please share how you are using/initializing the adblocker? This library does not contain filter lists per se, but does allow you to download community-driven lists with default presets for convenience. Not blocking ads on YouTube could either be an issue with the lists or with the adblocker library itself. If you can share the exact way you are creating the adblocker in your project I can try to reproduce. |
Thanks for responding, here is the code that I'm using that involves the ad-blocker. I got this from the documentation, but really struggled to understand how this adblocker works since the documentation didn't really seem to cover most of it for me. This does block banner ads on every website I visit through my electron app, but it doesn't block Video ads on YouTube. My entire code in my main JS file is this.
|
Additionally, there are times when even the banners on YouTube don't get blocked - but I think this can easily be solved by adding another filter list. |
I could reproduce. I seems like part of the adblocker features are not working on Electron anymore, it might have been caused by a regression with recent updates. To be honest I am not actively using Electron in any project at the moment and it has always been challenging to keep the adblocker working on this platform in the past. I will try to find some time to investigate. |
OK, so as of now - what should I do? Can I install a previous past version and that will work? |
Let me check if I can find an older version that works. |
For example v13 works, maybe a more recent version would also work. |
OK, I will try that out and let you know - additionally, I had one more question as to using multiple filter lists. I saw another closed post that used this, but when I tried that method, it did not work, none of the filter lists did their job. Here is the link - #1901 What I've tried to do my multiple filter lists is this - is this the right way?
|
No this will not work, at the moment you can only use one blocker per session. The only way would be to use |
There is something fishy with the adblocker in electron, I have been able to make it work with v17 (latest release) but it never works on the first start. If I cache the engine on disk then restart then it works, it is unclear to me why that is happening. |
I'm just trying to load all of these filter lists at once, to have a bigger database of filters. I have also noticed that the video ads are blocked at times, I'm not sure if that has anything to do with this, but it does work from time to time when I run it - even though I didn't cache the engine. |
It seems that for some reason the preload script is either not registered as it should be, or does not manage to send messages to the main process. I am not sure why that is. Since that does not happen consistently I have tried to let some time with a setTimeout without success. On your example above, you need to enable the blocker before you navigate to YouTube:
|
OK, and this should work? |
Try to call |
There is still this issue where the preload script does not consistently work. But with your current code the adblocker will never block on initial page load. |
Using the array seems to work - here is what I have done -
|
Also, which is v13, my current version is only 1.23.6 using npm. |
v13 should be the version of Electron you are using. |
My bad, I thought you were talking about the version of the ad blocker. I've tried using v13.0.0 of electron to no success. Could the version of electron-packager and builder make a difference? This is with the latest version of the ad-blocker. |
@sgebr01 Can you share the latest version of the code you are using please? |
Sure - my main.js is this
This is my preload.js
And my package.json
Additionally these are the packages that are installed
|
Have you been able to find out why? If you are busy since it's a weekday, no worries - I appreciate your help so far. |
Hey @sgebr01, sorry I did not get the time to investigate further but I will try to find the time. It's definitely something that needs fixing. |
No worries, go at your own pace. |
Hello @sgebr01, Also note the use of async and await to wait for the fetch to complete. import { ElectronBlocker, fullLists } from '@cliqz/adblocker-electron';
import { fetch } from 'cross-fetch';
import { session } from 'electron';
import { readFileSync, writeFileSync } from "original-fs";
module.exports = async function enableAdBlocker(){
var adBlocker = await ElectronBlocker.fromLists(
fetch,
fullLists,
{
enableCompression: true
},
{
path: `engine.bin`,
read: async (...args) => readFileSync(...args),
write: async (...args) => writeFileSync(...args),
}
);
adBlocker.enableBlockingInSession(session.defaultSession);
} Also make sure you are using the latest version: |
Thanks for chiming in @kylegundersen. Out of curiosity, does it also work when you start your Electron app immediately after deleting the on-disk cache? ( (sorry for closing/opening, wrong button :)) |
@remusao yea it does. Actually I had the same issue a week or two ago. Upgrading to the latest version is what fixed the YouTube Ad issue for me, because of the filter updates in the lists. |
Sure, I will try this out later today, and get back to you if it works. |
@kylegundersen I am still seeing some video ads, here is my code - however, I am guessing that some are getting blocked since I can see in my terminal Main.js Code
|
Hey @sgebr01, I was using commonJS to load it from a separate file, so you can remove the |
My bad, I'm trying that out now - also thank you for your help. Are the error codes I showed you in my previous comment showing that the video is getting blocked? I tried it, and I'm still getting video ads. |
Here is my updated code.
|
Sorry to hear that @sgebr01. What version of Electron and Cliqz are you running? Also I would try adding await and putting the BTW I tested it locally with the code you provided above and it worked as expected for me once I moved the Here was my package.json dependencies. "dependencies": {
"@cliqz/adblocker-electron": "^1.23.6",
"cross-fetch": "^3.1.5"
},
"devDependencies": {
"electron": "^16.0.6"
} |
I tried this out as well, it works on some videos, but on others it doesn't, Is it 100% effective for you? I replaced my dependencies and installed the exact versions with npm, afterwards, I moved the enableAdBlocker function inside my create window function as well. I'm guessing this is still an issue with the ad-blocker? |
@sgebr01 Yea it has been 100% effective for me. When upgrading dependencies did you then delete the bin file? |
That might be the issue, I think I need to do that. |
Yea its my bad, I probably should have removed it from the sample, its just a simple way to cache filters for consecutive startups. |
Still didn't work, after deleting that file. |
Maybe there is a preferred place to put the enableAdBlocker function? What is the updated code that you used? I put it into the createWindow function, I'm not sure if placing it towards the end or the beginning will have an effect? |
AD-blocker YouTube.zip |
OK, I tried this, it looks like it is working, but I think I will need to test it more. I'll try it tomorrow, and get back to you. Thank You for the Help! |
Looks like it's working, I'm not sure why I didn't it work for me before. I am guessing that this should work on webview elements as well? |
@sgebr01 Awesome, glad you got it all to work. Please feel free to close this issue.😄 |
Sure, I'm just wondering why it didn't work with the previous versions - thanks though for the help, I really appreciate it! |
I have been able to block most site ads with the original filter list, but for some reason this filter list does not work on YouTube Video Ads. What can I do to make it work on YouTube Video Ads? Is there a recommended filter list for this use case?
The text was updated successfully, but these errors were encountered: