mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-04 20:02:26 +00:00
fix(nostr): retry NIP-07 detection on timeout
Increases the robustness of NIP-07 extension detection by implementing a retry loop in `NostrClient.login`. If the initial detection (default 5s) times out, the client will retry up to 3 times with a 1-second delay between attempts, effectively handling slower injection scenarios or race conditions during page load. - Modified `js/nostr/client.js` to wrap `waitForNip07Extension` in a retry loop. - Validated with a reproduction test case simulating late injection.
This commit is contained in:
1 parent
4a1b58b777
commit
f66a2e5245
1 file changed
+28
-5
+28
-5
@@ -3959,13 +3959,36 @@ export class NostrClient {
|
||||
*/
|
||||
async login(options = {}) {
|
||||
try {
|
||||
try {
|
||||
await waitForNip07Extension();
|
||||
} catch (waitError) {
|
||||
devLogger.log("Timed out waiting for extension injection:", waitError);
|
||||
let extension = null;
|
||||
let attempts = 0;
|
||||
const maxAttempts = 3;
|
||||
|
||||
while (!extension && attempts < maxAttempts) {
|
||||
try {
|
||||
await waitForNip07Extension();
|
||||
extension = window.nostr;
|
||||
} catch (waitError) {
|
||||
devLogger.log(
|
||||
`Timed out waiting for extension injection (attempt ${
|
||||
attempts + 1
|
||||
}/${maxAttempts}):`,
|
||||
waitError,
|
||||
);
|
||||
}
|
||||
|
||||
if (extension) {
|
||||
break;
|
||||
}
|
||||
|
||||
attempts++;
|
||||
if (attempts < maxAttempts) {
|
||||
devLogger.log("Retrying NIP-07 detection...");
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
const extension = window.nostr;
|
||||
extension = window.nostr;
|
||||
|
||||
if (!extension) {
|
||||
devLogger.log("No Nostr extension found");
|
||||
throw new Error(
|
||||
|
||||
Reference in new issue
Block a user