How to write adblock rule for xbrowser

Brief introduction

XBrowser’s rule is not completely compatible with ABP rule writing. You know,ABP was born in PC era, so we did not fully implement the Ad blocking rules of ABP because of the performance of mobile devices, but provided simple and efficient Ad blocking strategy and rule writing, basically taking into account both performance and blocking effect.

After testing, XBrowser can execute more than 10,000 records Ad-blocking rules while browsing the page without significant impact on page rendering.

Most of the ABP rules can be imported into XBrowser by providing automatic rule importing tools in XBrowser. However, it is not recommended to import ABP official complete rules directly, because most of the ABP official rules are for PC browsers. Loading too many rules will only lead to unnecessary performance consumption.

Quick example
Block AD host whose domain is ""
Block all .gif files
Block all gif files This rule only takes effect under
Blocking request whose script's path is '/runtime/js/index960.js'
Block all request whose directory part of url start with '/content/ads'
block all URLs ending with '/ad/show_banner.js'
Remove page elements whose ID is "ad-container"
Remove page elements whose class name is "ad-container"
Remove all elements which property value contain the string "adv".

More instructions and examples

Like ABP, XBrowser provide two different kinds of ad-blocking strategy.“Interception strategy” and “Element hiding strategy”You can choose appropriate blocking strategy for different types of ads.

Interception strategy

The interception strategy blocks AD by matching the URL of the advertising website before the network request, which can effectively be blocking advertising resources loaded from outside, and the performance is also the best.

“Interception strategy” provides two matching methods, one is based on domain name and directory matching and the other is based on Regular expression matching. From the performance point of view, you should first use domain name and directory matching to write rules. Regular expression matching is complementary.

Blocking by domain and directory
Basic syntax and examples
This rule will block all ad resource URL with the top-level domain name, such as,, etc, will be blocked.
Block any ad resource url whose path start with "/content/ads".exp:","" etc
Block all ad resource url whose top domain is and path start with "/content/ads"
Block url whose path end with '/ad/banner.js',exp:*/ad/banner.js
As above,But the domain name of the URL is limited to
Control options

Like the rule syntax of ABP, the control parameter is immediately followed by “$”.The currently supported parameter option is “3p” which corresponds to the “third party” of ABP. The following example shows its usage.


Block url whose path start with ‘/ad/banner’ . But this rule is only valid for resources url of the third party. In other words, resources under the current domain name are not limited.

Contrary to the above example, the rule only works for resources under the current domain name
Blocking by regular expression

For users who know regular expressions, they can achieve more flexible pattern matching through regular expressions.

Convention: regular expression rules start with “–”.In other words, “–” is followed by the regular expression you want to write, as shown in the example below.

Blocking any URL that contains the string "ads"
Blocking any URL whose suffix is ".swf"
Blocking all URL whose subdomain is "ad" + digital. for example,,
Blocking all java script whose name contains the string "ad". For example:""

Element hiding strategy

For some ads that are not loaded by external resources and scripts. In other words, we can’t block it by interception strategy.

At this point, you can remove advertising elements from the page by “Element hiding” rule.

The element hiding rule same as ABP Element hiding rule which starts with “##” and followed by a CSS selector expression. Here are some examples of hidden element rules.

Remove the page element whose id is "mybanner"
Remove the page elements whose class name is "ad-container"
Remove all elements which property value contain the string "adv"

Like the hidden element rule of ABP, the scope of the Hiding element rule can be controlled by adding a domain name prefix, as shown in the following example.
Removes an element whose id is "mybanner" and the rule takes effect only under the

Rule scope

By default, the blocking rules you write will take effect on all sites except whitelists. Sometimes we can limit the scope of the rules in order to avoid mistakenly killing other sites. these rules will only take effect under certain domain names.

To set the scope of a rule, simply add “@” after the original rules and followed by the domain name we need to qualify. Below are valid rules with a scope.

In order to be compatible with the writing of ABP’s element hiding rule scopes, the following two methods are equivalent.

The scope supports multiple domain names, and the domain names are separated by “,”. The following is a example.,,,,

Test your rules

In addition, we have provided an ad-blocking test case page, which you can use to test whether your ad-blocking strategy works properly.