简体   繁体   中英

Firefox Extension - onPopupClose event?

I have popup in which I need to update the data inside it in reactively. What function or event is needed to track when a popup closes?

Currently my code structure is as follows:

 let BG = browser.extension.getBackgroundPage(); let timer = BG.timer; function updatePageTime(secondsElapsed) { const content = document.getElementById("content"); content.innerHTML = "Current Time Spent: " + timer.getTimeElapsed(); } document.addEventListener("DOMContentLoaded", function () { timer.subscribe(updatePageTime); }); document.addEventListener("unload", function () { timer.unsubscribe(updatePageTime); }); 

The problem is that unload and beforeunload do not trigger on popup closes, thus I am unable to stop updates to a non-existant DOM.

Unfortunately I did not see that unload is defined on window and not document. Simply changing the document.addEventListener("unload" to window.addEventListener("unload" fixes the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM