Reputation: 11
I recently started making an extension for Google Chrome. A few days ago everything was working but the "Uncaught ReferenceError: click is not defined" errors started popping up. Do you know where the error is and why it is happening. I am sending all the code so that there are no problems.
manifest.js
{
"icons": { "128": "icon128.png" },
"name": "ADSkip",
"version": "1.2",
"description": "Block and Skip Ads",
"permissions": ["webRequest", "webRequestBlocking", "<all_urls>","tabs","activeTab"],
"content_scripts": [{
"js": ["script.js"],
"run_at": "document_idle",
"matches": ["<all_urls>"]
}],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}
background.js
chrome.webRequest.onBeforeRequest.addListener(
function(details) { return {cancel: true}; },
{urls:
["*://*.doubleclick.net/*",
"*://*.googleadservices.com/*",
"*://*.googlesyndication.com/*",
"*://*.adskeeper.com/*",
"*://*.eternalfury.com/*",
"*://*.g.cda.pl/*",
"*://*.ocdn.eu/lps/*",
"*://*.adskeeper.co.uk/*",
"*://*.trafficstars.com/*",
"*://*.tsyndicate.com/*",
"*://*.greatdexchange.com/*",
"*://*.panel.zenbox.pl/file-pp/012021/336x280.png*",
"*://*.mgid.com/*",
"*://*.mrex.exs.pl/*",
"*://*.toglooman.com/*",
"*://*.www3.smartadserver.com/*",
"*://*.fwcdn.pl/prt/a1/hbo/*",
"*://*.r2---sn-f5f7kn7z.c.2mdn.net/*",
"*://*.ssl.cdne.cpmstar.com/*",
"*://*.cat.nl.eu.criteo.com/*",
"*://*.affilixxl.de/*",
"*://*.s1.adform.net/*",
"*://*.taboola.com/*",
"*://*.content.foreshop.net/*",
"*://*.tri-table.com/*",
"*://*.a.spolecznosci.net/*",
"*://*.mult-film.net.ru/*",
"*://*.ocs-pl.oktawave.com/*",
"*://*.moat.com/*"]
},
["blocking"]
);
script.js
setInterval(function(){
var skipButton = document.getElementsByClassName("ytp-ad-skip-button");
if(skipButton != undefined && skipButton.length > 0) {
console.log("Ad detected");
skipButton[0].click();
}
}, 3000)
setInterval(() => {
click("ytp-ad-overlay-close-button");
}, 300);
console.log("Ads closed");
setInterval(() => {
click("avnts-close-btn-con");
}, 300);
console.log("Ads closed");
I have also image :
Upvotes: 0
Views: 127
Reputation: 7666
I guess the problem has to do with the way you click ytp-ad-overlay-close-button
and avnts-close-btn-con
. Why don't you use it the same way as with ytp-ad-skip-button
?
setInterval(() => {
var closeButton = document.getElementByClassName('ytp-ad-overlay-close-button');
if (closeButton != undefined && closeButton.length > 0) {
closeButton[0].click();
console.log('Ads closed');
}
}, 300);
setInterval(() => {
var closeBtn = document.getElementByClassName('avnts-close-btn-con');
if (closeBtn != undefined && closeBtn.length > 0) {
closeBtn[0].click();
console.log('Ads closed');
}
}, 300);
Upvotes: 1