Tab class represents a single tab within Flow Browser. It encapsulates an Electron WebContentsView, manages state (URL, title, loading status, audio), handles layout, and coordinates lifecycle events like sleep/wake.
Overview
Each Tab instance:- Manages a
WebContentsViewandWebContentsfor rendering web pages - Tracks state: URL, title, loading, audio, favicon, visibility
- Supports different layouts (normal, glance, split)
- Handles lifecycle: creation, sleep/wake, and destruction
- Emits events for focus changes, updates, and destruction
Creating a Tab
Tabs are created through theTabsController:
TabCreationDetails
Required details passed to the Tab constructor:The TabsController instance managing this tab
ID of the user profile associated with this tab
ID of the space this tab belongs to
Electron Session object for this tab’s web content
The loaded profile instance
TabCreationOptions
Optional configuration for tab creation:The window to attach the tab to
Custom unique ID (auto-generated if not provided)
Electron WebContentsView customization options
Initial URL to load
Whether to create the tab in sleep mode (no WebContents, saves memory)
Tab position in the tab strip
Restored title (for sleeping tabs)
Restored favicon URL
Navigation history to restore
Active index in navigation history
Properties
Identity & Organization
Unique tab ID (stable across sleep/wake cycles)
Persistent unique identifier
Associated profile ID (readonly)
Associated space ID (can be changed with
setSpace())ID of the tab group this tab belongs to (if any)
State Properties
Whether the tab’s view is currently visible
Whether the tab has been destroyed
Whether the tab is in sleep mode (no WebContents to save memory)
Whether the tab is in fullscreen mode
Whether the tab has an active picture-in-picture window
Tab position in the tab strip
Timestamp when tab was last active
Content Properties
Current page title (default: “New Tab”)
Current page URL
Whether the page is currently loading
URL of the current favicon
Whether the tab is playing audio
Whether the tab’s audio is muted
Navigation history entries
Current index in navigation history
View Objects
The Electron WebContentsView instance (null when tab is asleep)
The Electron WebContents instance (null when tab is asleep)
Methods
Navigation
Loads a URL in the tabParameters:
url: URL to loadreplace: If true, replaces current history entry instead of creating new one
Loads a custom error page for the given error code and URL
Window & Space Management
Attaches the tab’s view to a window or moves it to a different windowParameters:
window: Target windowindex: View layer index (default: ViewLayer.TAB)
Returns the current window for the tab
Changes the space assignment for the tab
Visibility
Makes the tab’s view visible
Hides the tab’s view
State Updates
Reads current state from webContents and emits ‘updated’ event if anything changedReturns true if state changed, false otherwise.
Schedules an updateTabState() call via queueMicrotask. Multiple calls are coalesced.
Updates a single state property with change detection and emits ‘updated’ event
View Lifecycle
Creates the WebContentsView, sets up listeners, and registers with extensions. Called on wake from sleep.
Destroys the WebContentsView and frees resources. Called when putting tab to sleep.
Restores navigation history on the current webContents
Applies the correct background color based on the current URL (transparent for internal protocols)
Destruction
Destroys the tab and cleans up resources. Emits ‘destroyed’ event.
Events
The Tab class extendsTypedEventEmitter and emits:
Emitted when the tab’s webContents gains focus
Emitted when tab state changes (title, URL, loading status, favicon, visibility, etc.)
Emitted when the tab is destroyed
Emitted when the tab’s space assignment changes
Emitted when the tab moves to a different window
Emitted when fullscreen state changes
new-tab-requested
[url: string, disposition: string, options?: WebContentsViewConstructorOptions, details?: HandlerDetails]
Emitted when the page requests opening a new tab (e.g., target=“_blank” links)
Sleep Mode
Tabs can be put to sleep to save memory (~20-50MB per sleeping tab):tab.viewandtab.webContentsarenull- Visual state (title, URL, favicon) is preserved
- Navigation history is stored
Example: Managing Tab State
Related
Browser
Learn about browser controllers
Window
Learn about BrowserWindow