-
Notifications
You must be signed in to change notification settings - Fork 93
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
Implement ElectronBlocker abstraction #180
Conversation
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.
Thank you so much for contributing! As far as I can see the changes look great but ideally we would find a way to get type definitions for Electron without having to bundle the full package. Do you know if that is possible? Otherwise we could define these in the source code directly and make sure they are compatible with electron upstream via the example/electron
?
Electron has its own type definitions and |
I'm wondering if this could cause issues for people using the adblocker without having |
I implemented some cosmetic filtering, but it doesn't inject in all frames. I think you will need to check it. |
I have no idea how to separate |
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.
Few thoughts, wondering if in the future it would not make sense to have sub-packages for different environments (maybe managed with lerna
, i see it's a pretty common practice): @cliqz/adblocker
, @cliqz/adblocker-webextension
, @cliqz/adblocker-puppeteer
, @cliqz/adblocker-electron
; which would give a bit more freedom with dependencies. At the moment it was kind of fine since we could get only the types for different platforms but Electron seem to require a tighter integration.
@sentialx the mono-repo PR was merged so we should be able to move forward with the |
@remusao Sorry for the delay. Is there a way to separate |
No worries at all! Sure you can, if your rollup exports an array, you can define several configs (with different inputs and outputs). One such example would be: https://github.com/cliqz-oss/adblocker/blob/master/packages/adblocker/rollup.config.ts (another package in this repository); this way you could create a bundle for I noticed that you added by mistake the |
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.
You should also be able to remove package-lock.json
completely. Since the switch to mono-repo structure yarn
is needed to get access to the workspace
feature it provides. So the only lock file needed is yarn.lock
at the root of the repository.
The preload script is being injected before the page load, so in main process it's correct. However I'm not sure about the |
Makes sense. Is there a way to wait for DOM to be ready for injection maybe? Also, do you know if |
In
In |
@sentialx I've been investigating a bit further and gained some extra insight. It seems that when a new frame/content context is created and a page loads in it, sending a message to early might result in this message being dropped completely. Basically if:
So we might need to way "a bit". Now waiting for So now I'm not sure if we should just introduce an arbitrary delay before answering from main process, or if we could perform a preliminary handshake (at the cost of increased latency); like:
What do you think? I will play a bit more with this tomorrow. |
How is this possible, the renderer process loses the message sent from main process by request? I think it's something wrong with getting the styles to inject. |
What I did is this:
What I observed after starting the example multiple times:
Which is why I concluded that it might be due to a timing issue. Not sure if setting-up the |
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.
Great work @sentialx! It's getting really close, very exciting. I had a few comments while reviewing the changes again. Let me know what you think.
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.
Awesome, thanks a lot again! Looks very good. I'm going to give it a run on a list of websites where I know there are tricky cases for the adblocker to make sure everything works as expected (CSP headers, injections, etc.). Will merge after that.
private onGetCosmeticFilters = ( | ||
event: Electron.IpcMessageEvent, | ||
url: string, | ||
msg: IBackgroundCallback & { action?: 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.
We can remove & { action?: string }
} | ||
|
||
private injectStyles(sender: Electron.WebContents, styles: string): void { | ||
if (sender) { |
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.
In which case can sender
be falsy?
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.
Well, that's a safe check whether it's not null or undefined.
Looks great. I tried it a bit locally and things seem to work fine :D (just had to fix something related to CSP injection). |
⚡ 🚀 Nice work! It was a great experience and I learned a lot thanks to you. Thanks again for your hard work. I'm going to prepare a release soon so that we can start using this new abstraction in the wild. |
Thanks. Will it be a good idea to add a |
Yes, actually I was thinking that we could have a common mechanism to
Depending on the project and use-case, you might want these information or not. Maybe a simple counter of "requests altered" is enough. But before implementing such mechanism, I'd like to answer these questions so that we build something solid which can accommodate multiple use-cases. In terms of implementation details, it could be using some Let's continue the discussion in a separate issue. I'd love to get your thoughts about this. |
Enable full adblocking in Electron with only few lines of code: