Develop a content (ad) blocker Web Extension for Safari in JavaScript. There are multiple ways of blocking content in a browser. Within this project, we only need to focus on one of them: using scriptlets.
A scriplet is a simple script intended to perform a particular task like aborting an inline script, setting a constant, prunning JSON, and so on. Many existing popular content blockers like AdGuard and uBlock Origin are already using scriptlets to block ads that are difficult to block using standard declarative API.
For example, here’s how an extension can block YouTube ads using three rules with scriptlets:
youtube.com##+js(json-prune, [].[login to view URL] [].[login to view URL] [login to view URL] [login to view URL] adPlacements playerAds)
youtube.com##+js(set, [login to view URL], undefined)
youtube.com##+js(set, [login to view URL], undefined)
Another example of a rule that blocks a popup asking users to turn off their ad blocker:
brutal.io##+js(set, hasAdblock, false)
More on scriptlet injection: [login to view URL]
There are existing Scriptlet libraries that are huge and contain lots of functions:
[login to view URL]
[login to view URL]
Our web extension should support these scriptlets (MVP):
"set-constant" - [login to view URL]
"json-prune" - [login to view URL]
"abort-current-inline-script" - [login to view URL]
"abort-on-property-read" - [login to view URL]
"abort-on-property-write" - [login to view URL]
uBlock Origin and AdGuard are open-source on GitHub:
[login to view URL]
[login to view URL]
It’s recommended to check their code to see how they integrated their support of blocking content using rules with scriptlets. Perhaps, there were some weird edge-cases that uBlock Origin and AdGuard founded and worked around. No need to re-invent the wheel here.
Here’s an example filters file that contain rules with scriptlets: [login to view URL]
Our web extension will have a similar txt file with rules having scriptlets.
We only target one browser: Safari v14+.
The extension will have no interface. It only embeds into all webpages a script file that adds support for scriptlets and blocks content (ads) according to a txt file with rules.
The developer should have strong JavaScript skills and experience developing web extensions for browsers. Experience creating uBlock Origin filters is a plus.
Thank you.