From 325a6bd2bf4119a24c8fcde5d0eafc24bf225b8e Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Sun, 26 Oct 2025 21:30:14 -0400 Subject: [PATCH] Fix nostr SimplePool bootstrap --- js/nostr/toolkit.js | 12 ++++++++---- js/nostrToolsBootstrap.js | 40 ++++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/js/nostr/toolkit.js b/js/nostr/toolkit.js index 2cb42138..d6ed7329 100644 --- a/js/nostr/toolkit.js +++ b/js/nostr/toolkit.js @@ -210,10 +210,14 @@ function isSimplePoolConstructor(candidate) { return false; } - return ( - typeof prototype.sub === "function" && - typeof prototype.close === "function" - ); + const hasSubscribeMethod = + typeof prototype.sub === "function" || + typeof prototype.subscribe === "function" || + typeof prototype.subscribeMany === "function"; + + const hasCloseMethod = typeof prototype.close === "function"; + + return hasSubscribeMethod && hasCloseMethod; } function unwrapSimplePool(candidate) { diff --git a/js/nostrToolsBootstrap.js b/js/nostrToolsBootstrap.js index c951585c..813af171 100644 --- a/js/nostrToolsBootstrap.js +++ b/js/nostrToolsBootstrap.js @@ -584,19 +584,33 @@ export function bootstrapNostrTools() { return activeTools; }; - try { - Object.defineProperty(scope, "NostrTools", { - configurable: true, - enumerable: true, - get() { - return activeTools; - }, - set(value) { - applyActive(value); - }, - }); - } catch (error) { - userLogger.warn("[bitvid] Failed to install NostrTools guard.", error); + const existingDescriptor = + scope && typeof scope === "object" + ? Object.getOwnPropertyDescriptor(scope, "NostrTools") + : null; + + const canInstallGuard = + !existingDescriptor || existingDescriptor.configurable === true; + + if (canInstallGuard) { + try { + Object.defineProperty(scope, "NostrTools", { + configurable: true, + enumerable: true, + get() { + return activeTools; + }, + set(value) { + applyActive(value); + }, + }); + } catch (error) { + userLogger.warn("[bitvid] Failed to install NostrTools guard.", error); + } + } else { + devLogger.info( + "[bitvid] Skipping NostrTools guard; existing property is non-configurable." + ); } applyActive(existingGlobalTools);