Use the browser.sessions API to query and restore tabs and windows from a browsing session.

Permissions: sessions

Not allowed in: Content scripts, Devtools pages

Device
Filter
Session
MAX_SESSION_RESULTS
onChanged
forgetClosedTab
forgetClosedWindow
getDevices
getRecentlyClosed
getTabValue
getWindowValue
removeTabValue
removeWindowValue
restore
setTabValue
setWindowValue
MAX_SESSION_RESULTS: number

The maximum number of sessions.Session that will be included in a requested list.

onChanged: WebExtEvent<() => void>

Fired when recently closed tabs and/or windows are changed. This event does not monitor synced sessions changes.

  • Forget a recently closed tab.

    Parameters

    • windowId: number

      The windowId of the window to which the recently closed tab to be forgotten belongs.

    • sessionId: string

      The sessionId (closedId) of the recently closed tab to be forgotten.

    Returns Promise<void>

  • Forget a recently closed window.

    Parameters

    • sessionId: string

      The sessionId (closedId) of the recently closed window to be forgotten.

    Returns Promise<void>

  • Retrieves all devices with synced sessions.

    Parameters

    Returns Promise<Device[]>

    Unsupported on Firefox at this time.

  • Gets the list of recently closed tabs and/or windows.

    Parameters

    Returns Promise<Session[]>

  • Retrieve a value that was set for a given key on a given tab.

    Parameters

    • tabId: number

      The id of the tab whose value is being retrieved from.

    • key: string

      The key which corresponds to the value.

    Returns Promise<string | object>

  • Retrieve a value that was set for a given key on a given window.

    Parameters

    • windowId: number

      The id of the window whose value is being retrieved from.

    • key: string

      The key which corresponds to the value.

    Returns Promise<string | object>

  • Remove a key/value pair that was set on a given tab.

    Parameters

    • tabId: number

      The id of the tab whose key/value pair is being removed.

    • key: string

      The key which corresponds to the value.

    Returns Promise<void>

  • Remove a key/value pair that was set on a given window.

    Parameters

    • windowId: number

      The id of the window whose key/value pair is being removed.

    • key: string

      The key which corresponds to the value.

    Returns Promise<void>

  • Reopens a windows.Window or tabs.Tab, with an optional callback to run when the entry has been restored.

    Parameters

    • OptionalsessionId: string

      The windows.Window.sessionId, or tabs.Tab.sessionId to restore. If this parameter is not specified, the most recently closed session is restored.

    Returns Promise<Session>

  • Set a key/value pair on a given tab.

    Parameters

    • tabId: number

      The id of the tab that the key/value pair is being set on.

    • key: string

      The key which corresponds to the value being set.

    • value: any

      The value being set.

    Returns Promise<void>

  • Set a key/value pair on a given window.

    Parameters

    • windowId: number

      The id of the window that the key/value pair is being set on.

    • key: string

      The key which corresponds to the value being set.

    • value: any

      The value being set.

    Returns Promise<void>