Skip to content

nostrapps/awaitnostr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

awaitnostr

awaitnostr

Documentation


GitHub license npm npm Github Stars

Introduction

awaitnostr is a utility function that allows you to wait for window.nostr to be defined before using window.nostr functions. This can be useful when using the Nostr browser extension API in your web app, as window.nostr may not be defined immediately upon page load.

Import from CDN

To import the awaitnostr module from a CDN, add the following line to your HTML file:

import awaitNostr from 'https://cdn.skypack.dev/awaitnostr'

Usage

To use awaitnostr, simply import the awaitNostr() function from the package:

import awaitNostr from 'awaitnostr'

Then call the awaitNostr() function before using any window.nostr functions:

async function myFunction() {
  await awaitNostr();
  const publicKey = await window.nostr.getPublicKey();
  // Do something with publicKey
}

Demo

You can view the demo by clicking here.

Browser Performance Benchmarks

Below are the performance benchmarks for different web browsers:

Firefox

Elapsed Time (s) Interval Time (s)
2 2
5 3

Chrome

Elapsed Time (s) Interval Time (s)
2 2

Brave

Elapsed Time (s) Interval Time (s)
2 2
5 3
9.5 4.5
16.25 6.75

License

  • MIT