This is an archived project. Repository and other project resources are read-only.
Project 'eyeo/adblockplus/adblockpluscore' was moved to 'eyeo/adblockplus/abc/adblockpluscore'. Please update any links and bookmarks that may still have the old path.
In order to move forward with CV-19, we need to provide a way to enable a debugging flag to any kind of snippet we export.
Any snippet filter could be prefixed with a call to the snippet debug which enables debugging per each snippet/function we use.
The debug flag is setup in a way that each function could have more details in console, keeping the filter identical except for the optional debug prefix snippet.
example.com#$#log OKVSexample.com#$#debug; log OK
What to change
Add the debug snippet in the snippet library
Add debug support to the log snippet, prefixing the log output with DEBUG
any snippet can be now prefixed with the command debug; which enables debugging per each snippet/function we use.
This has been previously discussed, and it was planned for the sprint as "we need to find a way to enable debugging before actually implementing it per each snippet".
The reason it is as it is now, is that implementing debugging per each snippet in a single MR would take forever to land, while we would like to have incremental step-by-step debugging enhancement.
However, you are right that as it is it doesn't add much value to our core, so here an example:
functionhideIfMatches(match,selector,searchSelector){let{debug}=hideIfMatches;if (searchSelector==null)searchSelector=selector;if (debug)log(`hideIfMatches searching for ${searchSelector}`);letcallback=()=>{for (letelementofdocument.querySelectorAll(searchSelector)){letclosest=element.closest(selector);if (debug)log(`hideIfMatches closer ${selector}${closest&&match(element,closest)?'succeeded':'failed'} on ${element.nodeName}`);if (closest&&match(element,closest))hideElement(closest);}};newMutationObserver(callback).observe(document,{childList:true,characterData:true,subtree:true});callback();}functionhideIfContains(search,selector="*",searchSelector=null){letre=toRegExp(search);hideIfMatches(element=>re.test(element.textContent),selector,searchSelector);}
The debug flag is setup in a way that each function could have more details in console, keeping the filter identical except for the optional debug; prefix
example.com#$#hide-if-contains ads divVSexample.com#$#debug; hide-if-contains ads div
The ultimate goal is to provide as many useful feedbacks as possible for both injected snippets, and those simply used by the extension.
Some extra context on the current implementation: since each snippet could be used as stand-alone, as dependency, as regular snippet or as injected one, leaking a global debug flag wouldn't work as efficiently, while diverging between functions used as normal snippets VS injected won't make our own code consistent/portable between the two different worlds.
Accordingly, the current implementation grants that any exported callback will have its own .debug flag, set as false by default, that could be enabled through debug; prefix.
Since one function could have one or more dependencies, such flag should be set per each exported/injected function so that we can reuse the same .debug logic everywhere.
great, 'cause this MR could address that too, once enabled, as right now we're just exposing a flag, and how we use that with each snippet is still TBD