whale.windows

Description: Use the whale.windows API to interact with browser windows. You can use this API to create, modify, and rearrange windows in the browser.
Availability: Since Chrome 20.
Permissions: The whale.windows API can be used without declaring any permission. However, the "tabs" permission is required in order to populate the [url](tabs#property-Tab-url), [title](tabs#property-Tab-title), and [favIconUrl](tabs#property-Tab-favIconUrl) properties of [Tab](tabs#type-Tab) objects.
## Manifest When requested, a `[windows.Window](/extensions/windows#type-Window)` will contain an array of `[tabs.Tab](/extensions/tabs#type-Tab)` objects. You must declare the `"tabs"` permission in your [manifest](manifest) if you require access to the `[url](/extensions/tabs#property-Tab-url)`, `[title](/extensions/tabs#property-Tab-title)`, or `[favIconUrl](/extensions/tabs#property-Tab-favIconUrl)` properties of `[tabs.Tab](/extensions/tabs#type-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](/extensions/tabs#method-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](event_pages), 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 ![Two windows, each with one tab](/static/images/windows.png) You can find simple examples of using the windows module in the [examples/api/windows](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/docs/examples/api/windows/) directory. Another example is in the [tabs_api.html](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/docs/examples/api/tabs/inspector/tabs_api.html) file of the [inspector](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/docs/examples/api/tabs/inspector/) example. For other examples and for help in viewing the source code, see [Samples](samples).
## Summary | Types | |---| | [WindowType](#type-WindowType) | | [WindowState](#type-WindowState) | | [Window](#type-Window) | | [CreateType](#type-CreateType) | | Properties | | [WINDOW_ID_NONE](#property-WINDOW_ID_NONE) | | [WINDOW_ID_CURRENT](#property-WINDOW_ID_CURRENT) | | Methods | | [get](#method-get) − `whale.windows.get(integer windowId, object getInfo, function callback)` | | [getCurrent](#method-getCurrent) − `whale.windows.getCurrent(object getInfo, function callback)` | | [getLastFocused](#method-getLastFocused) − `whale.windows.getLastFocused(object getInfo, function callback)` | | [getAll](#method-getAll) − `whale.windows.getAll(object getInfo, function callback)` | | [create](#method-create) − `whale.windows.create(object createData, function callback)` | | [update](#method-update) − `whale.windows.update(integer windowId, object updateInfo, function callback)` | | [remove](#method-remove) − `whale.windows.remove(integer windowId, function callback)` | | Events | | [onCreated](#event-onCreated) | | [onRemoved](#event-onRemoved) | | [onFocusChanged](#event-onFocusChanged) |
## Types
### WindowType
The type of browser window this is. Under some circumstances a Window may not be assigned type property, for example when querying closed windows from the [sessions](/extensions/sessions) API.
| Enum | |---| | `"normal"`, `"popup"`, `"panel"`, `"app"`, or `"devtools"` |
### WindowState
The state of this browser window. Under some circumstances a Window may not be assigned state property, for example when querying closed windows from the [sessions](/extensions/sessions) API.
| Enum | |---| |
`"normal"`
Normal window state (i.e. not minimized, maximized, or fullscreen).
`"minimized"`
Minimized window state.
`"maximized"`
Maximized window state.
`"fullscreen"`
Fullscreen window state.
`"docked"`
_Deprecated since Chrome M59._ Docked windows are no longer supported. This state will be converted to "normal".
|
### Window | properties | |---| | integer | (optional) id | The ID of the window. Window IDs are unique within a browser session. Under some circumstances a Window may not be assigned an ID, for example when querying windows using the [sessions](/extensions/sessions) API, in which case a session ID may be present. | | boolean | focused | Whether the window is currently the focused window. | | integer | (optional) top | The offset of the window from the top edge of the screen in pixels. Under some circumstances a Window may not be assigned top property, for example when querying closed windows from the [sessions](/extensions/sessions) API. | | integer | (optional) left | The offset of the window from the left edge of the screen in pixels. Under some circumstances a Window may not be assigned left property, for example when querying closed windows from the [sessions](/extensions/sessions) API. | | integer | (optional) width | The width of the window, including the frame, in pixels. Under some circumstances a Window may not be assigned width property, for example when querying closed windows from the [sessions](/extensions/sessions) API. | | integer | (optional) height | The height of the window, including the frame, in pixels. Under some circumstances a Window may not be assigned height property, for example when querying closed windows from the [sessions](/extensions/sessions) API. | | array of [tabs.Tab](/extensions/tabs#type-Tab) | (optional) tabs | Array of [tabs.Tab](/extensions/tabs#type-Tab) objects representing the current tabs in the window. | | boolean | incognito | Whether the window is incognito. | | [WindowType](/extensions/windows#type-WindowType) | (optional) type | The type of browser window this is. | | [WindowState](/extensions/windows#type-WindowState) | (optional) state | The state of this browser window. | | boolean | alwaysOnTop | Whether the window is set to be always on top. | | string | (optional) sessionId | Since Chrome 31. The session ID used to uniquely identify a Window obtained from the [sessions](/extensions/sessions) API. |
### CreateType
Specifies what type of browser window to create. 'panel' is deprecated and only available to existing whitelisted extensions on Chrome OS.
| Enum | |---| | `"normal"`, `"popup"`, or `"panel"` |
## Properties | `-1` | `whale.windows.WINDOW_ID_NONE` | The windowId value that represents the absence of a chrome browser window. | |---|---|---| | `-2` | `whale.windows.WINDOW_ID_CURRENT` | The windowId value that represents the [current window](windows#current-window). | ## Methods
### get
`whale.windows.get(integer windowId, object getInfo, function callback)`
Gets details about a window. | Parameters | |---| | integer | windowId | | | object | (optional) getInfo | | boolean | (optional) populate | |---|---| If true, the [windows.Window](/extensions/windows#type-Window) object will have a tabs property that contains a list of the [tabs.Tab](/extensions/tabs#type-Tab) objects. The `Tab` objects only contain the `url`, `title` and `favIconUrl` properties if the extension's manifest file includes the `"tabs"` permission. | | array of [WindowType](/extensions/windows#type-WindowType) | (optional) windowTypes | Since Chrome 46. If set, the [windows.Window](/extensions/windows#type-Window) returned will be filtered based on its type. If unset the default filter is set to `['app', 'normal', 'panel', 'popup']`, with `'app'` and `'panel'` window types limited to the extension's own windows. | | | function | callback | The _callback_ parameter should be a function that looks like this: `function( [Window](/extensions/windows#type-Window) window) {...};` | [Window](/extensions/windows#type-Window) | window | | |---|---|---| |
### getCurrent
`whale.windows.getCurrent(object getInfo, function callback)`
Gets the [current window](#current-window). | Parameters | |---| | object | (optional) getInfo | | boolean | (optional) populate | |---|---| If true, the [windows.Window](/extensions/windows#type-Window) object will have a tabs property that contains a list of the [tabs.Tab](/extensions/tabs#type-Tab) objects. The `Tab` objects only contain the `url`, `title` and `favIconUrl` properties if the extension's manifest file includes the `"tabs"` permission. | | array of [WindowType](/extensions/windows#type-WindowType) | (optional) windowTypes | Since Chrome 46. If set, the [windows.Window](/extensions/windows#type-Window) returned will be filtered based on its type. If unset the default filter is set to `['app', 'normal', 'panel', 'popup']`, with `'app'` and `'panel'` window types limited to the extension's own windows. | | | function | callback | The _callback_ parameter should be a function that looks like this: `function( [Window](/extensions/windows#type-Window) window) {...};` | [Window](/extensions/windows#type-Window) | window | | |---|---|---| |
### getLastFocused
`whale.windows.getLastFocused(object getInfo, function callback)`
Gets the window that was most recently focused — typically the window 'on top'. | Parameters | |---| | object | (optional) getInfo | | boolean | (optional) populate | |---|---| If true, the [windows.Window](/extensions/windows#type-Window) object will have a tabs property that contains a list of the [tabs.Tab](/extensions/tabs#type-Tab) objects. The `Tab` objects only contain the `url`, `title` and `favIconUrl` properties if the extension's manifest file includes the `"tabs"` permission. | | array of [WindowType](/extensions/windows#type-WindowType) | (optional) windowTypes | Since Chrome 46. If set, the [windows.Window](/extensions/windows#type-Window) returned will be filtered based on its type. If unset the default filter is set to `['app', 'normal', 'panel', 'popup']`, with `'app'` and `'panel'` window types limited to the extension's own windows. | | | function | callback | The _callback_ parameter should be a function that looks like this: `function( [Window](/extensions/windows#type-Window) window) {...};` | [Window](/extensions/windows#type-Window) | window | | |---|---|---| |
### getAll
`whale.windows.getAll(object getInfo, function callback)`
Gets all windows. | Parameters | |---| | object | (optional) getInfo | | boolean | (optional) populate | |---|---| If true, each [windows.Window](/extensions/windows#type-Window) object will have a tabs property that contains a list of the [tabs.Tab](/extensions/tabs#type-Tab) objects for that window. The `Tab` objects only contain the `url`, `title` and `favIconUrl` properties if the extension's manifest file includes the `"tabs"` permission. | | array of [WindowType](/extensions/windows#type-WindowType) | (optional) windowTypes | Since Chrome 46. If set, the [windows.Window](/extensions/windows#type-Window) returned will be filtered based on its type. If unset the default filter is set to `['app', 'normal', 'panel', 'popup']`, with `'app'` and `'panel'` window types limited to the extension's own windows. | | | function | callback | The _callback_ parameter should be a function that looks like this: `function(array of [Window](/extensions/windows#type-Window) windows) {...};` | array of [Window](/extensions/windows#type-Window) | windows | | |---|---|---| |
### create
`whale.windows.create(object createData, function callback)`
Creates (opens) a new browser with any optional sizing, position or default URL provided. | Parameters | |---| | object | (optional) createData | | string or array of string | (optional) url | |---|---| A URL or array 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. | | integer | (optional) tabId | The id of the tab for which you want to adopt to the new window. | | integer | (optional) left | 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. | | integer | (optional) top | 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. | | integer | (optional) width | The width in pixels of the new window, including the frame. If not specified defaults to a natural width. | | integer | (optional) height | The height in pixels of the new window, including the frame. If not specified defaults to a natural height. | | boolean | (optional) focused | If true, opens an active window. If false, opens an inactive window. | | boolean | (optional) incognito | Whether the new window should be an incognito window. | | [CreateType](/extensions/windows#type-CreateType) | (optional) type | Specifies what type of browser window to create. | | [WindowState](/extensions/windows#type-WindowState) | (optional) state | Since Chrome 44. The initial state of the window. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'. | | | function | (optional) callback | If you specify the _callback_ parameter, it should be a function that looks like this: `function( [Window](/extensions/windows#type-Window) window) {...};` | [Window](/extensions/windows#type-Window) | (optional) window | |---|---| Contains details about the created window. | |
### update
`whale.windows.update(integer windowId, object updateInfo, function callback)`
Updates the properties of a window. Specify only the properties that you want to change; unspecified properties will be left unchanged. | Parameters | |---| | integer | windowId | | | object | updateInfo | | integer | (optional) left | |---|---| The offset from the left edge of the screen to move the window to in pixels. This value is ignored for panels. | | integer | (optional) top | The offset from the top edge of the screen to move the window to in pixels. This value is ignored for panels. | | integer | (optional) width | The width to resize the window to in pixels. This value is ignored for panels. | | integer | (optional) height | The height to resize the window to in pixels. This value is ignored for panels. | | boolean | (optional) focused | If true, brings the window to the front. If false, brings the next window in the z-order to the front. | | boolean | (optional) drawAttention | If true, 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 to false to cancel a previous draw attention request. | | [WindowState](/extensions/windows#type-WindowState) | (optional) state | The new state of the window. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'. | | | function | (optional) callback | If you specify the _callback_ parameter, it should be a function that looks like this: `function( [Window](/extensions/windows#type-Window) window) {...};` | [Window](/extensions/windows#type-Window) | window | | |---|---|---| |
### remove
`whale.windows.remove(integer windowId, function callback)`
Removes (closes) a window, and all the tabs inside it. | Parameters | |---| | integer | windowId | | | function | (optional) callback | If you specify the _callback_ parameter, it should be a function that looks like this: `function() {...};` |
## Events
### onCreated
Fired when a window is created. #### Filters
array of [WindowType](/extensions/windows#type-WindowType) windowTypes Conditions that the window's type being created must satisfy. By default it will satisfy `['app', 'normal', 'panel', 'popup']`, with `'app'` and `'panel'` window types limited to the extension's own windows.
#### addListener
`whale.windows.onCreated.addListener(function callback)`
| Parameters | |---| | function | callback | The _callback_ parameter should be a function that looks like this: `function( [Window](/extensions/windows#type-Window) window) {...};` | [Window](/extensions/windows#type-Window) | window | |---|---| Details of the window that was created. | |
### onRemoved
Fired when a window is removed (closed). #### Filters
array of [WindowType](/extensions/windows#type-WindowType) windowTypes Conditions that the window's type being removed must satisfy. By default it will satisfy `['app', 'normal', 'panel', 'popup']`, with `'app'` and `'panel'` window types limited to the extension's own windows.
#### addListener
`whale.windows.onRemoved.addListener(function callback)`
| Parameters | |---| | function | callback | The _callback_ parameter should be a function that looks like this: `function(integer windowId) {...};` | integer | windowId | |---|---| ID of the removed window. | |
### onFocusChanged
Fired when the currently focused window changes. Will be whale.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. #### Filters
array of [WindowType](/extensions/windows#type-WindowType) windowTypes Conditions that the window's type being removed must satisfy. By default it will satisfy `['app', 'normal', 'panel', 'popup']`, with `'app'` and `'panel'` window types limited to the extension's own windows.
#### addListener
`whale.windows.onFocusChanged.addListener(function callback)`
| Parameters | |---| | function | callback | The _callback_ parameter should be a function that looks like this: `function(integer windowId) {...};` | integer | windowId | |---|---| ID of the newly focused window. | |

results matching ""

    No results matching ""