diff --git a/Inline-script-tag-filtering.md b/Inline-script-tag-filtering.md index 24424b9..50da73e 100644 --- a/Inline-script-tag-filtering.md +++ b/Inline-script-tag-filtering.md @@ -1,33 +1,49 @@ There are many ways to block script tags from executing in uBlock Origin: - Block external script resources. -- Block all inline script tags[1] at once. +- Block all inline script tags embedded in a page at once.[1] -uBlock Origin 1.2.0 introduces a new way to block **specific** inline script tag in a web page through a new script tag cosmetic filter: +Inline script tags are those scripts which are embedded in the main page: they can not be blocked from downloading unless the whole page itself is blocked, which is not very useful. Here is a example of HTML code with two inline script tags: + +```html + +
+ + + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ + +``` + +In this example, blocking inline script tags wholesale would not be a good solution because both script tags would be blocked and we would lose the `usefulCode` function as well. + +uBlock Origin 1.2.0 introduces a new way to block **specific** inline script tag in a web page through the script tag cosmetic filter: example.com##script:contains(...) Where the value inside the parenthesis in `contains(...)` can be a plain string or a literal javascript regular expression (`/.../`). A script tag cosmetic filter will prevent the execution of whatever javascript inside a **specific** script tag when there is a match, i.e. when the plain text or the regular expression is found inside the script tag. +So we can use script tag filtering for our above example to specifically disable one of the script tag (assuming the page's URL is `https://foo.example/bar.html`): + + foo.example##script:contains(nuisanceCode) + +This filter means: for any web pages from `foo.example`, disable all inline script tags which contains the string `nuisanceCode`. + *** -- [1] Inline script tags are those which are embedded in the main web page. An example using an excerpt from the front page of Hacker News: