Estoy tratando de crear una extensión de Firefox usando la API de sesiones para mostrar un atributo de cada sesión cerrada recientemente.
El código directamente debajo funciona como se esperaba. Para cada sesión cerrada recientemente, el enlace textContent se establece en las sesiones 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); }); }Sin embargo, cuando trato de configurar el contenido de texto obteniendo información de browser.sessions, los enlaces no se muestran en absoluto. Esperaría que este código nombre los enlaces como "éxito" o "fallido".
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); }); }Actualización: cuando configuro "session.window.sessionId" manualmente en 0, los enlaces se denominan "fallidos". Además, cuando lo configuro en 1, los enlaces se denominan "éxito". No estoy seguro de por qué todavía.