extension.getViews()

Returns an array of the Window objects for each of the pages running inside the current extension. This includes, for example:

  • the background page, if one is defined
  • any popup pages, if defined and loaded
  • any options pages, if defined and loaded
  • any browser tabs that host content packaged with the extension

In Firefox, if this method is called from a page that is part of a private browsing window, such as a sidebar in a private window or a popup opened from a private window, then its return value will not include the extension's background page.

Syntax

js
let windows = browser.extension.getViews(
  fetchProperties // optional object
)

Parameters

fetchProperties Optional

An object with the following properties:

type Optional

string. An extension.ViewType indicating the type of view to get. If omitted, this function returns all views.

windowId Optional

integer. The window to restrict the search to. If omitted, this function returns all views. In Firefox version 92 and earlier, sidebar views are not matched and, therefore, not returned.

Return value

array of object. Array of Window objects.

Examples

Get all windows belonging to this extension, and log their URLs:

js
const windows = browser.extension.getViews();

for (const extensionWindow of windows) {
  console.log(extensionWindow.location.href);
}

Get only windows in browser tabs hosting content packaged with the extension:

js
const windows = browser.extension.getViews({ type: "tab" });

Get only windows in popups:

js
const windows = browser.extension.getViews({ type: "popup" });

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
getViews
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote
footnote If this is called from a page that is part of a private browsing window, such as a sidebar in a private window or a popup opened from a private window, then its return value will not include the extension's background page.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 48 (Release date: 2016-08-02)
footnote
footnote If this is called from a page that is part of a private browsing window, such as a sidebar in a private window or a popup opened from a private window, then its return value will not include the extension's background page.
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote Full support
windowId
Chrome – Full support
Chrome 5 (Release date: 2010-05-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote
footnote Since Firefox 93, sidebar views are now matched.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Partial support
Safari 14 – 17.6 (Release date: 2020-09-16)
footnote Partial support
footnote Filtering by windowId doesn't work when a tab is moved from one window to another.
Safari – Full support
Safari 18 (Release date: 2024-09-16)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 48 (Release date: 2016-08-02)
footnote Partial support
footnote The property is recognized, but the filter has no effect.
Safari on iOS – Partial support
Safari on iOS 15 – 17.6 (Release date: 2021-09-20)
footnote Partial support
footnote Filtering by windowId doesn't work when a tab is moved from one window to another.
Safari on iOS – Full support
Safari on iOS 18 (Release date: 2024-09-16)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
See implementation notes.
Has more compatibility info.

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