adblocker: Extremely slow request decision
Hi, I noticed after update (0.10 I guess) the engine.match method became super-slow. Here’s the code I’m using in my Electron app, and it literally hangs up:
webRequest.onBeforeRequest(
{ urls: ['<all_urls>'] },
async (details: Electron.OnBeforeRequestDetails, callback: any) => {
if (engine && settings.isShieldToggled) {
console.time('engine.match');
const { match, redirect } = engine.match(
Request.fromRawDetails({
type: details.resourceType as any,
url: details.url,
}),
);
console.timeEnd('engine.match');
if (match || redirect) {
appWindow.webContents.send(`blocked-ad-${details.webContentsId}`);
if (redirect) {
callback({ redirectURL: redirect });
} else {
callback({ cancel: true });
}
return;
}
}
callback({ cancel: false });
},
);

About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (8 by maintainers)
To make optimal use of cosmetics (both in terms of performance and coverage), the handling needs to be slightly more involved. The way to do it optimally depends on the capabilities. If we have a way to inject “content scripts” in pages via Electron APIs, then you can implement the full capabilities like in WebExtensions. The ideal scenario with cosmetics is this one:
MutationObserverin the web extension context and maybe there is a way to do the same for Electron.In puppeteer we only do
1.and2.at the moment. But probably we can do3.for Electron.Thank you for taking your time for investigating this issue. It would never come to my mind that it’s a particular list fault.
Sure, I will take a look at this.