diff --git a/src/lib/browser/Adblocker.ts b/src/lib/browser/Adblocker.ts index d74c298c..b353bdc8 100644 --- a/src/lib/browser/Adblocker.ts +++ b/src/lib/browser/Adblocker.ts @@ -1,8 +1,9 @@ import { request } from 'undici'; +import { report } from '../../helpers/errorReporting'; import { log as mainLog } from '../../helpers/logger'; -// TO DO: copy this at compile time. +// TO DO: Cronjob to update this list on our servers const list = 'https://raw.githubusercontent.com/badmojr/1Hosts/master/Pro/domains.txt'; @@ -15,26 +16,30 @@ export class Adblocker { #hostnames: Set = new Set(); async load(): Promise { - const res = await request(list, { - method: 'GET', - }); - - let body = ''; - for await (const chunk of res.body) { - body += chunk.toString(); - } - const lines = body.split(/[\r\n]+/); + try { + const res = await request(list, { + method: 'GET', + }); + + let body = ''; + for await (const chunk of res.body) { + body += chunk.toString(); + } + const lines = body.split(/[\r\n]+/); - for (const line of lines) { - if (!line.startsWith('#')) { - this.#hostnames.add(line); + for (const line of lines) { + if (!line.startsWith('#')) { + this.#hostnames.add(line); + } } - } - log.info('Ready', { - entries: this.#hostnames.size, - lastMod: res.headers['last-modified'], - }); + log.info('Ready', { + entries: this.#hostnames.size, + lastMod: res.headers['last-modified'], + }); + } catch (err: any) { + report(new Error('Error while setting up adblocker'), { err }); + } } match(url: URL): boolean {