I am trying to create a Firefox extension using the sessions api to display an attribute from each recently closed session.
The code directly below works as expected. For each recently closed session, the link textContent is set to the sessions sessionId:
function listSessions() {
browser.sessions.getRecentlyClosed().then((sessions) => {
let sessionList = document.getElementById("session-list");
let sessionDisplay = document.createDocumentFragment();
sessionList.textContent = '';
for (let session of sessions) {
if (session.window) {
let sessionLink = document.createElement('a');
sessionLink.textContent = session.window.sessionId;
sessionLink.setAttribute('href', session.sessionId);
sessionLink.classList.add('switch-tabs');
sessionDisplay.appendChild(sessionLink);
}
}
sessionList.appendChild(sessionDisplay);
});
}
However, when I try to set the textContent by getting information from browser.sessions, the links are not displayed at all. I would expect this code to name the links either "success" or "fail".
function listSessions() {
browser.sessions.getRecentlyClosed().then((sessions) => {
let sessionList = document.getElementById("session-list");
let sessionDisplay = document.createDocumentFragment();
sessionList.textContent = '';
for (let session of sessions) {
if (session.window) {
let sessionLink = document.createElement('a');
browser.sessions.getWindowValue(
session.window.sessionId,
'name'
).then((a) => {sessionLink.textContent = "success";}, (b) => {sessionLink.textContent = "fail";});
sessionLink.setAttribute('href', session.sessionId);
sessionLink.classList.add('switch-tabs');
sessionDisplay.appendChild(sessionLink);
}
}
sessionList.appendChild(sessionDisplay);
});
}
Update: When I set "session.window.sessionId" manually to 0, the links do get named "fail". Also, when I set it to 1, the links do get named "success". Not sure why yet.