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() {
let gettingSessions = browser.sessions.getRecentlyClosed({
maxResults: 1
});
gettingSessions.then(restoreMostRecent, onError);
});
Note: 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.