Windows
For information on how to use experimental APIs, see the chrome.experimental.* APIs page.
Windows
Use the chrome.windows
module
to interact with browser windows.
You can use this module to
create, modify, and rearrange windows in the browser.
Manifest
To use the windows API,
you must declare the "tabs" permission
in manifest.json.
(No, that isn't a typo —
the window and tabs modules interact so closely we
decided to just share one permission between them.)
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
chrome.tabs.getSelected.
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 background 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.
API reference: chrome.windows
Properties
WINDOW_ID_NONE
chrome.windows.WINDOW_ID_NONE
WINDOW_ID_NONE
(
optional
enumerated
Type
array of
integer
)
Undocumented.
The windowId value that represents the absence of a chrome browser window.
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
Methods
create
void
chrome.windows.create(, object
createData, function
callback)
Undocumented.
Creates (opens) a new browser with any optional sizing, position or default URL provided.
Parameters
-
createData
(
optional
enumerated
Type
array of
object
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
url
(
optional
enumerated
Type
array of
string or array of string
)
-
Undocumented.
- A URL or list of URLs to open as tabs in the window. Fully-qualified URLs must include a scheme (i.e. 'http://www.google.com', not 'www.google.com'). Relative URLs will be relative to the current page within the extension. Defaults to the New Tab Page.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
tabId
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The id of the tab for which you want to adopt to the new window.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
left
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- 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 focusd window.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
top
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- 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 focusd window.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
width
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The width in pixels of the new window. If not specified defaults to a natural width.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
height
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The height in pixels of the new window. If not specified defaults to a natural height.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
focused
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
- If true, opens an active window. If false, opens an inactive window.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
incognito
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
- Whether the new window should be an incognito window.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
type
(
optional
enumerated
Type
array of
string
["normal", "popup", "panel"]
)
-
Undocumented.
- Specifies what type of browser window to create. The 'panel' type requires the 'experimental' permission.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
-
-
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function(Window window) {...};
-
window
(
optional
enumerated
Window
array of
paramType
)
-
Undocumented.
- Contains details about the created window.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
get
void
chrome.windows.get(, integer
windowId, function
callback)
Undocumented.
Gets details about a window.
Parameters
-
windowId
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function(Window window) {...};
-
window
(
optional
enumerated
Window
array of
paramType
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
getAll
void
chrome.windows.getAll(, object
getInfo, function
callback)
Undocumented.
Gets all windows.
Parameters
-
getInfo
(
optional
enumerated
Type
array of
object
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
populate
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
- If true, each window object will have a tabs property that contains a list of the Tab objects for that window.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
-
-
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function(array of Window windows) {...};
-
windows
(
optional
enumerated
Type
array of
Window
array of
paramType
paramType
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
getCurrent
void
chrome.windows.getCurrent(, function
callback)
Undocumented.
Gets the current window.
Parameters
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function(Window window) {...};
-
window
(
optional
enumerated
Window
array of
paramType
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
getLastFocused
void
chrome.windows.getLastFocused(, function
callback)
Undocumented.
Gets the window that was most recently focused — typically the window 'on top'.
Parameters
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function(Window window) {...};
-
window
(
optional
enumerated
Window
array of
paramType
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
remove
void
chrome.windows.remove(, integer
windowId, function
callback)
Undocumented.
Removes (closes) a window, and all the tabs inside it.
Parameters
-
windowId
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function() {...};
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
update
void
chrome.windows.update(, integer
windowId, object
updateInfo, function
callback)
Undocumented.
Updates the properties of a window. Specify only the properties that you want to change; unspecified properties will be left unchanged.
Parameters
-
windowId
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
updateInfo
(
optional
enumerated
Type
array of
object
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
left
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The offset from the left edge of the screen to move the window to in pixels.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
top
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The offset from the top edge of the screen to move the window to in pixels.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
width
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The width to resize the window to in pixels.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
height
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The height to resize the window to in pixels.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
focused
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
- If true, brings the window to the front. If false, brings the next window in the z-order to the front.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
-
-
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function(Window window) {...};
-
window
(
optional
enumerated
Window
array of
paramType
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
Events
onCreated
chrome.windows.onCreated.addListener(function(Window window) {...});
Undocumented.
Fired when a window is created.
Parameters
-
window
(
optional
enumerated
Window
array of
paramType
)
-
Undocumented.
- Details of the window that was created.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
onFocusChanged
chrome.windows.onFocusChanged.addListener(function(integer windowId) {...});
Undocumented.
Fired when the currently focused window changes. Will be chrome.windows.WINDOW_ID_NONE if all chrome windows have lost focus. Note: On some Linux window managers, WINDOW_ID_NONE will always be sent immediately preceding a switch from one chrome window to another.
Parameters
-
windowId
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- ID of the newly focused window.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
onRemoved
chrome.windows.onRemoved.addListener(function(integer windowId) {...});
Undocumented.
Fired when a window is removed (closed).
Parameters
-
windowId
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- ID of the removed window.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Types
Window
paramName
(
optional
enumerated
Type
array of
object
)
Undocumented.
Description of this parameter from the json schema.
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
id
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The ID of the window. Window IDs are unique within a browser session.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
focused
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
- Whether the window is currently the focused window.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
top
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The offset of the window from the top edge of the screen in pixels.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
left
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The offset of the window from the left edge of the screen in pixels.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
width
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The width of the window in pixels.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
height
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The height of the window in pixels.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
tabs
(
optional
enumerated
Type
array of
Tab
array of
paramType
paramType
)
-
Undocumented.
- Array of Tab objects representing the current tabs in the window.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
incognito
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
- Whether the window is incognito.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
type
(
optional
enumerated
Type
array of
string
["normal", "popup", "panel", "app"]
)
-
Undocumented.
- The type of browser window this is. The 'panel' type requires the 'experimental' permission.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-