I have not tested the code so you have to test it…
1- Create a plain text file for the database and name it database.dat
2- Put the domains only in above file, without any extra path or characters. One domain per line.
example:
badurl.com
newbadurl.com
exoclick.com
googleads.g.doubleclick.net
ad.doubleclick.net
Do not add paths as it wont work in this code:
www.example.com/somepath/other
3- Change the manifest.json
"background": {
"scripts": ["background.js"]
},
4- Create a single background.js
Paste the following only in background.js
'use strict';
let db = []; // session Global
// ----- parse & cache the database data
fetch('database.dat')
.then(response => response.text())
.then(text => { db = text.trim().split(/[\r\n]+/); })
.catch(error => console.log(error));
chrome.webRequest.onBeforeRequest.addListener( details => {
let url = new URL(details.url);
return { cancel: url && url.hostname && db.includes(url.hostname) };
},
{urls: ["http://*/*", "https://*/*"]},
["blocking"]
);
Let me know how it works out.