From 5099da355cddbe8c156a488cec9567b7bef138ec Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Thu, 11 Apr 2024 08:10:38 -0700 Subject: [PATCH] BlockingObserver: Don't block when browserId is 0 --- chrome/content/zotero/BlockingObserver.jsm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/chrome/content/zotero/BlockingObserver.jsm b/chrome/content/zotero/BlockingObserver.jsm index 23f3cdc392..948d72103c 100644 --- a/chrome/content/zotero/BlockingObserver.jsm +++ b/chrome/content/zotero/BlockingObserver.jsm @@ -52,6 +52,9 @@ class BlockingObserver { register(browser) { let id = Zotero.platformMajorVersion > 102 ? browser.browserId : browser.browsingContext.top.id; + if (id === 0) { + throw new Error('BlockingObserver: Browser is not initialized'); + } this._ids.add(id); if (!this._observerAdded) { Services.obs.addObserver(this, 'http-on-modify-request'); @@ -62,6 +65,9 @@ class BlockingObserver { unregister(browser) { let id = Zotero.platformMajorVersion > 102 ? browser.browserId : browser.browsingContext.top.id; + if (id === 0) { + throw new Error('BlockingObserver: Browser is not initialized'); + } this._ids.delete(id); if (this._observerAdded && !this._ids.size) { Services.obs.removeObserver(this, 'http-on-modify-request'); @@ -69,10 +75,22 @@ class BlockingObserver { this._observerAdded = false; } } + + dispose() { + if (this._observerAdded) { + this._ids.clear(); + Services.obs.removeObserver(this, 'http-on-modify-request'); + Zotero.debug('BlockingObserver: Removed observer'); + this._observerAdded = false; + } + } observe(subject) { let channel = subject.QueryInterface(Ci.nsIHttpChannel); let id = Zotero.platformMajorVersion > 102 ? channel.browserId : channel.topBrowsingContextId; + if (id === 0) { + return; + } if (this._ids.has(id) && this.shouldBlock(channel.URI)) { channel.cancel(Cr.NS_BINDING_ABORTED); }