Skip to content

Commit

Permalink
Bug 1850828 - Use browsing-context-discarded instead of unload listen…
Browse files Browse the repository at this point in the history
…er to delete pending windows that close before we track them as open windows. r=nika, a=RyanVM

Differential Revision: https://phabricator.services.mozilla.com/D187466
  • Loading branch information
daogottwald committed Sep 5, 2023
1 parent cc99134 commit e220f82
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions browser/modules/BrowserWindowTracker.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,18 @@ export const BrowserWindowTracker = {

// Prevent leaks in case the window closes before we track it as an open
// window.
window.addEventListener(
"unload",
() => {
const topic = "browsing-context-discarded";
const observer = (aSubject, aTopic, aData) => {
if (window.browsingContext == aSubject) {
let pending = this.pendingWindows.get(window);
if (pending) {
this.pendingWindows.delete(window);
pending.deferred.resolve(window);
}
},
{ once: true }
);
Services.obs.removeObserver(observer, topic);
}
};
Services.obs.addObserver(observer, topic);
},

/**
Expand Down

0 comments on commit e220f82

Please sign in to comment.