Movatterモバイル変換


[0]ホーム

URL:


  1. Mozilla
  2. Add-ons
  3. Browser extensions
  4. JavaScript APIs
  5. sessions
  6. sessions.restore()

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 aPromise.

Syntax

js
let 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 thesessionId property of theTab orWindow object in theSession returned fromsessions.getRecentlyClosed().

Return value

APromise. This will be fulfilled with aSession object representing the session that was restored.

Examples

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

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

Browser compatibility

Note:This API is based on Chromium'schrome.sessions API.

Known issues

Bug 1538119 - Duplicate sessionId in browser.sessions.getRecentlyClosed() after "Restore previous session"

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp