HTMLIFrameElement.getScreenshot()

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The getScreenshot() method of the HTMLIFrameElement lets you request a screenshot of an content <iframe>, scaled to fit within a specified maximum width and height. The image will be cropped if necessary but will not be distorted vertically or horizontally.

Note: getScreenshot() waits for the event loop to go idle before it takes the screenshot. It won't wait more than 2000ms (this delay is defined by the Gecko dom.browserElement.maxScreenshotDelayMS preference).

Syntax

var instanceOfDOMRequest =
instanceOfHTMLIframeElement.getScreenshot(maxWidth, maxHeight, mimeType);

Returns

A DOMRequest for handling the screenshot request. Its request.onsuccess handler handles the success case (the screenshot is contained in request.result as a Blob object), and its request.onerror handler handles the failure case.

Parameters

maxWidth
A number representing the maximum width of the screenshot in device pixels.
maxHeight
A number representing the maximum height of the screenshot in device pixels.
mimeType Optional
A MIME type specifying the format of the image to be returned; if not specified, the default used is image/jpeg. Use image/png to capture the alpha channel of the rendered result by returning a PNG-format image. This lets you get a transparent background for the content <iframe>.

Examples

var browser = document.querySelector('iframe');
var request = browser.getScreenshot(100, 100);
request.onsuccess = function() {
  var blob = request.result;
  var url = URL.createObjectURL(blob);
}

Specification

Not part of any specification.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support No support 47 (47)[1] No support No support No support
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support No support No support No support No support No support No support No support

[1] Supported in chrome code only.

See also

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, wbamberg, teoli, timdream, Sheppy, ajaybhat, kscarfone, Jeremie
 Last updated by: chrisdavidmills,