Browser.sessions.restore() not completely restoring browser session

My Firefox add-on, Panic Button, has the ability to close all browser windows when the browser action is triggered from a toolbar button or keyboard shortcut, as well as restoring them when the browser action is triggered again afterwards. I’m using the browser.sessions.restore() API to restore the user’s session.

This is working without issues on Firefox 68 ESR, but I’ve noticed that on Firefox 71, browser.sessions.restore() is not restoring all the browser windows, if there was more than 1 open before they were closed by the browser action.

I’ve added some console.log() statements to try to debug this:

browser.sessions.getRecentlyClosed().then(aSessions => {
   // Check for zero-length aSessions array - omitted here for brevity.

   let restoredSessions = [];
      
    for (let i = 0; i < aSessions.length; i++) {
      let sess = aSessions[i];
      let sessID = null;
      if (sess.tab) {
        sessID = sess.tab.sessionId;
      }
      else {
        sessID = sess.window.sessionId;
      }
      console.log("Restoring session ID: " + sessID);
      restoredSessions.push(browser.sessions.restore(sessID));
    }

    Promise.all(restoredSessions).then(aResults => {
      // This doesn't get executed.
      console.log("Finished restoring browser sessions. Result:");
      console.log(aResults);
    }).catch(aErr => {
      // This doesn't get executed, either.
      console.error("Error restoring session " + sessID + ":\n" + aErr);
    }); 

Here are the permissions I have requested in the manifest.json file:
"permissions": ["history", "storage", "sessions"]

I read through the release notes for Firefox 69, 70 and 71 but couldn’t find any info about changes to the WebExtension sessions API.

Any ideas?

1 Like