chrome.sessions

Description: Use the chrome.sessions API to query and restore tabs and windows from a browsing session.
Availability: Since Chrome 37.
Permissions: "sessions"

Summary

Types
Filter
Session
Device
Properties
MAX_SESSION_RESULTS
Methods
getRecentlyClosed chrome.sessions.getRecentlyClosed( Filter filter, function callback)
getDevices chrome.sessions.getDevices( Filter filter, function callback)
restore chrome.sessions.restore(string sessionId, function callback)
Events
onChanged

Types

Filter

properties
integer (optional) maxResults

The maximum number of entries to be fetched in the requested list. Omit this parameter to fetch the maximum number of entries (sessions.MAX_SESSION_RESULTS).

Session

properties
integer lastModified

The time when the window or tab was closed or modified, represented in milliseconds since the epoch.

tabs.Tab (optional) tab

The tabs.Tab, if this entry describes a tab. Either this or sessions.Session.window will be set.

windows.Window (optional) window

The windows.Window, if this entry describes a window. Either this or sessions.Session.tab will be set.

Device

properties
string deviceName

The name of the foreign device.

array of Session sessions

A list of open window sessions for the foreign device, sorted from most recently to least recently modified session.

Properties

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

Methods

getRecentlyClosed

chrome.sessions.getRecentlyClosed( Filter filter, function callback)

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

Parameters
Filter (optional) filter
function callback

The callback parameter should be a function that looks like this:

function(array of Session sessions) {...};
array of Session sessions

The list of closed entries in reverse order that they were closed (the most recently closed tab or window will be at index 0). The entries may contain either tabs or windows.

getDevices

chrome.sessions.getDevices( Filter filter, function callback)

Retrieves all devices with synced sessions.

Parameters
Filter (optional) filter
function callback

The callback parameter should be a function that looks like this:

function(array of Device devices) {...};
array of Device devices

The list of sessions.Device objects for each synced session, sorted in order from device with most recently modified session to device with least recently modified session. tabs.Tab objects are sorted by recency in the windows.Window of the sessions.Session objects.

restore

chrome.sessions.restore(string sessionId, function callback)

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

Parameters
string (optional) sessionId

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

function (optional) callback

If you specify the callback parameter, it should be a function that looks like this:

function( Session restoredSession) {...};
Session restoredSession

A sessions.Session containing the restored windows.Window or tabs.Tab object.

Events

onChanged

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

addListener

chrome.sessions.onChanged.addListener(function callback)
Parameters
function callback

The callback parameter should be a function that looks like this:

function() {...};