Table of Contents
Also see: remove-node-text
Back to Static filter syntax.
Caveats
Script tag filters do not work in all browsers, due to browser API limitations:
- Not supported in Chromium-based browser.
- Starring the related Chromium issue may help motivate Chromium devs to implement support.
- Falling back on wholesale blocking of all inline script tags may work.[1]
- Not supported in Firefox's WebExtensions version of uBO when...
- Firefox 56 and less is used;
- uBO version 1.14.23b2 and less used.
[1] Through the use of the inline-script
static filter option (||example.com^$inline-script
), or through the use of a dynamic filtering block rule for inline scripts.
Overview
There are many ways to block script tags from executing in uBlock Origin:
- Block external script resources: these are taken care by network filtering.
- Block all inline script tags embedded in a page at once.[1]
Inline script tags are those blocks of JavaScript code 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 a web page's HTML code with two inline script tags:
<html>
<head>
<meta name="referrer" content="origin">
<link rel="stylesheet" href="main.css" />
<script type="text/javascript">
function usefulCode() {
...
}
...
</script>
<title>lorem ipsum</title>
</head>
<body>
<h1>lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<script type="text/javascript">
function nuisanceCode() {
...
}
...
</script>
</body>
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.15.0 introduces HTML filtering, which can be used to remove specific inline script tags from a web page before the browser parses the HTML response from the server:
example.com##^script:has-text(...)
Where the value inside the parenthesis in has-text(...)
can be a plain string or a literal JavaScript regular expression (/.../
).
So we can use HTML filtering for our above example to specifically remove one of the script tags (assuming the page's URL is https://foo.example/bar.html
):
foo.example##^script:has-text(nuisanceCode)
This filter means: for any web pages from the foo.example
web site, remove all inline script tags which contains the string nuisanceCode
.
In the cat and mouse game between web sites and blockers, the new script tag filter is a welcomed new tool on the user side, to foil attempt by site to work around blockers.
The big advantage of this new filter is that it can fix at the source many of the anti-blocker workarounds used by some web sites.
For example, the web site at http://focus.de/
will resort to deface itself with ridiculous ads when the site detects that the user is using a blocker, and using EasyList + EasyList Germany does not work, as the images pulled by the page are randomly named, defeating pattern-based network filters and cosmetic filters as well.
Wholesale blocking of inline script tags does prevent the self-defacing, but possibly at the cost of disabling other possible useful functionalities on the page. However, a script tag filter to block the specific inline script tag which contains the self-defacement JavaScript code allows a more targeted approach: prevent the undesirable inline JavaScript code from executing while keeping the desirable inline JavaScript code intact. At time of writing, this script tag filter worked for the site:
www.focus.de##^script:has-text(uabInject)
Concrete examples of usefulness
A concrete example of a site which resorts to self-defacement when it detects that a blocker is in use -- the front page of rp-online.de:
Without inline script tag filtering:
With an appropriate inline script tag filter:
The uBlock filters list, which is selected by default, already contains a couple of inline script tag filters to take care of some of these annoyances.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
- Wiki home
- About the Wiki documentation
- Permissions
- Privacy policy
- Info:
- The toolbar icon
- The popup user interface
- The context menu
- Dashboard
- Settings pane
- Filter lists pane
- My filters pane
- My rules pane
- Trusted sites pane
- Keyboard shortcuts
- The logger
- Element picker
- Element zapper
- Blocking mode
- Very easy mode
- Easy mode (default)
- Medium mode (optimal for advanced users)
- Hard mode
- Nightmare mode
- Strict blocking
- Few words about re-design of uBO's user interface
- Reference answers to various topics seen in the wild
- Overview of uBlock's network filtering engine
- Overview of uBlock's network filtering engine: details
- Does uBlock Origin block ads or just hide them?
- Doesn't uBlock Origin add overhead to page load?
- About "Why uBlock Origin works so much better than Pi‑hole does?"
- uBlock's blocking and protection effectiveness:
- uBlock's resource usage and efficiency:
- Memory footprint: what happens inside uBlock after installation
- uBlock vs. ABP: efficiency compared
- Counterpoint: Who cares about efficiency, I have 8 GB RAM and|or a quad core CPU
- Debunking "uBlock Origin is less efficient than Adguard" claims
- Myth: uBlock consumes over 80MB
- Myth: uBlock is just slightly less resource intensive than Adblock Plus
- Myth: uBlock consumes several or several dozen GB of RAM
- Various videos showing side by side comparison of the load speed of complex sites
- Own memory usage: benchmarks over time
- Contributed memory usage: benchmarks over time
- Can uBO crash a browser?
- Tools, tests
- Deploying uBlock Origin
- Proposal for integration/unit testing
- uBlock Origin Core (Node.js):
- Troubleshooting:
- Good external guides:
- Scientific papers
uBlock Origin - An efficient blocker for Chromium and Firefox. Fast and lean.