Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect WebLN provider without enabling it? #52

Open
ericpp opened this issue Oct 29, 2022 · 2 comments
Open

Detect WebLN provider without enabling it? #52

ericpp opened this issue Oct 29, 2022 · 2 comments

Comments

@ericpp
Copy link

ericpp commented Oct 29, 2022

Is there a recommended way to detect if the user has a WebLN provider installed? I'm wanting to use this detection to decide whether to show LN payment options to the user or to show them a message to download a WebLN provider.

The requestProvider() function seems like the best way to do this within the webln library, but it also enables the WebLN provider and causes some providers (Alby) to immediately prompt the user for authorization:

webln.enable().then(() => resolve(webln));

Alternatively, I could use the same window.webln check that requestProvider() uses without the enable call, but it feels wrong to go outside of the library to do this:

const webln: WebLNProvider = (window as any).webln;

@ericpp
Copy link
Author

ericpp commented Oct 29, 2022

A detectProvider function could be added to the library for this purpose,
see: ericpp@5eaf0a6

@wbobeirne
Copy link
Member

I think you're absolutely right that requestProvider should not necessarily automatically enable the provider, that was probably a bad move on the initial implementation.

I am however hesitant to implement a synchronous detectProvider function. One thing I wanted to keep in mind was alternative providers that aren't just browser extensions. For instance, I could see there being some kind of standard port that webln will try to reach out to and see if there's a local application listening. Or maybe an iframe-based postMessage implementation. Both of these would require you to wait for some kind of response.

If someone wants to hack around the lack of a detect method today by checking for window.webln, they can definitely do that, but it might not be future proof for some other future implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants