opera.extension.getScreenshot() and BrowserTab.getScreenshot()

By Opera Software

From Opera 15 onward, Opera 11 & 12’s extension format is no longer supported, and instead, we’ve switched to Chromium’s extension model. Check out our new documentation for developing extensions for Opera 15 and higher and start building your own extensions.


Captures a screenshot of a page within a tab.


  • callback: The callback function to execute. The callback function takes an ImageData object as its parameter, provided by the API.


void getScreenshot (<Function> callback)


  The configuration file ('config.xml').
<?xml version='1.0' encoding='utf-8'?>
<widget xmlns="http://www.w3.org/ns/widgets">
    <feature name="opera:screenshot" required="false"/>
// An injected script (e.g. includes/injected.js)

window.addEventListener('load', function() {
  // Check the Screenshot API is available
  if (opera.extension.getScreenshot) {
    opera.postError('Screenshot API found');

    // Callback function to replace page content with the screenshot
    function applyScreenshot(imageData) {
      opera.postError('Appending screenshot to current page...');

      // Create a blank canvas
      var canvas = document.createElement('canvas');
      canvas.width = imageData.width;
      canvas.height = imageData.height;

      // Write the screenshot image data to the canvas context
      var ctx = canvas.getContext('2d');
      ctx.putImageData(imageData, 0, 0);

      // Replace the page's content with the canvas
      var body = document.body;
      body.innerHTML = '';

      opera.postError('Snapshot appended to current page.');

    // Use the API's method to execute the callback function
  } else {
    opera.postError('No Screenshot API found');
}, false);

This article is licensed under a Creative Commons Attribution 3.0 Unported license.


No new comments accepted.