tabs.captureVisibleTab()

Creates a data URL encoding the image of an area of the active tab in the specified window. You must have the <all_urls> or activeTab permission.

Note: In Firefox 125 and earlier, this method was only available with the <all_urls> permission.

In addition to sites that extensions can normally access, this method allows extensions to capture sensitive sites that are otherwise restricted, including browser UI pages and other extensions' pages. These sensitive sites can only be captured with the activeTab permission. Chrome also permits file URLs to be captured when the extension has been granted file access.

This is an asynchronous function that returns a Promise.

Syntax

js
let capturing = browser.tabs.captureVisibleTab(
  windowId,               // optional integer
  options                 // optional extensionTypes.ImageDetails
)

Parameters

windowId Optional

integer. The target window. Defaults to the current window.

options Optional

extensionTypes.ImageDetails.

Return value

A Promise that is fulfilled with a data URL that encodes the captured image. It can be assigned to the 'src' property of an HTML image element for display. If any error occurs, the promise is rejected with an error message.

Examples

Capture an image of the active tab in the current window with default image settings:

js
function onCaptured(imageUri) {
  console.log(imageUri);
}

function onError(error) {
  console.log(`Error: ${error}`);
}

browser.browserAction.onClicked.addListener(() => {
  let capturing = browser.tabs.captureVisibleTab();
  capturing.then(onCaptured, onError);
});

Browser compatibility

BCD tables only load in the browser

Note: This API is based on Chromium's chrome.tabs API. This documentation is derived from tabs.json in the Chromium code.