From b8f2e14e6dc6b688605e55c86e68ac17b53338f0 Mon Sep 17 00:00:00 2001 From: Vivek Ganesan Date: Thu, 11 May 2023 20:39:40 +0530 Subject: [PATCH 1/3] Add user experience recommendation about NIP-07 Invoking NIP-07 methods as a part of page-load event listener creates intermittent issues due to race conditions between the browser's extension script and the client's page scripts. --- 07.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/07.md b/07.md index 3b7a1d29..0fe81217 100644 --- a/07.md +++ b/07.md @@ -22,6 +22,11 @@ async window.nostr.nip04.encrypt(pubkey, plaintext): string // returns ciphertex async window.nostr.nip04.decrypt(pubkey, ciphertext): string // takes ciphertext and iv as specified in nip-04 ``` +### User experience recommendation +Due to the way browsers load the extensions, it may take some time for `window.nostr` object will be fully ready to accept requests. Hence, it is a good idea to run the first `window.nostr` interaction on a user action on the web page (like a button click), and not during the page load. + +Calling the `window.nostr` based methods during the page load runs the risk of intermittent issues due to race conditions between the client page's script and the extension's script + ### Implementation - [horse](https://github.com/fiatjaf/horse) (Chrome and derivatives) From 9bf8bb0054f236533c8bc04f6a2966970c7d5bd9 Mon Sep 17 00:00:00 2001 From: Vivek Ganesan Date: Tue, 16 May 2023 04:05:24 +0530 Subject: [PATCH 2/3] Update 07.md Implemented review inputs --- 07.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/07.md b/07.md index 0fe81217..b350d0c0 100644 --- a/07.md +++ b/07.md @@ -22,8 +22,8 @@ async window.nostr.nip04.encrypt(pubkey, plaintext): string // returns ciphertex async window.nostr.nip04.decrypt(pubkey, ciphertext): string // takes ciphertext and iv as specified in nip-04 ``` -### User experience recommendation -Due to the way browsers load the extensions, it may take some time for `window.nostr` object will be fully ready to accept requests. Hence, it is a good idea to run the first `window.nostr` interaction on a user action on the web page (like a button click), and not during the page load. +### Recommendation to Implementers +When `window.nostr` is injected by a browser extension, it may not be fully available until a certain point in the page's lifecycle. Hence, it is a good idea to invoke the first `window.nostr` based functionality after a user-action on the web page (like a button click), and not during the page load. Calling the `window.nostr` based methods during the page load runs the risk of intermittent issues due to race conditions between the client page's script and the extension's script From 68c9e484ea1fdfa48e7a62da4a1e0b1e4a29a937 Mon Sep 17 00:00:00 2001 From: Vivek Ganesan Date: Mon, 15 Jul 2024 20:41:56 +0530 Subject: [PATCH 3/3] add suggestion to extension authors Wrote a note to extension authors --- 07.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/07.md b/07.md index b350d0c0..d733d010 100644 --- a/07.md +++ b/07.md @@ -22,10 +22,9 @@ async window.nostr.nip04.encrypt(pubkey, plaintext): string // returns ciphertex async window.nostr.nip04.decrypt(pubkey, ciphertext): string // takes ciphertext and iv as specified in nip-04 ``` -### Recommendation to Implementers -When `window.nostr` is injected by a browser extension, it may not be fully available until a certain point in the page's lifecycle. Hence, it is a good idea to invoke the first `window.nostr` based functionality after a user-action on the web page (like a button click), and not during the page load. +### Recommendation to Extension Authors +To make sure that the `window.nostr` is available to nostr clients on page load, the authors who create Chromium and Firefox extensions should load their scripts by specifying `"run_at": "document_end"` in the extension's manifest. -Calling the `window.nostr` based methods during the page load runs the risk of intermittent issues due to race conditions between the client page's script and the extension's script ### Implementation