Desktop Build With New Extension APIs: Screenshot, Resource Loader and URL Filter

We've been working hard recently to improve the functionality available inside Opera extensions, and today we are proud to reveal some of the fruits of our labours. In this article we'll share with you some new experimental desktop builds that feature three new extension APIs:

  • A screenshot API for capturing screenshots of pages within tabs
  • A resource loader API for easier loading of local resources by an extension
  • Some updates to the URL filter API (for adding and removing URLs to and from Opera's list of blocked URLs)

Below you'll find details of where to download the builds, what the new features do, and available documentation. Please give us as much feedback as you can on all this new experimental functionality before it becomes finalised.

Note that these features are now available in Opera for desktop version 12.10 and above.

Download the builds

We have builds available for:

The screenshot API

You can use the screenshot API to capture screenshots of pages within tabs in the browser by calling the getScreenshot() method from an extension injected or background script. You might want to take a screenshot of the current page and manipulate it within a <canvas>, or store it somewhere for later use.

Further reading:

The resource loader API

The resource loader API has been created to get around a problem whereby the extension security model will not allow local files to be accessed by an extension even if they are contained within the same extension package. The resource loader API's getfile() method can be used to grab the contents of a file, and those contents can then be read using the W3C File API. This is useful in so many ways — if you want to pull in different content, images or even script and styles into your extension.

Further reading:

The URL filter API

Finally, the URL filter API allows you to add and remove URLs to and from the Opera native content blocker's list of blocked URLs. Such changes added through the API are temporary, and only remain in effect for as long as the browser session is active and the extension is enabled.

This API was originally available in Opera 11.10, but since then we've added some new features that are available to experiment with in this set of builds:

  • White list support — intended as a list of exceptions to the blocked URL (black) list. The basic syntax looks like this — opera.extension.urlfilter.allow.add(pattern, options)
  • Including domains: block.add(pattern, {includeDomains: ["google.com", "google.co.uk", "google.com.au"])
  • Excluding domains: block.add(pattern, {excludeDomains: ["google.com", "google.co.uk", "google.com.au"])
  • Ability to fire events when a URL is blocked (black list) or allowed (white list). At the moment we don't intend to allow firing of events when there are no matches (when the URL is allowed because it is not in any list), as this can potentially impact performance
  • Third-party blocking (for example, blocking facebook.com only when it is called from another site) of URLs: block.add(pattern, {thirdParty: true})
  • Filtering by resource types (scripts, images, stylesheets, etc.): block.add(pattern, {resources: urlfilter.RESOURCE_SCRIPT | urlfilter.RESOURCE_STYLESHEET)
  • New filter syntax:
    • There is now a separator wildcard character available, ^. For example, example.com^foo will match example.com/foo and example.com?foo
    • You also have hostname matching syntax — ||. For example, ||example.com will match any URL with example.com as the filter
  • New syntax will also be enabled in the urlfilter.ini file

Further reading:

Cover image by Comedy Nose