-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(plugins): restore and fix adblocker plugin #4212
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
base: master
Are you sure you want to change the base?
Changes from 11 commits
69229da
3eeddfb
2421ff2
5aed127
e490c46
f9613aa
f104f3b
dce57d4
f3e462c
0dfa52d
6b1b336
240b098
be2ae28
b92d44a
5e0375f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /ad-blocker-engine.bin |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,80 @@ | ||||||||||
| // Used for caching | ||||||||||
| import path from 'node:path'; | ||||||||||
| import fs, { promises } from 'node:fs'; | ||||||||||
|
|
||||||||||
| import { ElectronBlocker } from '@ghostery/adblocker-electron'; | ||||||||||
| import { app, net } from 'electron'; | ||||||||||
|
|
||||||||||
| const SOURCES = [ | ||||||||||
| 'https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt', | ||||||||||
| // UBlock Origin | ||||||||||
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters.txt', | ||||||||||
|
||||||||||
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters.txt', | |
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters.txt', |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters.txt', | |
| ttps://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters.txt', |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/quick-fixes.txt', | |
| ttps://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/quick-fixes.txt', |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/quick-fixes.txt', | |
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/quick-fixes.txt', |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ···· with ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/unbreak.txt', | |
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/unbreak.txt', |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/unbreak.txt', | |
| ttps://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/unbreak.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2020.txt', | |
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2020.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ···· with ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2020.txt', | |
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2020.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ···· with ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2021.txt', | |
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2021.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ···· with ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2021.txt', | |
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2021.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2022.txt', | |
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2022.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ···· with ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2022.txt', | |
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2022.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2023.txt', | |
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2023.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2023.txt', | |
| 'https://raw.githubusercontent.com/ghostery/adblocker/master/packages/adblocker/assets/ublock-origin/filters-2023.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| // Fanboy Annoyances | |
| // Fanboy Annoyances |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| // Fanboy Annoyances | |
| // Fanboy Annoyances |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| 'https://secure.fanboy.co.nz/fanboy-annoyance_ubo.txt', | |
| 'https://secure.fanboy.co.nz/fanboy-annoyance_ubo.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| 'https://secure.fanboy.co.nz/fanboy-annoyance_ubo.txt', | |
| 'https://secure.fanboy.co.nz/fanboy-annoyance_ubo.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ···· with ··
| // AdGuard | |
| // AdGuard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| // AdGuard | |
| // AdGuard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ···· with ··
| 'https://filters.adtidy.org/extension/ublock/filters/122_optimized.txt', | |
| 'https://filters.adtidy.org/extension/ublock/filters/122_optimized.txt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| session: Electron.Session | undefined = undefined, | |
| session: Electron.Session | undefined = undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| session: Electron.Session | undefined = undefined, | |
| session: Electron.Session | undefined = undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| cache: boolean = true, | |
| cache: boolean = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| cache: boolean = true, | |
| cache: boolean = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| additionalBlockLists: string[] = [], | |
| additionalBlockLists: string[] = [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| additionalBlockLists: string[] = [], | |
| additionalBlockLists: string[] = [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| disableDefaultLists: boolean | unknown[] = false, | |
| disableDefaultLists: boolean | unknown[] = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| disableDefaultLists: boolean | unknown[] = false, | |
| disableDefaultLists: boolean | unknown[] = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| // Only use cache if no additional blocklists are passed | |
| // Only use cache if no additional blocklists are passed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| // Only use cache if no additional blocklists are passed | |
| // Only use cache if no additional blocklists are passed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ···· with ··
| const cacheDirectory = path.join(app.getPath('userData'), 'adblock_cache'); | |
| const cacheDirectory = path.join(app.getPath('userData'), 'adblock_cache'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| const cacheDirectory = path.join(app.getPath('userData'), 'adblock_cache'); | |
| const cacheDirectory = path.join(app.getPath('userData'), 'adblock_cache'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| if (!fs.existsSync(cacheDirectory)) { | |
| if (!fs.existsSync(cacheDirectory)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ···· with ··
| if (!fs.existsSync(cacheDirectory)) { | |
| if (!fs.existsSync(cacheDirectory)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ····
| fs.mkdirSync(cacheDirectory); | |
| fs.mkdirSync(cacheDirectory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ····
| fs.mkdirSync(cacheDirectory); | |
| fs.mkdirSync(cacheDirectory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| const cachingOptions = | |
| const cachingOptions = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| const cachingOptions = | |
| const cachingOptions = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ····
| cache && additionalBlockLists.length === 0 | |
| cache && additionalBlockLists.length === 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ····
| cache && additionalBlockLists.length === 0 | |
| cache && additionalBlockLists.length === 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ······
| ? { | |
| ? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ······
| ? { | |
| ? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ······
| path: path.join(cacheDirectory, 'adblocker-engine.bin'), | |
| path: path.join(cacheDirectory, 'adblocker-engine.bin'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ················ with ··········
| path: path.join(cacheDirectory, 'adblocker-engine.bin'), | |
| path: path.join(cacheDirectory, 'adblocker-engine.bin'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ······
| read: promises.readFile, | |
| read: promises.readFile, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ······
| read: promises.readFile, | |
| read: promises.readFile, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ················ with ··········
| write: promises.writeFile, | |
| write: promises.writeFile, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ················ with ··········
| write: promises.writeFile, | |
| write: promises.writeFile, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ····
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ······
| : undefined; | |
| : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ······
| : undefined; | |
| : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··
| const lists = [ | |
| const lists = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ···· with ··
| const lists = [ | |
| const lists = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ····
| ...((disableDefaultLists && !Array.isArray(disableDefaultLists)) || | |
| ...((disableDefaultLists && !Array.isArray(disableDefaultLists)) || |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import { contextBridge, webFrame } from 'electron'; | ||
|
|
||
| import { blockers } from './types'; | ||
| import { createPlugin } from '@/utils'; | ||
| import { | ||
| isBlockerEnabled, | ||
| loadAdBlockerEngine, | ||
| unloadAdBlockerEngine, | ||
| } from './blocker'; | ||
|
|
||
| import injectCliqzPreload from './injectors/inject-cliqz-preload'; | ||
| import { inject, isInjected } from './injectors/inject'; | ||
|
|
||
| import { t } from '@/i18n'; | ||
|
|
||
| import type { BrowserWindow } from 'electron'; | ||
|
|
||
| interface AdblockerConfig { | ||
| /** | ||
| * Whether to enable the adblocker. | ||
| * @default true | ||
| */ | ||
| enabled: boolean; | ||
| /** | ||
| * When enabled, the adblocker will cache the blocklists. | ||
| * @default true | ||
| */ | ||
| cache: boolean; | ||
| /** | ||
| * Which adblocker to use. | ||
| * @default blockers.InPlayer | ||
| */ | ||
| blocker: (typeof blockers)[keyof typeof blockers]; | ||
| /** | ||
| * Additional list of filters to use. | ||
| * @example ["https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt"] | ||
| * @default [] | ||
| */ | ||
| additionalBlockLists: string[]; | ||
| /** | ||
| * Disable the default blocklists. | ||
| * @default false | ||
| */ | ||
| disableDefaultLists: boolean; | ||
| } | ||
|
|
||
| export default createPlugin({ | ||
| name: () => t('plugins.adblocker.name'), | ||
| description: () => t('plugins.adblocker.description'), | ||
| restartNeeded: false, | ||
| config: { | ||
| enabled: true, | ||
| cache: true, | ||
| blocker: blockers.InPlayer, | ||
| additionalBlockLists: [], | ||
| disableDefaultLists: false, | ||
| } as AdblockerConfig, | ||
| menu: async ({ getConfig, setConfig }) => { | ||
| const config = await getConfig(); | ||
|
|
||
| return [ | ||
| { | ||
| label: t('plugins.adblocker.menu.blocker'), | ||
| submenu: Object.values(blockers).map((blocker) => ({ | ||
| label: blocker, | ||
| type: 'radio', | ||
| checked: (config.blocker || blockers.WithBlocklists) === blocker, | ||
| click() { | ||
| setConfig({ blocker }); | ||
| }, | ||
| })), | ||
| }, | ||
| ]; | ||
| }, | ||
| backend: { | ||
| mainWindow: null as BrowserWindow | null, | ||
| async start({ getConfig, window }) { | ||
| const config = await getConfig(); | ||
| this.mainWindow = window; | ||
|
|
||
| if (config.blocker === blockers.WithBlocklists) { | ||
| await loadAdBlockerEngine( | ||
| window.webContents.session, | ||
| config.cache, | ||
| config.additionalBlockLists, | ||
| config.disableDefaultLists, | ||
| ); | ||
| } | ||
| }, | ||
| stop({ window }) { | ||
| if (isBlockerEnabled(window.webContents.session)) { | ||
| unloadAdBlockerEngine(window.webContents.session); | ||
| } | ||
| }, | ||
| async onConfigChange(newConfig) { | ||
| if (this.mainWindow) { | ||
| if ( | ||
| newConfig.blocker === blockers.WithBlocklists && | ||
| !isBlockerEnabled(this.mainWindow.webContents.session) | ||
| ) { | ||
| await loadAdBlockerEngine( | ||
| this.mainWindow.webContents.session, | ||
| newConfig.cache, | ||
| newConfig.additionalBlockLists, | ||
| newConfig.disableDefaultLists, | ||
| ); | ||
| } | ||
| } | ||
| }, | ||
| }, | ||
| preload: { | ||
| script: 'window.JSON.parse = window._proxyJsonParse; window._proxyJsonParse = undefined; window.Response.prototype.json = window._proxyResponseJson; window._proxyResponseJson = undefined; 0', | ||
| async start({ getConfig }) { | ||
| const config = await getConfig(); | ||
|
|
||
| if (config.blocker === blockers.WithBlocklists) { | ||
| // Preload adblocker to inject scripts/styles | ||
| await injectCliqzPreload(); | ||
| } else if (config.blocker === blockers.InPlayer && !isInjected()) { | ||
| inject(contextBridge); | ||
| await webFrame.executeJavaScript(this.script); | ||
| } | ||
| }, | ||
| async onConfigChange(newConfig) { | ||
| if (newConfig.blocker === blockers.WithBlocklists) { | ||
| await injectCliqzPreload(); | ||
| } else if (newConfig.blocker === blockers.InPlayer && !isInjected()) { | ||
| inject(contextBridge); | ||
| await webFrame.executeJavaScript(this.script); | ||
| } | ||
| }, | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export default async () => { | ||
| await import('@ghostery/adblocker-electron-preload'); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import type { ContextBridge } from 'electron'; | ||
|
|
||
| export const inject: (contextBridge: ContextBridge) => void; | ||
|
|
||
| export const isInjected: () => boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete
··