Contents
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
You must declare the "tabs" permission in your extension's manifest to use the windows API. (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 that uses windows", "version": "0.1", "permissions": [ "tabs" ] }
The current window
Many functions in the extension system take an optional windowId parameter which is documented to default 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, consider code running in a toolstrip, that calls chrome.tabs.getSelected. The current window is the window that contains the toolstrip 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 topmost window.
API reference: chrome.windows
Methods
create
Create (open) a new browser with any optional sizing, position or default url provided.
Parameters
-
createData
( optional object )
- Undocumented.
-
-
url
( optional string )
- The URL to navigate the first tab to. 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.
-
left
( optional integer )
- 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.
-
top
( optional integer )
- 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.
-
width
( optional integer )
- The width in pixels of the new window. If not specified defaults to a natural width.
-
height
( optional integer )
- The height in pixels of the new window. If not specified defaults to a natural height.
-
url
-
callback
( optional function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(Window window) {...});
-
window
( Window )
- Contains details about the created window.
get
Gets details about a window.
Parameters
-
windowId
( integer )
- Undocumented.
-
callback
( function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(Window window) {...});
-
window
( Window )
- Undocumented.
getAll
Get all windows.
Parameters
-
getInfo
( optional object )
- Undocumented.
-
-
populate
( optional boolean )
- If true, each window object will have a tabs property that contains a list of the Tab objects for that window.
-
populate
-
callback
( function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(array of Window windows) {...});
-
windows
( array of Window )
- Undocumented.
getCurrent
Gets the current window.
Parameters
-
callback
( function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(Window window) {...});
-
window
( Window )
- Undocumented.
getLastFocused
Get the window that was most recently focused -- typically the window 'on top'.
Parameters
-
callback
( function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(Window window) {...});
-
window
( Window )
- Undocumented.
remove
Removes (closes) a window, and all the tabs inside it.
Parameters
-
windowId
( integer )
- Undocumented.
-
callback
( optional function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function() {...});
update
Update the properties of a window. Only specify the properties that you want to change, unspecified properties will be left unchanged.
Parameters
-
windowId
( integer )
- Undocumented.
-
updateInfo
( object )
- Undocumented.
-
-
left
( optional integer )
- The offset from the left edge of the screen to move the window to in pixels.
-
top
( optional integer )
- The offset from the top edge of the screen to move the window to in pixels.
-
width
( optional integer )
- The width to resize the window to in pixels.
-
height
( optional integer )
- The height to resize the window to in pixels.
-
left
-
callback
( optional function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(Window window) {...});
-
window
( Window )
- Undocumented.
Events
onCreated
Fired when a window is created.
Parameters
-
createInfo
( object )
- Undocumented.
-
-
id
( integer )
- ID of the new window.
-
id
Types
Window
-
id
( integer )
- The ID of the window. Window IDs are unique within a browser session.
-
focused
( boolean )
- Whether the window is currently the focused window.
-
top
( integer )
- The offset of the window from the top edge of the screen in pixels.
-
left
( integer )
- The offset of the window from the left edge of the screen in pixels.
-
width
( integer )
- The width of the window in pixels.
-
height
( integer )
- The height of the window in pixels.