Removed interference with extensions. Had to go back to only allowing handling single extension.
This commit is contained in:
141
lite/build.js
141
lite/build.js
@@ -1200,16 +1200,149 @@ class NostrLite {
|
||||
|
||||
_setupWindowNostrFacade() {
|
||||
if (typeof window !== 'undefined') {
|
||||
console.log('NOSTR_LOGIN_LITE: === TRUE SINGLE-EXTENSION ARCHITECTURE ===');
|
||||
console.log('NOSTR_LOGIN_LITE: Initial window.nostr:', window.nostr);
|
||||
console.log('NOSTR_LOGIN_LITE: Initial window.nostr constructor:', window.nostr?.constructor?.name);
|
||||
|
||||
// Store existing window.nostr if it exists (from extensions)
|
||||
const existingNostr = window.nostr;
|
||||
|
||||
// Always install our facade
|
||||
window.nostr = new WindowNostr(this, existingNostr);
|
||||
console.log('NOSTR_LOGIN_LITE: window.nostr facade installed',
|
||||
existingNostr ? '(with extension passthrough)' : '(no existing extension)');
|
||||
// TRUE SINGLE-EXTENSION ARCHITECTURE: Don't install facade when extensions detected
|
||||
if (this._isRealExtension(existingNostr)) {
|
||||
console.log('NOSTR_LOGIN_LITE: ✓ REAL EXTENSION DETECTED IMMEDIATELY - PRESERVING WITHOUT FACADE');
|
||||
console.log('NOSTR_LOGIN_LITE: Extension constructor:', existingNostr.constructor?.name);
|
||||
console.log('NOSTR_LOGIN_LITE: Extension keys:', Object.keys(existingNostr));
|
||||
console.log('NOSTR_LOGIN_LITE: Leaving window.nostr untouched for extension compatibility');
|
||||
this.preservedExtension = existingNostr;
|
||||
this.facadeInstalled = false;
|
||||
// DON'T install facade - leave window.nostr as the extension
|
||||
return;
|
||||
}
|
||||
|
||||
// DEFERRED EXTENSION DETECTION: Extensions like nos2x may load after us
|
||||
console.log('NOSTR_LOGIN_LITE: No real extension detected initially, starting deferred detection...');
|
||||
this.facadeInstalled = false;
|
||||
|
||||
let checkCount = 0;
|
||||
const maxChecks = 10; // Check for up to 2 seconds
|
||||
const checkInterval = setInterval(() => {
|
||||
checkCount++;
|
||||
const currentNostr = window.nostr;
|
||||
|
||||
console.log('NOSTR_LOGIN_LITE: === DEFERRED CHECK ' + checkCount + '/' + maxChecks + ' ===');
|
||||
console.log('NOSTR_LOGIN_LITE: Current window.nostr:', currentNostr);
|
||||
console.log('NOSTR_LOGIN_LITE: Constructor:', currentNostr?.constructor?.name);
|
||||
|
||||
// Skip if it's our facade
|
||||
if (currentNostr?.constructor?.name === 'WindowNostr') {
|
||||
console.log('NOSTR_LOGIN_LITE: Skipping - this is our facade');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._isRealExtension(currentNostr)) {
|
||||
console.log('NOSTR_LOGIN_LITE: ✓✓✓ LATE EXTENSION DETECTED - PRESERVING WITHOUT FACADE ✓✓✓');
|
||||
console.log('NOSTR_LOGIN_LITE: Extension detected after ' + (checkCount * 200) + 'ms!');
|
||||
console.log('NOSTR_LOGIN_LITE: Extension constructor:', currentNostr.constructor?.name);
|
||||
console.log('NOSTR_LOGIN_LITE: Extension keys:', Object.keys(currentNostr));
|
||||
console.log('NOSTR_LOGIN_LITE: Leaving window.nostr untouched for extension compatibility');
|
||||
this.preservedExtension = currentNostr;
|
||||
this.facadeInstalled = false;
|
||||
clearInterval(checkInterval);
|
||||
// DON'T install facade - leave window.nostr as the extension
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop checking after max attempts - no extension found
|
||||
if (checkCount >= maxChecks) {
|
||||
console.log('NOSTR_LOGIN_LITE: ⚠️ MAX CHECKS REACHED - NO EXTENSION FOUND');
|
||||
clearInterval(checkInterval);
|
||||
console.log('NOSTR_LOGIN_LITE: Installing facade for local/NIP-46/readonly methods');
|
||||
this._installFacade();
|
||||
}
|
||||
}, 200); // Check every 200ms
|
||||
|
||||
console.log('NOSTR_LOGIN_LITE: Waiting for deferred detection to complete...');
|
||||
}
|
||||
}
|
||||
|
||||
_installFacade(existingNostr = null) {
|
||||
if (typeof window !== 'undefined' && !this.facadeInstalled) {
|
||||
console.log('NOSTR_LOGIN_LITE: === _installFacade CALLED ===');
|
||||
console.log('NOSTR_LOGIN_LITE: existingNostr parameter:', existingNostr);
|
||||
console.log('NOSTR_LOGIN_LITE: existingNostr constructor:', existingNostr?.constructor?.name);
|
||||
console.log('NOSTR_LOGIN_LITE: window.nostr before installation:', window.nostr);
|
||||
console.log('NOSTR_LOGIN_LITE: window.nostr constructor before:', window.nostr?.constructor?.name);
|
||||
|
||||
const facade = new WindowNostr(this, existingNostr);
|
||||
window.nostr = facade;
|
||||
this.facadeInstalled = true;
|
||||
|
||||
console.log('NOSTR_LOGIN_LITE: === FACADE INSTALLED WITH EXTENSION ===');
|
||||
console.log('NOSTR_LOGIN_LITE: window.nostr after installation:', window.nostr);
|
||||
console.log('NOSTR_LOGIN_LITE: window.nostr constructor after:', window.nostr.constructor?.name);
|
||||
console.log('NOSTR_LOGIN_LITE: facade.existingNostr:', window.nostr.existingNostr);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to identify real browser extensions
|
||||
_isRealExtension(obj) {
|
||||
console.log('NOSTR_LOGIN_LITE: === _isRealExtension DEBUG ===');
|
||||
console.log('NOSTR_LOGIN_LITE: obj:', obj);
|
||||
console.log('NOSTR_LOGIN_LITE: typeof obj:', typeof obj);
|
||||
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
console.log('NOSTR_LOGIN_LITE: ✗ Not an object');
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log('NOSTR_LOGIN_LITE: Object keys:', Object.keys(obj));
|
||||
console.log('NOSTR_LOGIN_LITE: getPublicKey type:', typeof obj.getPublicKey);
|
||||
console.log('NOSTR_LOGIN_LITE: signEvent type:', typeof obj.signEvent);
|
||||
|
||||
// Must have required Nostr methods
|
||||
if (typeof obj.getPublicKey !== 'function' || typeof obj.signEvent !== 'function') {
|
||||
console.log('NOSTR_LOGIN_LITE: ✗ Missing required methods');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Exclude our own library classes
|
||||
const constructorName = obj.constructor?.name;
|
||||
console.log('NOSTR_LOGIN_LITE: Constructor name:', constructorName);
|
||||
|
||||
if (constructorName === 'WindowNostr' || constructorName === 'NostrLite') {
|
||||
console.log('NOSTR_LOGIN_LITE: ✗ Is our library class');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Exclude NostrTools library object
|
||||
if (obj === window.NostrTools) {
|
||||
console.log('NOSTR_LOGIN_LITE: ✗ Is NostrTools object');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Real extensions typically have internal properties or specific characteristics
|
||||
console.log('NOSTR_LOGIN_LITE: Extension property check:');
|
||||
console.log(' _isEnabled:', !!obj._isEnabled);
|
||||
console.log(' enabled:', !!obj.enabled);
|
||||
console.log(' kind:', !!obj.kind);
|
||||
console.log(' _eventEmitter:', !!obj._eventEmitter);
|
||||
console.log(' _scope:', !!obj._scope);
|
||||
console.log(' _requests:', !!obj._requests);
|
||||
console.log(' _pubkey:', !!obj._pubkey);
|
||||
console.log(' name:', !!obj.name);
|
||||
console.log(' version:', !!obj.version);
|
||||
console.log(' description:', !!obj.description);
|
||||
|
||||
const hasExtensionProps = !!(
|
||||
obj._isEnabled || obj.enabled || obj.kind ||
|
||||
obj._eventEmitter || obj._scope || obj._requests || obj._pubkey ||
|
||||
obj.name || obj.version || obj.description
|
||||
);
|
||||
|
||||
console.log('NOSTR_LOGIN_LITE: Extension detection result for', constructorName, ':', hasExtensionProps);
|
||||
return hasExtensionProps;
|
||||
}
|
||||
|
||||
launch(startScreen = 'login') {
|
||||
console.log('NOSTR_LOGIN_LITE: Launching with screen:', startScreen);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user