Chrome Extension Window Management — Developer Guide
3 min readWindow Management in Chrome Extensions
Introduction
chrome.windowsAPI for creating, managing, and monitoring browser windows- No special permission required for basic window operations
- Use with
chrome.tabsfor full window/tab management
Key APIs
chrome.windows.create()
// Normal browser window
const win = await chrome.windows.create({ url: "https://example.com", type: "normal" });
// Popup window (no tabs, bookmarks bar, etc.)
const popup = await chrome.windows.create({
url: "popup-window.html",
type: "popup",
width: 400, height: 600,
left: 100, top: 100
});
// Incognito window
const incog = await chrome.windows.create({ url: "https://example.com", incognito: true });
Window Types
"normal"— standard browser window with all chrome UI"popup"— minimal window, no tabs/address bar — great for extension UIs"panel"— deprecated, use popup instead
chrome.windows.get/getAll/getCurrent/getLastFocused
const current = await chrome.windows.getCurrent({ populate: true }); // includes tabs
const all = await chrome.windows.getAll({ populate: true });
const focused = await chrome.windows.getLastFocused();
populate: trueincludes tab array in the result
chrome.windows.update()
await chrome.windows.update(windowId, {
left: 0, top: 0, width: 800, height: 600, // Position and size
focused: true, // Bring to front
state: "normal" // "normal", "minimized", "maximized", "fullscreen"
});
chrome.windows.remove()
await chrome.windows.remove(windowId); // Closes all tabs in the window
Window Events
chrome.windows.onCreated.addListener((window) => { /* new window */ });
chrome.windows.onRemoved.addListener((windowId) => { /* window closed */ });
chrome.windows.onFocusChanged.addListener((windowId) => {
if (windowId === chrome.windows.WINDOW_ID_NONE) {
console.log("No Chrome window focused");
}
});
Common Patterns
Floating Tool Window
- Create a
"popup"type window for extension UI that persists alongside browsing - Position relative to main window
- Store position with
@theluckystrike/webext-storage
Multi-Window Session Manager
- Save all windows and their tabs:
getAll({ populate: true }) - Restore by creating windows with
create({ url: [...] }) - Store sessions with
@theluckystrike/webext-storage
Picture-in-Picture Style UI
- Small
"popup"window always on top (usefocused: trueon focus loss) - Fixed small size for video/chat overlay
Incognito Awareness
- Check
window.incognitobefore performing actions - Extension must declare
"incognito": "spanning"or"split"in manifest @theluckystrike/webext-storagelocal storage is shared, sync storage is separate per profile
Window-Tab Relationship
- Every tab belongs to a window (
tab.windowId) chrome.tabs.move(tabId, { windowId })moves tabs between windows- Closing last tab in a window closes the window
Common Mistakes
- Not handling
WINDOW_ID_NONEinonFocusChanged— fires when no Chrome window is focused - Assuming window position is valid on multi-monitor — check
screendimensions - Creating too many popup windows — confuses users
- Not requesting
"tabs"permission when you need tab URLs inpopulate: trueresults
Related Articles
Related Articles
Part of the Chrome Extension Guide by theluckystrike. Built at zovo.one.