Adding scripts to uBlock Origin means writing filter rules that block or modify content beyond what the default filter lists do

uBlock Origin stores custom rules in its My filters tab, where you write instructions that tell the extension what to block, hide, or change on specific websites. You do not need to code — the filter syntax is a set of patterns and commands that uBlock Origin reads and applies. Most people add scripts to block ads that slip through default lists, hide website elements, or prevent tracking on sites they visit regularly.

The process is the same across browsers: open uBlock Origin's dashboard, go to My filters, type your rule, and save. The rule takes effect when ready on pages you reload. If the rule breaks a website or does not work, you delete it and try again — there is no penalty for experimenting.

Key Takeaways

  • Custom filter rules go in the My filters tab of uBlock Origin's dashboard, not in a separate script manager.
  • The simplest rules hide elements on a page using CSS selectors, which you can find by right-clicking an ad or element and inspecting it.
  • Rules take effect when ready when you save them, and you can test them by reloading the page.
  • If a rule breaks a website or stops working after an update, you can disable or delete it without affecting other rules.
  • uBlock Origin's filter syntax is different from browser script managers — do not paste userscripts into My filters.

Opening the uBlock Origin dashboard and finding My filters

Click the uBlock Origin icon in your browser's toolbar, then click the gear icon in the bottom right corner of the popup. This opens the dashboard in a new tab. On the left side, you will see tabs labeled Dashboard, Settings, Filter lists, My filters, and others. Click My filters.

My filters is a text box where you write one rule per line. Above the text box, uBlock Origin shows how many rules you have written and how many are active. If you have never added a custom rule before, the box will be empty. Start typing your first rule directly into the box — there is no button to click to create a new rule.

Writing a basic rule to hide an element on a page

The easiest rule to write hides a specific element — an ad, a banner, a sidebar — on a website. To do this, you need the element's CSS selector, which is a way of pointing to that element in the page's code.

Right-click the element you want to hide and select Inspect or Inspect Element. Your browser's developer tools will open and highlight the code for that element. Look for a tag like <div class="ad-banner"> or <div id="sidebar">. The class name or id is what you need. If the element has a class, the selector is a period followed by the class name: .ad-banner. If it has an id, the selector is a hash followed by the id: #sidebar.

In My filters, type the website's domain, two colons, and the selector. For example, to hide an element with class "ad-banner" on example.com, write:

example.com##.ad-banner

Press Enter or click outside the text box to save. Reload the page in your browser. The element should disappear. If it does not, the selector may be wrong — inspect the element again and check the class or id name for typos.

Blocking a specific URL or resource

If an ad or tracker loads from a specific URL, you can block it directly. For example, if ads load from ads.example.com/banner.js, you can write a rule that stops that file from loading at all.

Open your browser's developer tools by pressing F12 or right-clicking and selecting Inspect. Go to the Network tab. Reload the page. Look through the list of requests for the ad or tracker you want to block. Click on it and copy its full URL from the address bar or the request details.

In My filters, write a pipe character, the URL or part of the URL, and pipe again. For example:

||ads.example.com/banner.js

This blocks any request to that exact URL. If you want to block all requests to a domain, use:

||ads.example.com^

The caret tells uBlock Origin to stop at the domain boundary. Save the rule and reload the page. The resource should no longer load.

explore a rule to specific websites only

You can write a rule that works on one website but not others by adding the domain before the rule. This is useful if you want to hide an element that appears on many sites but only bothers you on one, or if a rule breaks a website you like.

The format is: domain, then the rule. For example, to hide the element .ad-banner only on example.com:

example.com##.ad-banner

To explore the same rule to multiple domains, separate them with commas:

example.com,another.com,third.com##.ad-banner

To explore a rule to all sites except one, use a pipe and a tilde before the domain you want to exclude:

~example.com##.ad-banner

This hides .ad-banner everywhere except example.com. You can combine multiple exclusions:

~example.com,~another.com##.ad-banner

Testing and fixing rules that do not work

If you add a rule and the element still appears, or if the rule breaks a website, open the developer tools and check the Console tab for errors. uBlock Origin will sometimes log a message if your rule has a syntax error — for example, a missing colon or a mistyped selector.

The most common mistake is copying a selector that is too specific or too general. If you hide .ad, you might hide legitimate content because many elements use that class. If you hide .ad-banner-container-wrapper-v2, the rule may break after the website updates its code. Try a middle ground: use a class or id that clearly describes the ad or element, and test the rule on a few pages of the site to make sure it does not break anything.

If a rule stops working after a website updates, the element's code probably changed. Inspect the element again, find the new class or id, and update your rule. You can also disable a rule temporarily by adding ! at the start of the line:

!example.com##.ad-banner

The rule will not run, but you can re-enable it later by removing the !. To delete a rule, select the entire line and press Delete or Backspace.

Understanding the difference between My filters and userscripts

uBlock Origin's My filters tab is not the same as a userscript manager like Tampermonkey or Greasemonkey. My filters uses uBlock Origin's filter syntax, which is designed for blocking and hiding elements. Userscripts use JavaScript, which can modify page behavior, automate actions, and do much more complex things.

If you find a userscript online and try to paste it into My filters, it will not work — uBlock Origin will not understand the JavaScript code. If you want to run userscripts, you need to install a separate extension like Tampermonkey, then add the script there. My filters is for filter rules only: blocking URLs, hiding elements, and modifying how ads and trackers load.

Some websites and forums share filter rules designed for uBlock Origin. These rules are safe to copy into My filters. Userscripts shared on sites like Greasy Fork are not — they belong in a userscript manager instead.

Frequently Asked Questions

Can I back up my custom rules so I do not lose them if I reinstall my browser?

Yes. In the My filters tab, select all the text (Ctrl+A or Cmd+A), copy it, and paste it into a text file on your computer. When you reinstall your browser or set up uBlock Origin on a new device, open My filters and paste the rules back in. uBlock Origin does not sync rules across devices automatically, so manual backup is the only way to preserve them.

What does the caret symbol (^) do in a filter rule?

The caret marks a boundary in a URL — usually the end of the domain name. For example, ||ads.example.com^ blocks all requests to ads.example.com and any path under it, like ads.example.com/banner.js or ads.example.com/tracker. Without the caret, uBlock Origin might not recognize where the domain ends, especially if the URL is complex.

If I add a rule that breaks a website, will it affect other websites?

No. Each rule applies only to the domains you specify. If you write example.com##.sidebar and it hides something important, other websites are not affected. You can delete or disable that rule without touching any others. This is why it is safe to experiment — a bad rule only breaks the site you wrote it for.

Can I use regular expressions in My filters?

Yes, but only in specific contexts. uBlock Origin supports regex (regular expressions) in URL-blocking rules if you prefix the rule with / and end it with /. For example, ||/ads.*\.js/ blocks any JavaScript file with "ads" in the name. Regex in CSS selectors (the ## rules) is not supported — use standard CSS selectors instead.

Where do I find filter rules that other people have written?

Many websites and forums share uBlock Origin filter rules. Reddit communities like r/uBlockOrigin, GitHub repositories, and ad-blocking forums post rules for specific websites and trackers. When you find a rule, copy it and paste it into My filters. Always check that a rule comes from a trusted source before adding it — malicious rules could theoretically hide important content or cause other problems.