From 8041d7d4df89d7c174f9aae1b371cc0d20823872 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Wed, 23 Jul 2025 11:54:30 -0400 Subject: [PATCH] Complain when Notifier/Prefs observer leaks window --- chrome/content/zotero/xpcom/notifier.js | 8 +++++++- chrome/content/zotero/xpcom/prefs.js | 10 +++++++--- chrome/content/zotero/xpcom/utilities_internal.js | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/notifier.js b/chrome/content/zotero/xpcom/notifier.js index 9239b3c2ba..5de04301aa 100644 --- a/chrome/content/zotero/xpcom/notifier.js +++ b/chrome/content/zotero/xpcom/notifier.js @@ -153,11 +153,17 @@ Zotero.Notifier = new function () { continue; } + let ref = _observers[id].ref; + + if (Zotero.Debug.enabled && Zotero.Utilities.Internal.isObjectLeakingWindow(ref)) { + Zotero.warn(`Notifier observer with id '${id}' belongs to leaked window`); + } + // Catch exceptions so all observers get notified even if // one throws an error try { let t = new Date; - yield Zotero.Promise.resolve(_observers[id].ref.notify(event, type, ids, extraData)); + yield Zotero.Promise.resolve(ref.notify(event, type, ids, extraData)); t = new Date - t; if (t > 5) { //Zotero.debug(id + " observer finished in " + t + " ms", 5); diff --git a/chrome/content/zotero/xpcom/prefs.js b/chrome/content/zotero/xpcom/prefs.js index b1e64c0b45..c75352a8c4 100644 --- a/chrome/content/zotero/xpcom/prefs.js +++ b/chrome/content/zotero/xpcom/prefs.js @@ -402,10 +402,14 @@ Zotero.Prefs = new function() { return; } - var obs = _observers[data]; - for (var i=0; i