Documentation: Chrome Windows API
A promise-based wrapper for the Chrome windows API to create, query, update, and manage browser windows.
- isAvailableWindows()
- createWindow(createData?)
- getWindow(windowId, queryOptions?)
- getAllWindows(queryOptions?)
- getCurrentWindow(queryOptions?)
- getLastFocusedWindow(queryOptions?)
- removeWindow(windowId)
- updateWindow(windowId, updateInfo)
- onWindowBoundsChanged(callback)
- onWindowCreated(callback, filter?)
- onWindowFocusChanged(callback, filter?)
- onWindowRemoved(callback, filter?)
isAvailableWindows(method?: ApiMethodName<typeof chrome.windows>): booleanThe optional method is a native function name, for example isAvailableWindows("getAll").
Import the public ApiMethodName type from @addon-core/browser for your own typed helpers.
This checks callable presence without invoking the method; permissions and argument support still require handling.
Returns true when the windows namespace is present on the API selected by browser() in the current context.
Returns false if the namespace or WebExtension environment is absent, or if accessing it throws.
The check is synchronous, does not log, and reads the current API on every call without caching.
Without an argument, it checks namespace presence only. Pass a native method name to also check that it is callable.
Neither form verifies permissions, argument support, or a successful operation. See method availability.
import {isAvailableWindows} from "@addon-core/browser";
if (isAvailableWindows()) {
// The namespace is present; handle operation-specific failures when using it.
}createWindow(createData?: chrome.windows.CreateData): Promise<chrome.windows.Window | undefined>
Creates a new browser window with the specified options. Resolves with the created Window or undefined.
getWindow(windowId: number, queryOptions?: chrome.windows.QueryOptions): Promise<chrome.windows.Window>
Retrieves details for the window with the given ID.
getAllWindows(queryOptions?: chrome.windows.QueryOptions): Promise<chrome.windows.Window[]>
Retrieves all windows, optionally filtered by the provided query options.
getCurrentWindow(queryOptions?: chrome.windows.QueryOptions): Promise<chrome.windows.Window>
Gets the current window (the window that contains the code calling this method).
getLastFocusedWindow(queryOptions?: chrome.windows.QueryOptions): Promise<chrome.windows.Window>
Gets the most recently focused window.
removeWindow(windowId: number): Promise<void>
Removes (closes) the window with the given ID.
updateWindow(windowId: number, updateInfo: chrome.windows.UpdateInfo): Promise<chrome.windows.Window>
Updates the properties of the specified window and resolves with the updated Window.
onWindowBoundsChanged(
callback: (windowId: number) => void
): () => void
Adds a listener that fires when the window's bounds (size or position) change. Returns an unsubscribe function.
onWindowCreated(
callback: (window: chrome.windows.Window) => void,
filter?: { windowTypes: chrome.windows.WindowType[] } // WindowEventFilter
): () => void
Adds a listener that fires when a new window is created. Optionally filter by window types. Returns an unsubscribe function.
onWindowFocusChanged(
callback: (windowId: number) => void,
filter?: { windowTypes: chrome.windows.WindowType[] } // WindowEventFilter
): () => void
Adds a listener that fires when the focused window changes. Optionally filter by window types. Returns an unsubscribe function.
onWindowRemoved(
callback: (windowId: number) => void,
filter?: { windowTypes: chrome.windows.WindowType[] } // WindowEventFilter
): () => void
Adds a listener that fires when a window is removed (closed). Optionally filter by window types. Returns an unsubscribe function.