getAlby / lightning-browser-extension

The Bitcoin Lightning Browser extension that connects to different wallet interfaces and brings deep lightning integration to the web
https://getalby.com
MIT License
530 stars 193 forks source link

Protocol handlers not properly supported #1305

Open RenegadeButcher opened 2 years ago

RenegadeButcher commented 2 years ago

LNURLS hyperlinked with the lightning: prefix open in Alby, but the same links forwarded in a shrt url or forwarded subdomain do not get recognized by Alby. Instead browsers attempt to call an external application.

To Reproduce

Steps to reproduce the behavior:

  1. Visit a URL Shortener like https://tinyurl.com/tiprenegadebutcher
  2. Create a new redirected link with "lightning:LNURL***"
  3. Visit the provided redirect

Expected behavior

Alby should recognize the forwarded string in the same manner as a normal hyperlink

Alby information

This seems to occur on any kind of redirect. Some sites (Wordpress) attempt to treat lightning: hyperlinks as internal links, and some (YouTube) block the link through a redirect. Redirecting in the manner described solves the issue for mobile browsers, but does not allow the use of Alby for clickable tipping links.

Are you working on this issue?

Yes and no, I'm trying to find a way to prevent or circumvent the issue.

RenegadeButcher commented 2 years ago

Based on my current experimenting, it appears it's specifically 301 redirects that work quite well to open mobile wallets, but bypass Alby even if the final URL is lightning:LNURL****. So something about a 301 redirect is blinding the webln.

reneaaron commented 2 years ago

Thanks for your detailed report, that really helps a lot. 👍

After investigating this for a bit I want to summarize my findings here:

Extensions can register themselves as protocol handlers

Browser APIs limit events that are exposed

Intercepting 301 redirect is possible

--> Not ideal, but does the job

Other ideas

Submit lightning as a proposal for official link schemes:

https://html.spec.whatwg.org/multipage/system-state.html#safelisted-scheme

That way Alby could register for lightning links globally and handle them properly

Links

RenegadeButcher commented 2 years ago

Excellent! I appreciate your thorough research. At least now it's clear why the issue exists!

Perhaps watching headers is a simple addition in the short term until protocol and browser standards catch-up. In the meantime, I've managed some workarounds.

Thank you, again!

On Fri, Aug 26, 2022 at 5:44 AM René Aaron @.***> wrote:

Thanks for your detailed report, that really helps a lot. 👍

After investigating this for a bit I want to summarize my findings here: Extensions can register themselves as protocol handlers

Browser APIs limit events that are exposed

  • browser.tabs.onUpdated will only trigger for certain schemes (which lightning is not a part of)

Intercepting 301 redirect is possible

  • Intercept all responses
  • check the location header for lightning: links
  • rewrite the header to ext+alby:...
  • this will open a new extension page (not the extension popup)

--> Not ideal, but does the job Other ideas

Submit lightning as a proposal for official link schemes:

https://html.spec.whatwg.org/multipage/system-state.html#safelisted-scheme

That way Alby could register for lightning links globally and handle them properly

— Reply to this email directly, view it on GitHub https://github.com/getAlby/lightning-browser-extension/issues/1305#issuecomment-1228342908, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2IS4DCUY26TSG3Q2IRVF73V3CNZLANCNFSM565Z7NIA . You are receiving this because you authored the thread.Message ID: @.***>

bumi commented 2 years ago

thanks for reporting and thanks @reneaaron for the research, good to know should alby register the bitcoin: protocol handler?

reneaaron commented 2 years ago

I was also thinking about that. At least bitcoin: links with the lightning parameter could potentially be handled by Alby. (BIP21)

reneaaron commented 2 years ago

Registering a bitcoin: protocol handler would probably be the cleaner way to handle bitcoin: links for now since it allows the user to choose between different software (e.g. if they have locally installed software that is able to handle those links, too).

Right now we already handle those kind of links and local software has no chance of picking up the links.