Developers › Dev.Opera

Desktop build with new extension APIs: Screenshot, Resource Loader and URL Filter

May 16, 2012 · by Chris Mills

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 will not be part of the final Opera 12 release, but a later release.

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

Chris Mills

Chris Mills is a web technologist, open standards evangelist and education agitator, currently working at Opera Software in the developer relations team. He spends most of his time writing articles about web standards for dev.opera.com and other publications (such as .net mag and A List Apart), giving talks at universities and industry conferences, and lobbying universities to improve their web education courses. He believes that education is the answer to everything, but in particular he is passionate about using education to improve the overall content quality, accessibility, usability and future-viability of the Web.

He is the creator of the Opera Web standards curriculum, contributor to the WaSP InterACT project, and coauthor of InterACT with web standards: A Holistic Approach to Web Design. In August 2011, he also accepted the position of co-chair of the newly-formed Web Education Community Group.

Outside work he is a heavy metal drummer, proud father of three and lover of good beer.


About this article

Published inDev.Opera
DateMay 16, 2012
AuthorChris Mills
Tagsextensions, opera, Resource Loader, screenshot, URL filter
OriginalInternet Archive