Fixed adblocker

This commit is contained in:
Mr. Stallion 2020-10-24 18:28:39 -05:00
parent d69cab94ec
commit 73345e38ae
1 changed files with 22 additions and 1 deletions

View File

@ -219,11 +219,32 @@ function createWindow(): Electron.BrowserWindow | undefined {
'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badware.txt', // uBlock Origin Badware
'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt', // uBlock Origin Resource Abuse
'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/unbreak.txt' // uBlock Origin Unbreak
]
],
{
enableCompression: true
},
{
path: path.join(baseDir, 'adblocker.bin'),
read: fs.promises.readFile,
write: fs.promises.writeFile
}
).then(
(blocker) => {
blocker.enableBlockingInSession(electron.session.defaultSession);
// Temp fix -- manually override adblocker's preload script 1) to point to CJS; 2) to use absolute path
const preloadScript = path.resolve(path.dirname(require.resolve('@cliqz/adblocker-electron-preload')), 'preload.cjs.js');
electron.session.defaultSession.setPreloads(
_.concat(
_.filter(
electron.session.defaultSession.getPreloads(),
(p) => (p.indexOf('adblocker-electron-preload') < 0)
),
[preloadScript]
)
);
// blocker.on('request-blocked', (request: Request) => {
// console.log('blocked', request.url);
// });