« Documentation Home

URL filter

This documentation relates to Opera's now deprecated .oex Extension API framework for Opera versions <= 12.15 and also provided by our OEX2NEX shim library.

For the latest Opera Extensions API documentation for Opera versions > 12.15 please consult the latest Opera Extensions API documentation online.

opera.extension.urlfilter.allow.add()
Adds a rule to the virtual list of allowed URLs. (Opera 12 Labs build only)
opera.extension.urlfilter.block.add()
Adds a rule to the virtual list of blocked URLs.
opera.extension.urlfilter.block.remove()
Removes a rule from the virtual list of blocked URLs.
RuleOptions.excludeDomains
Domains on which to not apply a filter rule. (Opera 12 Labs build only)
RuleOptions.includeDomains
Domains on which to apply a filter rule. (Opera 12 Labs build only)
RuleOptions.resources
Resource types to apply a filter rule to. (Opera 12 Labs build only)
RuleOptions.thirdParty
Specifies whether a filter rule should apply to third-party domains. (Opera 12 Labs build only)
URL Filter syntax
Special characters that can be used when filtering. (Opera 12 Labs build only)

Overview

The URL Filter API for Opera extensions defines a DOM interface that allows extensions to add temporary rules to Opera's native content blocker. Rules added through this API are associated with an extension and apply as long as the extension is enabled. Once an extension is disabled or the browser is shut down, the temporary rules are discarded.

To enable the URL filter, the opera:urlfilter feature needs to be added as a feature element to the extension's config.xml file.

An in-depth tutorial is available at Dev.Opera: Site blocking with Opera's URL Filter API

Note that when developing and testing, some pages and resources may be cached making it look as though blocking rules are not working. If this happens, try using Opera's "Delete private data" feature.

Example

Block example.com/images, example.com/css and any subdirectories, whatever the protocol. Note that www.example.com and other sub-domains are not affected.

<!-- 
  The configuration file ('config.xml').
-->
<?xml version='1.0' encoding='utf-8'?>
<widget xmlns="http://www.w3.org/ns/widgets">
    <feature name="opera:urlfilter"/>
</widget>
//
// The background process (e.g. index.html)
//

// Check that the URL Filter API exists
if (typeof opera.extension.urlfilter != 'undefined') {
  // Create a list of rules to block
  var rules = ['*://example.com/images/*', '*://example.com/css/*'];

  // Assign the URLFilter object to a variable for efficiency
  var filter = opera.extension.urlfilter;

  // Loop through the array of rules and add each one to the "block" list
  for (var i = 0, len = rules.length; i < len; i++) {
    filter.block.add(rules[i]);
  }
}