joule-labs / webln

Spec and client library for WebLN apps and providers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trouble understanding WebLN - Joule integration

dannydeezy opened this issue · comments

Hello, I'm really excited to use WebLN but I'm having trouble configuring it. Hoping for some guidance.

I have a web server that is serving an html file to the clients. Within the html file I am including the script tag:
<script src="https://unpkg.com/webln@0.1.0/dist/webln.min.js" integrity="sha384-KbiwDLn7g4wD+1fs5EA/1c6p4Zzy0u8RwWObPvI+ty1WpALihdyvjF7/yKJzJk/I" crossorigin="anonymous"></script>

The web server also provides a javascript file: some code to run in their browser. Within this file, I can do console.dir(WebLN) and I see the WebLN object show up in the console.

The client's browser has Lightning Joule enabled and set up in his browser.

However, if the client code runs WebLN.requestProvider(), I get the error: "Your browser does not support WebLN"

I feel like I'm close, but must be missing something. Do i need to approve the domain from the Lightning Joule settings? If so, I couldn't figure out how to do this.

Please let me know if there is any more information I can provide, and thanks in advance for any guidance.

It's likely you're calling the function too quickly, it takes a little bit of time for WebLN to inject depending on the client. You might want to put it inside of a DOMContentLoaded listener. Better yet, don't call it until the user has performed some action on the site that would require WebLN. It's a little jarring as a user to visit a site and immediately get a popup asking to connect.

I'll likely want to add the DOMContentLoaded listener into the WebLN requestProvider function itself to prevent issues like these though. Thanks for posting.

awesome thank you, that worked.
I waited until the user first clicked a relevant button, and it worked great.
super excited about this :)