sessions

The sessions API allows an extension to query and restore tabs and windows from a user's browsing session.

What it does

  • Query: Get a list of recently closed tabs and windows.
  • Restore: Reopen a recently closed tab or an entire window.
  • Monitor: Listen for changes to the list of recently closed tabs.
  • Can be used in conjunction with device info APIs to access sessions from other devices the user is logged into.

When to use it

This permission is ideal for tab managers or extensions that help users recover from accidentally closing tabs.

Examples:

  • A "session manager" that can save and restore entire sets of windows and tabs.
  • An enhanced "recently closed" menu that provides more context or search functionality.
  • An extension that helps migrate open tabs from one device to another.

Manifest Declaration

{
  "name": "My Session Manager",
  "version": "1.0",
  "manifest_version": 3,
  "permissions": [
    "sessions",
    "tabs"
  ]
}

Note: The tabs permission is often needed alongside sessions to do anything useful.

Security & Privacy

Why is it risky?

This permission lets an extension see the tabs and windows you have recently closed. This includes the titles and web addresses of those pages, which can reveal parts of your browsing history.

A malicious extension could use this information to learn about your browsing habits. While it can't see what you did on those pages, the list of closed tabs can still be sensitive. Legitimate session manager extensions use this to help you recover your tabs if you accidentally close a window.

API Usage Example

This example gets the 5 most recently closed tabs and provides a way to restore the first one.

// popup.js

async function showRecentlyClosed() {
  const recentlyClosed = await chrome.sessions.getRecentlyClosed({
    maxResults: 5
  });

  console.log("Recently closed sessions:", recentlyClosed);

  if (recentlyClosed.length > 0) {
    const firstItem = recentlyClosed[0];
    // The session item could be a single tab or a window with multiple tabs.
    const sessionId = firstItem.tab ? firstItem.tab.sessionId : firstItem.window.sessionId;

    console.log(`First item's session ID is ${sessionId}. To restore it, call chrome.sessions.restore('${sessionId}');`);

    // Example of restoring it:
    // await chrome.sessions.restore(sessionId);
  }
}

showRecentlyClosed();

Extensions with the sessions permission

Here are some popular browser extensions that use the "sessions" permission. To explore more, try our Advanced search.

Permission Metrics

Popularity

Security Risk


Usage by Platform