sessions.restore()

Restores a closed tab or window. Restoring doesn't just reopen the tab or window: it also restores the tab's navigation history so the back/forward buttons will work. Restoring a window will restore all the tabs that the window contained when it was closed.

This is an asynchronous function that returns a Promise.

Syntax

var restoringSession = browser.sessions.restore(
  sessionId             // string
)

Parameters

sessionId
string. A string containing the session ID for the window or tab to restore. This can be found in the sessionId property of the Tab or Window object in the Session returned from sessions.getRecentlyClosed().

Return value

A Promise. This will be fulfilled with a Session object representing the session that was restored.

Browser compatibility

ChromeEdgeFirefoxFirefox for AndroidOpera
Basic supportYesNo52NoYes

Examples

This restores the single most recently-closed session, whether it's a window or tab:

function restoreMostRecent(sessionInfos) {
  if (!sessionInfos.length) {
    console.log("No sessions found")
    return;
  }
  let sessionInfo = sessionInfos[0];
  if (sessionInfo.tab) {
    browser.sessions.restore(sessionInfo.tab.sessionId);
  } else {
    browser.sessions.restore(sessionInfo.window.sessionId);
  }
}
function onError(error) {
  console.log(error);
}
browser.browserAction.onClicked.addListener(function() {
  var gettingSessions = browser.sessions.getRecentlyClosed({
    maxResults: 1
  });
  gettingSessions.then(restoreMostRecent, onError);
});

Acknowledgements

This API is based on Chromium's chrome.sessions API.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

Document Tags and Contributors

 Contributors to this page: wbamberg
 Last updated by: wbamberg,