packages: adblocker-electron: conditionally enable webRequest handlers#4438
packages: adblocker-electron: conditionally enable webRequest handlers#4438seg6 wants to merge 2 commits intoghostery:masterfrom
webRequest handlers#4438Conversation
Signed-off-by: nullptropy <nullptropy@tutanota.com>
99285d1 to
fcd5513
Compare
|
Hi @nullptropy , Thanks for your PR. I don't think the third argument for registering web request handlers optionally can be inferred clearly what actually it implies. Also, web request handlers are necessary for the library to provide an adblocking feature. From my perspective, I'd rather prefer allowing web request handlers to be completely independent. For an instance, the following structure would give you a full access to the handler and optional registration of handlers. // refs https://www.electronjs.org/docs/latest/api/web-request
mainWindow.webContents.session.webRequest.onHeadersReceived(filter, (details, callback) => {
// Do some tasks prior to ad-blocking
return blocker.handleHeadersReceived(details, callback);
})Note that this is just another way to archive your needs. 👍 |
|
Hi @seia-soto! Thank you for the review. I think that would be a better API to have, but my thinking was that:
How do you suggest we move forward with this? |
|
Hi @nullptropy , If you really want to be flexible on those, I'd suggest you to completely remove adblocker-electron and use adblocker library directly. In one of our primary project: ghostery/ghostery-extension, we're directly using the adblocker library (not adblocker-webextension) to bring things as much as possible on manifest version 3 environment. Anytime, we (us and you) can backport adblocker co-packages instead. Apart to my opinion, I'll ping my team to get a review on the redirection. Always thanks for your interest and investment to adblocker library. Best |
|
@nullptropy whouldn't something like this work instead? const onBeforeRequest = blocker.onBeforeRequest.bind(blocker);
blocker.onBeforeRequest = (...args) => {
// run custom logic
return onBeforeRequest(...args);
};The point of the |
|
Thank you for the clarifications regarding the intent behind the I'd still argue that the default behavior of overwriting some Apart from this issue, Either way, the presented workarounds also work for what I'm trying to do. I'll be closing this PR, but please let me know if you have an alternative solution for the API. I'd be happy to tackle the implementation. |
|
Can definitely see your point. A move into this direction may indeed be beneficial for all consumers. However, introduction of such change is breaking the current API, so if we want it, we should probably offer the same solution for other supported platforms like puppeteer and playwright. This will probably require a major version bump. If you don't mind, I would prefer to re-open the PR to remind us about this proposal. |
…-webrequest-callbacks
We make heavy use of the
webRequestAPIs in our application, but the@ghostery/adblocker-electronpackage completely takes over theonHeadersReceivedandonBeforeRequesthandlers without providing an escape hatch, which makes it difficult for us to use the library.This patch provides a way for users to manually drive the adblocking process from outside the
@ghostery/adblocker-electrondependency.