Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/windows/update/index.md
6556 views
---
title: windows.update() slug: Mozilla/Add-ons/WebExtensions/API/windows/update page-type: webextension-api-function tags: - API - Add-ons - Extensions - Method - Non-standard - Reference - Update - WebExtensions - Windows browser-compat: webextensions.api.windows.update
---

{{AddonSidebar()}}

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

let 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 {{optional_inline}}

        • : boolean. 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 drawAttention request.

      • focused {{optional_inline}}

        • : boolean. If true, brings the window to the front. If false, brings the next window in the z-order to the front.

      • height {{optional_inline}}

        • : integer. The height to resize the window to in pixels. This value is ignored for panels.

      • left {{optional_inline}}

        • : integer. The offset from the left edge of the screen to move the window to in pixels. This value is ignored for panels.

      • state {{optional_inline}}

        • : {{WebExtAPIRef('windows.WindowState')}}. The new state of the window. The minimized, maximized and fullscreen states cannot be combined with left, top, width or height.

      • titlePreface {{optional_inline}}

        • : string. 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 {{optional_inline}}

        • : integer. The offset from the top edge of the screen to move the window to in pixels. This value is ignored for panels.

      • width {{optional_inline}}

        • : integer. 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 {{WebExtAPIRef('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

{{Compat}}

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) => { let updating = browser.windows.update(tab.windowId, { left: 0, top: 0 }); updating.then(onUpdated, onError); });

{{WebExtExamples}}

Note: This API is based on Chromium's chrome.windows API. This documentation is derived from windows.json in the Chromium code.