windows.update()
Updates the properties of a window. Use this to move, resize, and (un)focus a window, etc.
This is an asynchronous function that returns a Promise
.
Syntax
var updating = browser.windows.update(
windowId, // integer
updateInfo // object
)
Parameters
windowId
integer
. ID of the window to update.updateInfo
object
. Object containing the properties to update.-
drawAttention
Optionalboolean
. 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 tofalse
to cancel a previousdrawAttention
request.focused
Optionalboolean
. Iftrue
, brings the window to the front. If false, brings the next window in the z-order to the front.height
Optionalinteger
. The height to resize the window to in pixels. This value is ignored for panels.left
Optionalinteger
. The offset from the left edge of the screen to move the window to in pixels. This value is ignored for panels.state
Optionalwindows.WindowState
. The new state of the window. Theminimized
,maximized
andfullscreen
states cannot be combined withleft
,top
,width
orheight
.titlePreface
Optionalstring
. Use this to add a string to the beginning of the browser window's title. Depending on the underlying operating system, this might not work on browser windows that don't have a title (such as about:blank in Firefox).top
Optionalinteger
. The offset from the top edge of the screen to move the window to in pixels. This value is ignored for panels.width
Optionalinteger
. The width to resize the window to in pixels. This value is ignored for panels.
Return value
A Promise
that will be fulfilled with a windows.Window
object containing the details of the updated window. If any error occurs, the promise will be rejected with an error message.
Browser compatibility
Report problems with this compatibility data on GitHubwebextensions-desktop | webextensions-mobile | |||||
---|---|---|---|---|---|---|
update | ChromeFull supportYes | EdgeFull support14 | FirefoxFull support45 | OperaFull supportYes | SafariFull support14 | Firefox for AndroidNo supportNo |
drawAttention | ChromeFull supportYes | EdgeFull support79 | FirefoxFull support45 | OperaFull supportYes | SafariNo supportNo | Firefox for AndroidNo supportNo |
focused | ChromeFull supportYes | EdgeFull support14 | FirefoxFull support45 | OperaFull supportYes | SafariFull support14 | Firefox for AndroidNo supportNo |
height | ChromeFull supportYes | EdgeFull support14 | FirefoxFull support45 | OperaFull supportYes | SafariFull support14 | Firefox for AndroidNo supportNo |
left | ChromeFull supportYes | EdgeFull support79 | FirefoxFull support45 | OperaFull supportYes | SafariFull support14 | Firefox for AndroidNo supportNo |
state | ChromeFull supportYes | EdgeFull support14 | FirefoxFull support45 | OperaFull supportYes | SafariFull support14 | Firefox for AndroidNo supportNo |
titlePreface | ChromeNo supportNo | EdgeNo supportNo | FirefoxFull support56 | OperaNo supportNo | SafariNo supportNo | Firefox for AndroidNo supportNo |
top | ChromeFull supportYes | EdgeFull support79 | FirefoxFull support45 | OperaFull supportYes | SafariFull support14 | Firefox for AndroidNo supportNo |
width | ChromeFull supportYes | EdgeFull support14 | FirefoxFull support45 | OperaFull supportYes | SafariFull support14 | Firefox for AndroidNo supportNo |
Legend
- Full support
- Full support
- No support
- No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Examples
When the user clicks a browser action's icon, move the window to the top left corner:
function onUpdated(windowInfo) {
console.log(`Updated window: ${windowInfo.id}`);
}
function onError(error) {
console.log(`Error: ${error}`);
}
browser.browserAction.onClicked.addListener((tab) => {
var updating = browser.windows.update(tab.windowId, {
left: 0,
top: 0
});
updating.then(onUpdated, onError);
});
Example extensions
Acknowledgements
This API is based on Chromium's chrome.windows
API. This documentation is derived from windows.json
in the Chromium code.
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.