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.

Two windows, each with one tab

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.