Dart Documentationchrome.sessionsChromeSessions

ChromeSessions class

class ChromeSessions extends ChromeApi {
 static final JsObject _sessions = chrome['sessions'];

 ChromeSessions._();

 bool get available => _sessions != null;

 /**
  * The maximum number of [Session] that will be included in a requested list.
  */
 int get MAX_SESSION_RESULTS => _sessions['MAX_SESSION_RESULTS'];

 /**
  * Gets the list of recently closed tabs and/or windows.
  * 
  * Returns:
  * 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.
  */
 Future<List<Session>> getRecentlyClosed([Filter filter]) {
   if (_sessions == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<Session>>.oneArg((e) => listify(e, _createSession));
   _sessions.callMethod('getRecentlyClosed', [jsify(filter), completer.callback]);
   return completer.future;
 }

 /**
  * Retrieves all devices with synced sessions.
  * 
  * Returns:
  * The list of [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 [Session] objects.
  */
 Future<List<Device>> getDevices([Filter filter]) {
   if (_sessions == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<Device>>.oneArg((e) => listify(e, _createDevice));
   _sessions.callMethod('getDevices', [jsify(filter), completer.callback]);
   return completer.future;
 }

 /**
  * Reopens a [windows.Window] or [tabs.Tab], with an optional callback to run
  * when the entry has been restored.
  * 
  * [sessionId] The [windows.Window.sessionId], or [tabs.Tab.sessionId] to
  * restore.
  * 
  * Returns:
  * A [Session] containing the restored [windows.Window] or [tabs.Tab] object.
  */
 Future<Session> restore([String sessionId]) {
   if (_sessions == null) _throwNotAvailable();

   var completer = new ChromeCompleter<Session>.oneArg(_createSession);
   _sessions.callMethod('restore', [sessionId, completer.callback]);
   return completer.future;
 }

 void _throwNotAvailable() {
   throw new UnsupportedError("'chrome.sessions' is not available");
 }
}

Extends

ChromeApi > ChromeSessions

Properties

final bool available #

Returns true if the API is available. The common causes of an API not being avilable are:

  • a permission is missing in the application's manifest.json file
  • the API is defined on a newer version of Chrome then the current runtime
docs inherited from ChromeApi
bool get available => _sessions != null;

final int MAX_SESSION_RESULTS #

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

int get MAX_SESSION_RESULTS => _sessions['MAX_SESSION_RESULTS'];

Methods

Future<List<Device>> getDevices([Filter filter]) #

Retrieves all devices with synced sessions.

Returns: The list of 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 Session objects.

Future<List<Device>> getDevices([Filter filter]) {
 if (_sessions == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<Device>>.oneArg((e) => listify(e, _createDevice));
 _sessions.callMethod('getDevices', [jsify(filter), completer.callback]);
 return completer.future;
}

Future<List<Session>> getRecentlyClosed([Filter filter]) #

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

Returns: 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.

Future<List<Session>> getRecentlyClosed([Filter filter]) {
 if (_sessions == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<Session>>.oneArg((e) => listify(e, _createSession));
 _sessions.callMethod('getRecentlyClosed', [jsify(filter), completer.callback]);
 return completer.future;
}

Future<Session> restore([String sessionId]) #

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

sessionId The windows.Window.sessionId, or tabs.Tab.sessionId to restore.

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

Future<Session> restore([String sessionId]) {
 if (_sessions == null) _throwNotAvailable();

 var completer = new ChromeCompleter<Session>.oneArg(_createSession);
 _sessions.callMethod('restore', [sessionId, completer.callback]);
 return completer.future;
}