browsingData
or history
APIs to remove history. This is an asynchronous function that returns a Promise
.
var forgettingTab = browser.sessions.forgetClosedTab( windowId, // integer sessionId // string )
windowId
Integer
. The ID of the window that hosted the tab you want to forget.sessionId
String
. The ID of the session you want to forget.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.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
forgetClosedTab |
No |
No |
55 |
? |
No |
No |
? |
? |
No |
? |
? |
? |
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);
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/sessions/forgetClosedTab