chrome.windows (original) (raw)

Skip to main content

chrome.windows

Description

Use the chrome.windows API to interact with browser windows. You can use this API to create, modify, and rearrange windows in the browser.

Permissions

When requested, a windows.Window contains an array of tabs.Tab objects. You must declare the "tabs" permission in your manifest if you need access to the url,pendingUrl, title, or favIconUrl properties of tabs.Tab. For example:

{
  "name": "My extension",
  ...
  "permissions": ["tabs"],
  ...
}

Concepts and usage

The current window

Many functions in the extension system take an optional windowId argument, which defaults to the current window.

The current window is the window that contains the code that is currently executing. It's important to realize that this can be different from the topmost or focused window.

For example, say an extension creates a few tabs or windows from a single HTML file, and that the HTML file contains a call to tabs.query(). The current window is the window that contains the page that made the call, no matter what the topmost window is.

In the case of service workers, the value of the current window falls back to the last active window. Under some circumstances, there may be no current window for background pages.

Examples

To try this API, install the windows API example from the chrome-extension-samplesrepository.

Two windows, each with one tab

Two windows, each with one tab.

Types

CreateType

Specifies what type of browser window to create. 'panel' is deprecated and is available only to existing allowlisted extensions on Chrome OS.

Enum

"normal"
Specifies the window as a standard window.

"popup"
Specifies the window as a popup window.

"panel"
Specifies the window as a panel.

QueryOptions

Properties

Window

Properties

WindowState

The state of this browser window. In some circumstances a window may not be assigned a state property; for example, when querying closed windows from the sessions API.

Enum

"normal"
Normal window state (not minimized, maximized, or fullscreen).

"minimized"
Minimized window state.

"maximized"
Maximized window state.

"fullscreen"
Fullscreen window state.

"locked-fullscreen"
Locked fullscreen window state. This fullscreen state cannot be exited by user action and is available only to allowlisted extensions on Chrome OS.

WindowType

The type of browser window this is. In some circumstances a window may not be assigned a type property; for example, when querying closed windows from the sessions API.

Enum

"normal"
A normal browser window.

"popup"
A browser popup.

"panel"
Deprecated in this API. A Chrome App panel-style window. Extensions can only see their own panel windows.

"app"
Deprecated in this API. A Chrome App window. Extensions can only see their app own windows.

"devtools"
A Developer Tools window.

Properties

WINDOW_ID_CURRENT

The windowId value that represents the current window.

WINDOW_ID_NONE

The windowId value that represents the absence of a Chrome browser window.

Methods

create()

chrome.windows.create(
  createData?: object,
): Promise<Window | undefined>

Creates (opens) a new browser window with any optional sizing, position, or default URL provided.

Parameters

Returns

get()

chrome.windows.get(
  windowId: number,
  queryOptions?: QueryOptions,
): Promise<Window>

Gets details about a window.

Parameters

Returns

getAll()

chrome.windows.getAll(
  queryOptions?: QueryOptions,
): Promise<Window[]>

Gets all windows.

Parameters

Returns

getCurrent()

chrome.windows.getCurrent(
  queryOptions?: QueryOptions,
): Promise<Window>

Gets the current window.

Parameters

Returns

getLastFocused()

chrome.windows.getLastFocused(
  queryOptions?: QueryOptions,
): Promise<Window>

Gets the window that was most recently focused — typically the window 'on top'.

Parameters

Returns

remove()

chrome.windows.remove(
  windowId: number,
): Promise

Removes (closes) a window and all the tabs inside it.

Parameters

Returns

update()

chrome.windows.update(
  windowId: number,
  updateInfo: object,
): Promise<Window>

Updates the properties of a window. Specify only the properties that to be changed; unspecified properties are unchanged.

Parameters

Returns

Events

onBoundsChanged

chrome.windows.onBoundsChanged.addListener(
  callback: function,
)

Fired when a window has been resized; this event is only dispatched when the new bounds are committed, and not for in-progress changes.

Parameters

onCreated

chrome.windows.onCreated.addListener(
  callback: function,
  filters?: object,
)

Fired when a window is created.

Parameters

onFocusChanged

chrome.windows.onFocusChanged.addListener(
  callback: function,
  filters?: object,
)

Fired when the currently focused window changes. Returns chrome.windows.WINDOW_ID_NONE if all Chrome windows have lost focus. Note: On some Linux window managers, WINDOW_ID_NONE is always sent immediately preceding a switch from one Chrome window to another.

Parameters

onRemoved

chrome.windows.onRemoved.addListener(
  callback: function,
  filters?: object,
)

Fired when a window is removed (closed).

Parameters

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-11 UTC.