- Description
Use thechrome.windowsAPI to interact with browser windows. You can use this API to create, modify, and rearrange windows in the browser.
Manifest
When requested, awindows.Windowwill contain an array oftabs.Tabobjects. You must declare the"tabs"permission in your manifest if you require access to theurl,pendingUrl,title, orfavIconUrlproperties oftabs.Tab. For example:{"name": "My extension",..."permissions": ["tabs"],...}
The current window
Many functions in the extension system take an optional windowId parameter, 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 the event page, 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

You can find simple examples of using the windows module in the examples/api/windows directory. Another example is in the tabs_api.html file of the inspector example. For other examples and for help in viewing the source code, see Samples.Summary
| Types | QueryOptions
Window
CreateType
WindowState
WindowType | | —- | —- | | Properties | WINDOW_ID_CURRENT
WINDOW_ID_NONE | | Methods | createwindows.create(createData: object, callback: function)
getwindows.get(windowId: number, queryOptions?: [QueryOptions](https://developer.chrome.com/docs/extensions/reference/windows/#type-QueryOptions), callback: function)
getAllwindows.getAll(queryOptions?: [QueryOptions](https://developer.chrome.com/docs/extensions/reference/windows/#type-QueryOptions), callback: function)
getCurrentwindows.getCurrent(queryOptions?: [QueryOptions](https://developer.chrome.com/docs/extensions/reference/windows/#type-QueryOptions), callback: function)
getLastFocusedwindows.getLastFocused(queryOptions?: [QueryOptions](https://developer.chrome.com/docs/extensions/reference/windows/#type-QueryOptions), callback: function)
removewindows.remove(windowId: number, callback: function)
updatewindows.update(windowId: number, updateInfo: object, callback: function)| | Events | onBoundsChanged
onCreated
onFocusChanged
onRemoved |
Types
QueryOptions
PROPERTIES
- populate
booleanoptional
If true, theWindowobject has a tabs property that contains a list of thetabs.Tabobjects. TheTabobjects only contain theurl,pendingUrl,title, andfavIconUrlproperties if the extension’s manifest file includes the"tabs"permission. windowTypes
tabs.WindowType[]optional
If set, theWindowreturned is filtered based on its type. If unset, the default filter is set to['normal', 'popup'].
Window
PROPERTIES
alwaysOnTop
boolean
Whether the window is set to be always on top.- focused
boolean
Whether the window is currently the focused window. - height
numberoptional
The height of the window, including the frame, in pixels. In some circumstances a window may not be assigned aheightproperty; for example, when querying closed windows from thesessionsAPI. - id
numberoptional
The ID of the window. Window IDs are unique within a browser session. In some circumstances a window may not be assigned anIDproperty; for example, when querying windows using thesessionsAPI, in which case a session ID may be present. - incognito
boolean
Whether the window is incognito. - left
numberoptional
The offset of the window from the left edge of the screen in pixels. In some circumstances a window may not be assigned aleftproperty; for example, when querying closed windows from thesessionsAPI. - sessionId
stringoptional
The session ID used to uniquely identify a window, obtained from thesessionsAPI. - state
WindowStateoptional
The state of this browser window. - tabs
tabs.Tab[]optional
Array oftabs.Tabobjects representing the current tabs in the window. - top
numberoptional
The offset of the window from the top edge of the screen in pixels. In some circumstances a window may not be assigned atopproperty; for example, when querying closed windows from thesessionsAPI. - type
tabs.WindowTypeoptional
The type of browser window this is. width
numberoptional
The width of the window, including the frame, in pixels. In some circumstances a window may not be assigned awidthproperty; for example, when querying closed windows from thesessionsAPI.
CreateType
Since Chrome 44.
Specifies what type of browser window to create. ‘panel’ is deprecated and is available only to existing whitelisted extensions on Chrome OS.ENUM
WindowState
Since Chrome 44.
The state of this browser window. In some circumstances a window may not be assigned astateproperty; for example, when querying closed windows from thesessionsAPI.ENUM
"normal","minimized","maximized","fullscreen", or"locked-fullscreen"WindowType
Since Chrome 44.
The type of browser window this is. In some circumstances a window may not be assigned atypeproperty; for example, when querying closed windows from thesessionsAPI.ENUM
"normal","popup","panel","app", or"devtools"Properties
WINDOW_ID_CURRENT
The windowId value that represents the current window.
VALUE
WINDOW_ID_NONE
The windowId value that represents the absence of a chrome browser window.
VALUE
Methods
create
windows.create(createData: object, callback: function)
Creates (opens) a new browser window with any optional sizing, position, or default URL provided.PARAMETERS
createDataobject
- focused
booleanoptional
Iftrue, opens an active window. Iffalse, opens an inactive window. - height
numberoptional
The height in pixels of the new window, including the frame. If not specified, defaults to a natural height. - incognito
booleanoptional
Whether the new window should be an incognito window. - left
numberoptional
The number of pixels to position the new window from the left edge of the screen. If not specified, the new window is offset naturally from the last focused window. This value is ignored for panels. - setSelfAsOpener
booleanoptional
Since Chrome 64.
Iftrue, the newly-created window’s ‘window.opener’ is set to the caller and is in the same unit of related browsing contexts as the caller. - state
WindowStateoptional
Since Chrome 44.
The initial state of the window. Theminimized,maximized, andfullscreenstates cannot be combined withleft,top,width, orheight. - tabId
numberoptional
The ID of the tab to add to the new window. - top
numberoptional
The number of pixels to position the new window from the top edge of the screen. If not specified, the new window is offset naturally from the last focused window. This value is ignored for panels. - type
CreateTypeoptional
Specifies what type of browser window to create. - url
string | string[]optional
A URL or array of URLs to open as tabs in the window. Fully-qualified URLs must include a scheme, e.g., ‘http://www.google.com‘, not ‘www.google.com’. Non-fully-qualified URLs are considered relative within the extension. Defaults to the New Tab Page. - width
numberoptional
The width in pixels of the new window, including the frame. If not specified, defaults to a natural width.
- focused
callbackfunctionThe callback parameter should be a function that looks like this:
(window: [Window](https://developer.chrome.com/docs/extensions/reference/windows/#type-Window)) => {...}- window
Window
Contains details about the created window.
get
windows.get(windowId: number, queryOptions?: [QueryOptions](https://developer.chrome.com/docs/extensions/reference/windows/#type-QueryOptions), callback: function)
Gets details about a window.PARAMETERS
- window
windowId
number- queryOptions
QueryOptionsoptional
Since Chrome 88. callbackfunctionThe callback parameter should be a function that looks like this:
(window: [Window](https://developer.chrome.com/docs/extensions/reference/windows/#type-Window)) => {...}- window
Window
getAll
windows.getAll(queryOptions?: [QueryOptions](https://developer.chrome.com/docs/extensions/reference/windows/#type-QueryOptions), callback: function)
Gets all windows.PARAMETERS
- window
queryOptions
QueryOptionsoptional
Since Chrome 88.callbackfunctionThe callback parameter should be a function that looks like this:
(windows: [Window](https://developer.chrome.com/docs/extensions/reference/windows/#type-Window)[]) => {...}- windows
Window[]
getCurrent
windows.getCurrent(queryOptions?: [QueryOptions](https://developer.chrome.com/docs/extensions/reference/windows/#type-QueryOptions), callback: function)
Gets the current window.PARAMETERS
- windows
queryOptions
QueryOptionsoptional
Since Chrome 88.callbackfunctionThe callback parameter should be a function that looks like this:
(window: [Window](https://developer.chrome.com/docs/extensions/reference/windows/#type-Window)) => {...}- window
Window
getLastFocused
windows.getLastFocused(queryOptions?: [QueryOptions](https://developer.chrome.com/docs/extensions/reference/windows/#type-QueryOptions), callback: function)
Gets the window that was most recently focused — typically the window ‘on top’.PARAMETERS
- window
queryOptions
QueryOptionsoptional
Since Chrome 88.callbackfunctionThe callback parameter should be a function that looks like this:
(window: [Window](https://developer.chrome.com/docs/extensions/reference/windows/#type-Window)) => {...}- window
Window
remove
windows.remove(windowId: number, callback: function)
Removes (closes) a window and all the tabs inside it.PARAMETERS
- window
windowId
numbercallback
function
The callback parameter should be a function that looks like this:() => {...}
update
windows.update(windowId: number, updateInfo: object, callback: function)
Updates the properties of a window. Specify only the properties that to be changed; unspecified properties are unchanged.PARAMETERS
windowId
number- updateInfoobject
- drawAttention
booleanoptional
Iftrue, causes the window to be displayed in a manner that draws the user’s attention to the window, without changing the focused window. The effect lasts until the user changes focus to the window. This option has no effect if the window already has focus. Set tofalseto cancel a previousdrawAttentionrequest. - focused
booleanoptional
Iftrue, brings the window to the front; cannot be combined with the state ‘minimized’. Iffalse, brings the next window in the z-order to the front; cannot be combined with the state ‘fullscreen’ or ‘maximized’. - height
numberoptional
The height to resize the window to in pixels. This value is ignored for panels. - left
numberoptional
The offset from the left edge of the screen to move the window to in pixels. This value is ignored for panels. - state
WindowStateoptional
The new state of the window. The ‘minimized’, ‘maximized’, and ‘fullscreen’ states cannot be combined with ‘left’, ‘top’, ‘width’, or ‘height’. - top
numberoptional
The offset from the top edge of the screen to move the window to in pixels. This value is ignored for panels. - width
numberoptional
The width to resize the window to in pixels. This value is ignored for panels.
- drawAttention
callbackfunctionThe callback parameter should be a function that looks like this:
(window: [Window](https://developer.chrome.com/docs/extensions/reference/windows/#type-Window)) => {...}- window
Window
Events
onBoundsChanged
windows.onBoundsChanged.addListener(listener: function)
Since Chrome 86.
Fired when a window has been resized; this event is only dispatched when the new bounds are committed, and not for in-progress changes.EVENT
- window
listenerfunctionThe listener parameter should be a function that looks like this:
(window: [Window](https://developer.chrome.com/docs/extensions/reference/windows/#type-Window)) => {...}- window
Window
Details of the window. The tabs will not be populated for the window.
onCreated
windows.onCreated.addListener(listener: function)
Fired when a window is created.EVENT
- window
listenerfunctionThe listener parameter should be a function that looks like this:
(window: [Window](https://developer.chrome.com/docs/extensions/reference/windows/#type-Window)) => {...}- window
Window
Details of the created window.
onFocusChanged
windows.onFocusChanged.addListener(listener: function)
Fired when the currently focused window changes. Returnschrome.windows.WINDOW_ID_NONEif all Chrome windows have lost focus. Note: On some Linux window managers,WINDOW_ID_NONEis always sent immediately preceding a switch from one Chrome window to another.EVENT
- window
listenerfunctionThe listener parameter should be a function that looks like this:
(windowId: number) => {...}listenerfunctionThe listener parameter should be a function that looks like this:
(windowId: number) => {...}- windowId
number
ID of the removed window.
- windowId
