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
Improve engine events to expose internal workflow #3881
base: master
Are you sure you want to change the base?
Improve engine events to expose internal workflow #3881
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.
Few things to address:
- To have a better overview we should also emit information of the exceptions (unHide), similarly to how it is being done for the network matches.
- how about we have one new event, lets call it
match
that would fire for both network and cosmetic filters. It's params should look alike for both types. (don't remove old event, they important for backwards compatibility)
I see it like this:
const context = { tabId: 1, frameId: 2 };
engine.getCosmeticsFilters(oldParams, withMetadata, context);
engine.match(request, withMetadata, context);
engine.on('match', (context, result) => {
console.log(context, result.match, result.exception, result.metadata);
});
Notice withMetadata
for getCosmeticsFilters
this is another capability to remember about. The result for the cosmetic filters should include the metadata in the same way the network result does.
@remusao I'd like to get a feedback about the way passing "context" to matching functions. It might help a lot for extension developers often used to involve @chrmod This is actually an off-topic but if we involve Passing an external context can solve many complex situations but I'd like to go simple as possible. For example, we could decorate the passed |
console.log('extended-rule-matched', rule, context); | ||
}); | ||
|
||
blocker.on('style-rule-matched', (rule, context) => { |
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.
I wonder if we could make it clearer in the naming that this is a hostname-based march of a cosmetic rule. Also, that it does not mean it marched in the page, just that it was selected by the engine as a candidate to be injected (I think it’s important to make this clear to avoid confusion)
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.
Not sure if we need that many new events. How about we introduce one filter-matched
which would emit:
- a filter, cosmetic or network
- a function name used to acquire the filter, like
match
,getHtmlFilters
,getCosmeticsFilters
- function arguments, which can include additional info like the
context: any
. For network filters it is most important to get the request.
Additionally, would like to set a naming convention for the public interfaces for the filters. Sometimes we call those things rules
(for instance in context of Cosmetic bucket), but on the interface level I would strony suggest we always call both network and cosmetic "rule" with a name of filters
.
This will be a contrast to the DNR, where after conversion the filters become the rules.
In the last changes, the events were narrowed down to two: Also, the commit addresses the followings:
|
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.
should we add filter-matched
for network filters as well? that would be in engine.match
and engine.matchAll
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.
Looks like while we develop this feature it started to change direction. All good, but it also got a bit complex. Lets try to simplify a bit before moving forward.
To recap the goal: We want to introduce new events that would allow us to implement a logger that is able to list matched filters and exceptions in a context of a given tab.
@@ -1035,6 +1195,8 @@ export default class FilterEngine extends EventEmitter< | |||
|
|||
// Emit events if we found a match | |||
if (result.exception !== undefined) { | |||
this.emit('filter-matched', result.exception, context); | |||
|
|||
this.emit('request-whitelisted', request, result); | |||
} else if (result.redirect !== 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.
shouldn't we emit redirects as well?
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.
This is treated as a normal filter (result.filter
) before being registered as result.redirect
. The event should be triggered right after the filter match.
Co-authored-by: chrmod <chrmod@ghostery.com>
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.
LGTM, let me test it locally before merging.
fixes #3876