sessions.forgetClosedTab()
Removes a closed tab from the browser's list of recently closed tabs.
Note that the sites visited by that tab are not removed from the browser's history. Use the
browsingData
or history
APIs to remove history.This is an asynchronous function that returns a Promise
.
Syntax
var forgettingTab = browser.sessions.forgetClosedTab(
windowId, // integer
sessionId // string
)
Parameters
Return value
A Promise
. This will be fulfilled with no arguments when the session has been removed.
If an error occurs, the promise will be rejected with an error message.
Browser compatibility
Report problems with this compatibility data on GitHubwebextensions-desktop | webextensions-mobile | |||||
---|---|---|---|---|---|---|
forgetClosedTab | ChromeNo supportNo | EdgeNo supportNo | FirefoxFull support55 | OperaNo supportNo | SafariNo supportNo | Firefox for AndroidNo supportNo |
Legend
- Full support
- Full support
- No support
- No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Examples
This code forgets the single most recently-closed session, whether it's a tab or a window:
function forgetMostRecent(sessionInfos) {
if (!sessionInfos.length) {
console.log("No sessions found")
return;
}
let sessionInfo = sessionInfos[0];
if (sessionInfo.tab) {
browser.sessions.forgetClosedTab(sessionInfo.tab.windowId, sessionInfo.tab.sessionId);
} else {
browser.sessions.forgetClosedWindow(sessionInfo.window.sessionId);
}
}
function onError(error) {
console.log(error);
}
browser.sessions.getRecentlyClosed({maxResults: 1})
.then(forgetMostRecent, onError);