@ghostery/adblocker-electron
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("electron"),require("tldts-experimental"),require("@ghostery/adblocker"),require("node:module")):"function"==typeof define&&define.amd?define(["exports","electron","tldts-experimental","@ghostery/adblocker","node:module"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).adblocker={},e.electron,e.tldtsExperimental,e.adblocker,e.node_module)}(this,(function(e,t,s,r,o){"use strict";var i="undefined"!=typeof document?document.currentScript:null;function n(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var l=n(t);const c=o.createRequire("undefined"==typeof document&&"undefined"==typeof location?require("url").pathToFileURL(__filename).href:"undefined"==typeof document?location.href:i&&"SCRIPT"===i.tagName.toUpperCase()&&i.src||new URL("adblocker.umd.min.js",document.baseURI).href).resolve("@ghostery/adblocker-electron-preload"),{ipcMain:a}=l;function d(e){const{id:t,url:s,resourceType:o,referrer:i,webContentsId:n}=e;return r.Request.fromRawDetails(n?{_originalRequestDetails:e,requestId:`${t}`,sourceUrl:i,tabId:n,type:o||"other",url:s}:{_originalRequestDetails:e,requestId:`${t}`,sourceUrl:i,type:o||"other",url:s})}process.env.ELECTRON_DISABLE_SECURITY_WARNINGS="true";class u{constructor(e,t){this.session=e,this.blocker=t,this.onBeforeRequest=(e,s)=>t.onBeforeRequest(e,s),this.onGetCosmeticFiltersFirst=(e,s)=>t.onGetCosmeticFiltersFirst(e,s),this.onGetCosmeticFiltersUpdated=(e,s,r)=>t.onGetCosmeticFiltersUpdated(e,s,r),this.onHeadersReceived=(e,s)=>t.onHeadersReceived(e,s),this.onIsMutationObserverEnabled=e=>t.onIsMutationObserverEnabled(e)}enable(){!0===this.blocker.config.loadCosmeticFilters&&(this.session.setPreloads(this.session.getPreloads().concat([c])),a.on("get-cosmetic-filters-first",this.onGetCosmeticFiltersFirst),a.on("get-cosmetic-filters",this.onGetCosmeticFiltersUpdated),a.on("is-mutation-observer-enabled",this.onIsMutationObserverEnabled)),!0===this.blocker.config.loadNetworkFilters&&(this.session.webRequest.onHeadersReceived({urls:["<all_urls>"]},this.onHeadersReceived),this.session.webRequest.onBeforeRequest({urls:["<all_urls>"]},this.onBeforeRequest))}disable(){!0===this.blocker.config.loadNetworkFilters&&(this.session.webRequest.onHeadersReceived(null),this.session.webRequest.onBeforeRequest(null)),!0===this.blocker.config.loadCosmeticFilters&&(this.session.setPreloads(this.session.getPreloads().filter((e=>e!==c))),a.removeListener("get-cosmetic-filters",this.onGetCosmeticFiltersUpdated))}}class f extends r.FiltersEngine{constructor(){super(...arguments),this.contexts=new WeakMap,this.onIsMutationObserverEnabled=e=>{e.returnValue=this.config.enableMutationObserver},this.onGetCosmeticFiltersFirst=(e,t)=>{const r=s.parse(t),o=r.hostname||"",i=r.domain||"",{active:n,styles:l,scripts:c,extended:a}=this.getCosmeticsFilters({domain:i,hostname:o,url:t,getBaseRules:!0,getInjectionRules:!0,getExtendedRules:!0,getRulesFromHostname:!0,getRulesFromDOM:!1,callerContext:{frameId:e.frameId,processId:e.processId}});!1!==n?(this.injectStyles(e.sender,l),e.sender.send("get-cosmetic-filters-response",{active:n,extended:a,styles:""}),e.returnValue=c):e.returnValue=null},this.onGetCosmeticFiltersUpdated=(e,t,r)=>{const o=s.parse(t),i=o.hostname||"",n=o.domain||"",{active:l,styles:c,extended:a}=this.getCosmeticsFilters({domain:n,hostname:i,url:t,classes:r.classes,hrefs:r.hrefs,ids:r.ids,getBaseRules:!1,getInjectionRules:!1,getExtendedRules:!1,getRulesFromHostname:!1,getRulesFromDOM:!0,callerContext:{frameId:e.frameId,processId:e.processId,lifecycle:r.lifecycle}});!1!==l&&(this.injectStyles(e.sender,c),e.sender.send("get-cosmetic-filters-response",{active:l,extended:a,styles:""}))},this.onHeadersReceived=(e,t)=>{const s="content-security-policy",r=[],o=e.responseHeaders||{};if("mainFrame"===e.resourceType||"subFrame"===e.resourceType){const i=this.getCSPDirectives(d(e));if(void 0!==i){r.push(...i.split(";").map((e=>e.trim())));for(const[e,t]of Object.entries(o))e.toLowerCase()===s&&(r.push(...t),delete o[e]);return o[s]=[r.join(";")],void t({responseHeaders:o})}}t({})},this.onBeforeRequest=(e,t)=>{const s=d(e);if(!0===this.config.guessRequestTypeFromUrl&&"other"===s.type&&s.guessTypeOfRequest(),s.isMainFrame())return void t({});const{redirect:r,match:o}=this.match(s);t(r?{redirectURL:r.dataUrl}:o?{cancel:!0}:{})}}enableBlockingInSession(e){let t=this.contexts.get(e);return void 0!==t||(t=new u(e,this),this.contexts.set(e,t),t.enable()),t}disableBlockingInSession(e){const t=this.contexts.get(e);if(void 0===t)throw new Error("Trying to disable blocking which was not enabled");this.contexts.delete(e),t.disable()}isBlockingEnabled(e){return this.contexts.has(e)}injectStyles(e,t){t.length>0&&e.insertCSS(t,{cssOrigin:"user"})}}e.BlockingContext=u,e.ElectronBlocker=f,e.fromElectronDetails=d,Object.keys(r).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return r[t]}})}))})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("electron"),require("tldts-experimental"),require("@ghostery/adblocker"),require("node:module")):"function"==typeof define&&define.amd?define(["exports","electron","tldts-experimental","@ghostery/adblocker","node:module"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).adblocker={},e.electron,e.tldtsExperimental,e.adblocker,e.node_module)}(this,(function(e,t,s,o,r){"use strict";var n="undefined"!=typeof document?document.currentScript:null;function i(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var o=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,o.get?o:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var l=i(t);const c=r.createRequire("undefined"==typeof document&&"undefined"==typeof location?require("url").pathToFileURL(__filename).href:"undefined"==typeof document?location.href:n&&"SCRIPT"===n.tagName.toUpperCase()&&n.src||new URL("adblocker.umd.min.js",document.baseURI).href).resolve("@ghostery/adblocker-electron-preload"),{ipcMain:a}=l;function d(e){const{id:t,url:s,resourceType:r,referrer:n,webContentsId:i}=e;return o.Request.fromRawDetails(i?{_originalRequestDetails:e,requestId:`${t}`,sourceUrl:n,tabId:i,type:r||"other",url:s}:{_originalRequestDetails:e,requestId:`${t}`,sourceUrl:n,type:r||"other",url:s})}process.env.ELECTRON_DISABLE_SECURITY_WARNINGS="true";class u{constructor(e,t){this.session=e,this.blocker=t,this.onBeforeRequest=(e,s)=>t.onBeforeRequest(e,s),this.onInjectCosmeticFilters=(e,s,o)=>t.onInjectCosmeticFilters(e,s,o),this.onHeadersReceived=(e,s)=>t.onHeadersReceived(e,s),this.onIsMutationObserverEnabled=e=>t.onIsMutationObserverEnabled(e)}enable(){!0===this.blocker.config.loadCosmeticFilters&&(this.session.setPreloads(this.session.getPreloads().concat([c])),a.handle("@ghostery/adblocker/inject-cosmetic-filters",this.onInjectCosmeticFilters),a.handle("@ghostery/adblocker/is-mutation-observer-enabled",this.onIsMutationObserverEnabled)),!0===this.blocker.config.loadNetworkFilters&&(this.session.webRequest.onHeadersReceived({urls:["<all_urls>"]},this.onHeadersReceived),this.session.webRequest.onBeforeRequest({urls:["<all_urls>"]},this.onBeforeRequest))}disable(){!0===this.blocker.config.loadNetworkFilters&&(this.session.webRequest.onHeadersReceived(null),this.session.webRequest.onBeforeRequest(null)),!0===this.blocker.config.loadCosmeticFilters&&(this.session.setPreloads(this.session.getPreloads().filter((e=>e!==c))),a.removeHandler("@ghostery/adblocker/inject-cosmetic-filters"),a.removeHandler("@ghostery/adblocker/is-mutation-observer-enabled"))}}class h extends o.FiltersEngine{constructor(){super(...arguments),this.contexts=new WeakMap,this.onIsMutationObserverEnabled=async e=>this.config.enableMutationObserver,this.onInjectCosmeticFilters=async(e,t,o)=>{const r=s.parse(t),n=r.hostname||"",i=r.domain||"",l=void 0===o,{active:c,styles:a,scripts:d}=this.getCosmeticsFilters({domain:i,hostname:n,url:t,classes:null==o?void 0:o.classes,hrefs:null==o?void 0:o.hrefs,ids:null==o?void 0:o.ids,getBaseRules:l,getInjectionRules:l,getExtendedRules:!1,getRulesFromHostname:l,getRulesFromDOM:!l,callerContext:{frameId:e.frameId,processId:e.processId,lifecycle:null==o?void 0:o.lifecycle}});if(!1!==c){a.length>0&&e.sender.insertCSS(a,{cssOrigin:"user"});for(const t of d)try{e.sender.executeJavaScript(t,!0)}catch(e){console.error("@ghostery/adblocker scriptlet crashed",e)}}},this.onHeadersReceived=(e,t)=>{const s="content-security-policy",o=[],r=e.responseHeaders||{};if("mainFrame"===e.resourceType||"subFrame"===e.resourceType){const n=this.getCSPDirectives(d(e));if(void 0!==n){o.push(...n.split(";").map((e=>e.trim())));for(const[e,t]of Object.entries(r))e.toLowerCase()===s&&(o.push(...t),delete r[e]);return r[s]=[o.join(";")],void t({responseHeaders:r})}}t({})},this.onBeforeRequest=(e,t)=>{const s=d(e);if(!0===this.config.guessRequestTypeFromUrl&&"other"===s.type&&s.guessTypeOfRequest(),s.isMainFrame())return void t({});const{redirect:o,match:r}=this.match(s);t(o?{redirectURL:o.dataUrl}:r?{cancel:!0}:{})}}enableBlockingInSession(e){let t=this.contexts.get(e);return void 0!==t||(t=new u(e,this),this.contexts.set(e,t),t.enable()),t}disableBlockingInSession(e){const t=this.contexts.get(e);if(void 0===t)throw new Error("Trying to disable blocking which was not enabled");this.contexts.delete(e),t.disable()}isBlockingEnabled(e){return this.contexts.has(e)}}e.BlockingContext=u,e.ElectronBlocker=h,e.fromElectronDetails=d,Object.keys(o).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return o[t]}})}))})); | ||
//# sourceMappingURL=adblocker.umd.min.js.map |
@@ -21,4 +21,3 @@ /*! | ||
private readonly onBeforeRequest; | ||
private readonly onGetCosmeticFiltersUpdated; | ||
private readonly onGetCosmeticFiltersFirst; | ||
private readonly onInjectCosmeticFilters; | ||
private readonly onHeadersReceived; | ||
@@ -39,10 +38,8 @@ private readonly onIsMutationObserverEnabled; | ||
isBlockingEnabled(session: Electron.Session): boolean; | ||
onIsMutationObserverEnabled: (event: Electron.IpcMainEvent) => void; | ||
onGetCosmeticFiltersFirst: (event: Electron.IpcMainEvent, url: string) => void; | ||
onGetCosmeticFiltersUpdated: (event: Electron.IpcMainEvent, url: string, msg: IBackgroundCallback) => void; | ||
onIsMutationObserverEnabled: (_: Electron.IpcMainInvokeEvent) => Promise<boolean>; | ||
onInjectCosmeticFilters: (event: Electron.IpcMainInvokeEvent, url: string, msg?: IBackgroundCallback) => Promise<void>; | ||
onHeadersReceived: (details: Electron.OnHeadersReceivedListenerDetails, callback: (a: Electron.HeadersReceivedResponse) => void) => void; | ||
onBeforeRequest: (details: Electron.OnBeforeRequestListenerDetails, callback: (a: Electron.CallbackResponse) => void) => void; | ||
private injectStyles; | ||
} | ||
export * from '@ghostery/adblocker'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -75,4 +75,3 @@ "use strict"; | ||
this.onBeforeRequest = (details, callback) => blocker.onBeforeRequest(details, callback); | ||
this.onGetCosmeticFiltersFirst = (event, url) => blocker.onGetCosmeticFiltersFirst(event, url); | ||
this.onGetCosmeticFiltersUpdated = (event, url, msg) => blocker.onGetCosmeticFiltersUpdated(event, url, msg); | ||
this.onInjectCosmeticFilters = (event, url, msg) => blocker.onInjectCosmeticFilters(event, url, msg); | ||
this.onHeadersReceived = (details, callback) => blocker.onHeadersReceived(details, callback); | ||
@@ -84,5 +83,4 @@ this.onIsMutationObserverEnabled = (event) => blocker.onIsMutationObserverEnabled(event); | ||
this.session.setPreloads(this.session.getPreloads().concat([preload_path_js_1.PRELOAD_PATH])); | ||
ipcMain.on('get-cosmetic-filters-first', this.onGetCosmeticFiltersFirst); | ||
ipcMain.on('get-cosmetic-filters', this.onGetCosmeticFiltersUpdated); | ||
ipcMain.on('is-mutation-observer-enabled', this.onIsMutationObserverEnabled); | ||
ipcMain.handle('@ghostery/adblocker/inject-cosmetic-filters', this.onInjectCosmeticFilters); | ||
ipcMain.handle('@ghostery/adblocker/is-mutation-observer-enabled', this.onIsMutationObserverEnabled); | ||
} | ||
@@ -109,3 +107,4 @@ if (this.blocker.config.loadNetworkFilters === true) { | ||
this.session.setPreloads(this.session.getPreloads().filter((p) => p !== preload_path_js_1.PRELOAD_PATH)); | ||
ipcMain.removeListener('get-cosmetic-filters', this.onGetCosmeticFiltersUpdated); | ||
ipcMain.removeHandler('@ghostery/adblocker/inject-cosmetic-filters'); | ||
ipcMain.removeHandler('@ghostery/adblocker/is-mutation-observer-enabled'); | ||
} | ||
@@ -126,62 +125,30 @@ } | ||
// ----------------------------------------------------------------------- // | ||
this.onIsMutationObserverEnabled = (event) => { | ||
event.returnValue = this.config.enableMutationObserver; | ||
this.onIsMutationObserverEnabled = async (_) => { | ||
return this.config.enableMutationObserver; | ||
}; | ||
this.onGetCosmeticFiltersFirst = (event, url) => { | ||
// Extract hostname from sender's URL | ||
this.onInjectCosmeticFilters = async (event, url, msg) => { | ||
const parsed = (0, tldts_experimental_1.parse)(url); | ||
const hostname = parsed.hostname || ''; | ||
const domain = parsed.domain || ''; | ||
const { active, styles, scripts, extended } = this.getCosmeticsFilters({ | ||
// `msg` is undefined for the initial call and present for subsequent updates | ||
const isFirstRun = msg === undefined; | ||
const { active, styles, scripts } = this.getCosmeticsFilters({ | ||
domain, | ||
hostname, | ||
url, | ||
// This needs to be done only once per frame | ||
getBaseRules: true, | ||
getInjectionRules: true, | ||
getExtendedRules: true, | ||
getRulesFromHostname: true, | ||
getRulesFromDOM: false, // Only done on updates (see `onGetCosmeticFiltersUpdated`) | ||
callerContext: { | ||
frameId: event.frameId, | ||
processId: event.processId, | ||
}, | ||
}); | ||
if (active === false) { | ||
event.returnValue = null; | ||
return; | ||
} | ||
// Inject custom stylesheets | ||
this.injectStyles(event.sender, styles); | ||
event.sender.send('get-cosmetic-filters-response', { | ||
active, | ||
extended, | ||
styles: '', | ||
}); | ||
// to execute Inject scripts synchronously, simply return scripts to renderer. | ||
event.returnValue = scripts; | ||
}; | ||
this.onGetCosmeticFiltersUpdated = (event, url, msg) => { | ||
// Extract hostname from sender's URL | ||
const parsed = (0, tldts_experimental_1.parse)(url); | ||
const hostname = parsed.hostname || ''; | ||
const domain = parsed.domain || ''; | ||
const { active, styles, extended } = this.getCosmeticsFilters({ | ||
domain, | ||
hostname, | ||
url, | ||
classes: msg.classes, | ||
hrefs: msg.hrefs, | ||
ids: msg.ids, | ||
// Only done on first load in the frame, disable for updates | ||
getBaseRules: false, | ||
getInjectionRules: false, | ||
// DOM information, only available for updates | ||
classes: msg === null || msg === void 0 ? void 0 : msg.classes, | ||
hrefs: msg === null || msg === void 0 ? void 0 : msg.hrefs, | ||
ids: msg === null || msg === void 0 ? void 0 : msg.ids, | ||
// Rules to fetch: true for initial call, false for updates | ||
getBaseRules: isFirstRun, | ||
getInjectionRules: isFirstRun, | ||
getExtendedRules: false, | ||
getRulesFromHostname: false, | ||
// This will be done every time we get information about DOM mutation | ||
getRulesFromDOM: true, | ||
getRulesFromHostname: isFirstRun, | ||
// Only true for update calls when we have DOM information | ||
getRulesFromDOM: !isFirstRun, | ||
callerContext: { | ||
frameId: event.frameId, | ||
processId: event.processId, | ||
lifecycle: msg.lifecycle, | ||
lifecycle: msg === null || msg === void 0 ? void 0 : msg.lifecycle, | ||
}, | ||
@@ -192,10 +159,13 @@ }); | ||
} | ||
// Inject custom stylesheets | ||
this.injectStyles(event.sender, styles); | ||
// Inject scripts from content script | ||
event.sender.send('get-cosmetic-filters-response', { | ||
active, | ||
extended, | ||
styles: '', | ||
}); | ||
if (styles.length > 0) { | ||
event.sender.insertCSS(styles, { cssOrigin: 'user' }); | ||
} | ||
for (const script of scripts) { | ||
try { | ||
event.sender.executeJavaScript(script, true); | ||
} | ||
catch (e) { | ||
console.error('@ghostery/adblocker scriptlet crashed', e); | ||
} | ||
} | ||
}; | ||
@@ -270,9 +240,2 @@ this.onHeadersReceived = (details, callback) => { | ||
} | ||
injectStyles(sender, styles) { | ||
if (styles.length > 0) { | ||
sender.insertCSS(styles, { | ||
cssOrigin: 'user', | ||
}); | ||
} | ||
} | ||
} | ||
@@ -279,0 +242,0 @@ exports.ElectronBlocker = ElectronBlocker; |
@@ -21,4 +21,3 @@ /*! | ||
private readonly onBeforeRequest; | ||
private readonly onGetCosmeticFiltersUpdated; | ||
private readonly onGetCosmeticFiltersFirst; | ||
private readonly onInjectCosmeticFilters; | ||
private readonly onHeadersReceived; | ||
@@ -39,10 +38,8 @@ private readonly onIsMutationObserverEnabled; | ||
isBlockingEnabled(session: Electron.Session): boolean; | ||
onIsMutationObserverEnabled: (event: Electron.IpcMainEvent) => void; | ||
onGetCosmeticFiltersFirst: (event: Electron.IpcMainEvent, url: string) => void; | ||
onGetCosmeticFiltersUpdated: (event: Electron.IpcMainEvent, url: string, msg: IBackgroundCallback) => void; | ||
onIsMutationObserverEnabled: (_: Electron.IpcMainInvokeEvent) => Promise<boolean>; | ||
onInjectCosmeticFilters: (event: Electron.IpcMainInvokeEvent, url: string, msg?: IBackgroundCallback) => Promise<void>; | ||
onHeadersReceived: (details: Electron.OnHeadersReceivedListenerDetails, callback: (a: Electron.HeadersReceivedResponse) => void) => void; | ||
onBeforeRequest: (details: Electron.OnBeforeRequestListenerDetails, callback: (a: Electron.CallbackResponse) => void) => void; | ||
private injectStyles; | ||
} | ||
export * from '@ghostery/adblocker'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -45,4 +45,3 @@ /*! | ||
this.onBeforeRequest = (details, callback) => blocker.onBeforeRequest(details, callback); | ||
this.onGetCosmeticFiltersFirst = (event, url) => blocker.onGetCosmeticFiltersFirst(event, url); | ||
this.onGetCosmeticFiltersUpdated = (event, url, msg) => blocker.onGetCosmeticFiltersUpdated(event, url, msg); | ||
this.onInjectCosmeticFilters = (event, url, msg) => blocker.onInjectCosmeticFilters(event, url, msg); | ||
this.onHeadersReceived = (details, callback) => blocker.onHeadersReceived(details, callback); | ||
@@ -54,5 +53,4 @@ this.onIsMutationObserverEnabled = (event) => blocker.onIsMutationObserverEnabled(event); | ||
this.session.setPreloads(this.session.getPreloads().concat([PRELOAD_PATH])); | ||
ipcMain.on('get-cosmetic-filters-first', this.onGetCosmeticFiltersFirst); | ||
ipcMain.on('get-cosmetic-filters', this.onGetCosmeticFiltersUpdated); | ||
ipcMain.on('is-mutation-observer-enabled', this.onIsMutationObserverEnabled); | ||
ipcMain.handle('@ghostery/adblocker/inject-cosmetic-filters', this.onInjectCosmeticFilters); | ||
ipcMain.handle('@ghostery/adblocker/is-mutation-observer-enabled', this.onIsMutationObserverEnabled); | ||
} | ||
@@ -79,3 +77,4 @@ if (this.blocker.config.loadNetworkFilters === true) { | ||
this.session.setPreloads(this.session.getPreloads().filter((p) => p !== PRELOAD_PATH)); | ||
ipcMain.removeListener('get-cosmetic-filters', this.onGetCosmeticFiltersUpdated); | ||
ipcMain.removeHandler('@ghostery/adblocker/inject-cosmetic-filters'); | ||
ipcMain.removeHandler('@ghostery/adblocker/is-mutation-observer-enabled'); | ||
} | ||
@@ -95,62 +94,30 @@ } | ||
// ----------------------------------------------------------------------- // | ||
this.onIsMutationObserverEnabled = (event) => { | ||
event.returnValue = this.config.enableMutationObserver; | ||
this.onIsMutationObserverEnabled = async (_) => { | ||
return this.config.enableMutationObserver; | ||
}; | ||
this.onGetCosmeticFiltersFirst = (event, url) => { | ||
// Extract hostname from sender's URL | ||
this.onInjectCosmeticFilters = async (event, url, msg) => { | ||
const parsed = parse(url); | ||
const hostname = parsed.hostname || ''; | ||
const domain = parsed.domain || ''; | ||
const { active, styles, scripts, extended } = this.getCosmeticsFilters({ | ||
// `msg` is undefined for the initial call and present for subsequent updates | ||
const isFirstRun = msg === undefined; | ||
const { active, styles, scripts } = this.getCosmeticsFilters({ | ||
domain, | ||
hostname, | ||
url, | ||
// This needs to be done only once per frame | ||
getBaseRules: true, | ||
getInjectionRules: true, | ||
getExtendedRules: true, | ||
getRulesFromHostname: true, | ||
getRulesFromDOM: false, // Only done on updates (see `onGetCosmeticFiltersUpdated`) | ||
callerContext: { | ||
frameId: event.frameId, | ||
processId: event.processId, | ||
}, | ||
}); | ||
if (active === false) { | ||
event.returnValue = null; | ||
return; | ||
} | ||
// Inject custom stylesheets | ||
this.injectStyles(event.sender, styles); | ||
event.sender.send('get-cosmetic-filters-response', { | ||
active, | ||
extended, | ||
styles: '', | ||
}); | ||
// to execute Inject scripts synchronously, simply return scripts to renderer. | ||
event.returnValue = scripts; | ||
}; | ||
this.onGetCosmeticFiltersUpdated = (event, url, msg) => { | ||
// Extract hostname from sender's URL | ||
const parsed = parse(url); | ||
const hostname = parsed.hostname || ''; | ||
const domain = parsed.domain || ''; | ||
const { active, styles, extended } = this.getCosmeticsFilters({ | ||
domain, | ||
hostname, | ||
url, | ||
classes: msg.classes, | ||
hrefs: msg.hrefs, | ||
ids: msg.ids, | ||
// Only done on first load in the frame, disable for updates | ||
getBaseRules: false, | ||
getInjectionRules: false, | ||
// DOM information, only available for updates | ||
classes: msg === null || msg === void 0 ? void 0 : msg.classes, | ||
hrefs: msg === null || msg === void 0 ? void 0 : msg.hrefs, | ||
ids: msg === null || msg === void 0 ? void 0 : msg.ids, | ||
// Rules to fetch: true for initial call, false for updates | ||
getBaseRules: isFirstRun, | ||
getInjectionRules: isFirstRun, | ||
getExtendedRules: false, | ||
getRulesFromHostname: false, | ||
// This will be done every time we get information about DOM mutation | ||
getRulesFromDOM: true, | ||
getRulesFromHostname: isFirstRun, | ||
// Only true for update calls when we have DOM information | ||
getRulesFromDOM: !isFirstRun, | ||
callerContext: { | ||
frameId: event.frameId, | ||
processId: event.processId, | ||
lifecycle: msg.lifecycle, | ||
lifecycle: msg === null || msg === void 0 ? void 0 : msg.lifecycle, | ||
}, | ||
@@ -161,10 +128,13 @@ }); | ||
} | ||
// Inject custom stylesheets | ||
this.injectStyles(event.sender, styles); | ||
// Inject scripts from content script | ||
event.sender.send('get-cosmetic-filters-response', { | ||
active, | ||
extended, | ||
styles: '', | ||
}); | ||
if (styles.length > 0) { | ||
event.sender.insertCSS(styles, { cssOrigin: 'user' }); | ||
} | ||
for (const script of scripts) { | ||
try { | ||
event.sender.executeJavaScript(script, true); | ||
} | ||
catch (e) { | ||
console.error('@ghostery/adblocker scriptlet crashed', e); | ||
} | ||
} | ||
}; | ||
@@ -239,9 +209,2 @@ this.onHeadersReceived = (details, callback) => { | ||
} | ||
injectStyles(sender, styles) { | ||
if (styles.length > 0) { | ||
sender.insertCSS(styles, { | ||
cssOrigin: 'user', | ||
}); | ||
} | ||
} | ||
} | ||
@@ -248,0 +211,0 @@ // re-export @ghostery/adblocker symbols for convenience |
{ | ||
"name": "@ghostery/adblocker-electron", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Ghostery adblocker Electron wrapper", | ||
@@ -58,4 +58,4 @@ "author": { | ||
"dependencies": { | ||
"@ghostery/adblocker": "^2.0.0", | ||
"@ghostery/adblocker-electron-preload": "^2.0.0", | ||
"@ghostery/adblocker": "^2.0.1", | ||
"@ghostery/adblocker-electron-preload": "^2.0.1", | ||
"tldts-experimental": "^6.0.14" | ||
@@ -112,3 +112,3 @@ }, | ||
], | ||
"gitHead": "664c98e1bfec2ad1a035f65218f8be575bc6cbf9" | ||
"gitHead": "84366cc7fdf9bd2b0761b39443f01ad9defd2e63" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
86506
558