interledger / rfcs

Specifications for Interledger and related protocols
https://interledger.org
Other
427 stars 106 forks source link

Simplify WebMonetization standard #488

Closed michielbdejong closed 5 years ago

michielbdejong commented 5 years ago

The current version of IL-RFC-28 has two disadvantages:

For comparison, the header of my personal blog now contains the following three snippets:

    <!-- Browser Donations: Flattr -->
    <meta name="flattr:id" content="qjjrw5">

    <!-- Browser Donations: LedgerLoops -->
    <link rel="ledger" href="wss://monetization-hubbie.herokuapp.com">

    <!-- Browser Donations: Coil -->
    <script src="https://polyfill.webmonetization.org/polyfill.js"></script>
    <script src="https://cdn.coil.com/donate.js"></script>
    <script>
      window.WebMonetizationScripts.donate({
        paymentPointer: '$twitter.xrptipbot.com/michielbdejong'
      })
    </script>

All my blog visitors (not only the ones who wish to donate via ILP/STREAM) now waste electricity retrieving and executing that JavaScript. I would prefer if the spec and the Coil browser extension could also support something like the following simplified format (also bringing it more in line with how the Flattr and LedgerLoops browser extensions retrieve donations details from the page):

<meta name="donate" content="$twitter.xrptipbot.com/michielbdejong" >
sharafian commented 5 years ago

Right now the polyfill requires that a script is included in order to support mobile browsers which don't have any extensions. But if you're ok with only supporting users who have a browser extension, you could do:

<script>
  if (window.WebMonetization) {
    // dynamically load in cdn.coil.com/donate.js
    // ...

    window.WebMonetizationScripts.donate({
      paymentPointer: '$twitter.xrptipbot.com/michielbdejong'
    })
  }
</script>

This solution requires no script tags; for a non web-monetized user they'll just run a single if-statement. The reason it works is that the Coil extension sets the window.WebMonetization methods on all sites to functions which will lazily load the Web Monetization polyfill if it's ever used.

This flow isn't documented anywhere right now, though, so we'll definitely work on making this case easier to include in your site

michielbdejong commented 5 years ago

support mobile browsers which don't have any extensions

So a web page with the polyfill on it can detect and receive donations from Coilers even if they use a mobile browser? How does that work?

michielbdejong commented 5 years ago

the Coil extension sets the window.WebMonetization methods on all sites

It could stop doing that, no need to inject anything into the DOM anymore. Only query for the presence of a passive html tag in the page, like I described above.

sharafian commented 5 years ago

It could stop doing that, no need to inject anything into the DOM anymore. Only query for the presence of a passive html tag in the page, like I described above.

It adds more dependencies to the standard, though, which I think is the most important part to keep simple if we want to make it into a web standard. Right now the Web Monetization API is purely a Javascript API, and it only includes STREAM, not SPSP (The payment pointer functionality is written on top)

If sending to a payment pointer turns out to be the only use case then maybe it would make sense to remove a lot of the complex functionality in favor of something like that, but it would mean getting rid of a lot of functionality which we still might want to use.

So a web page with the polyfill on it can detect and receive donations from Coilers even if they use a mobile browser? How does that work?

When you register a Web Monetization handler through Coil, it creates an iframe to polyfill.webmonetization.org in which you confirm the registration. If you confirm, then your web monetization handler is saved to localstorage on polyfill.webmonetization.org.

Now whenever you go to a page that uses the Web Monetization polyfill, polyfill.webmonetization.org embeds an iframe to the web monetization handler you've saved, and sends your ILP packets through there. Details about the user's Web Monetization handler are hidden from the page because polyfill.webmonetization.org does all of this from within its own iframe.

michielbdejong commented 5 years ago

Interesting approach! So the reason you propose to use a JavaScript API instead of an html tag is that in the future a web page might interact with the donation process. It would need to do a server-side check of any information it gets from there (otherwise the user could just inject a cheating script into the page), but despite that, I can see it could be useful.

And teaching webmasters to include the WebMonetization polyfill paves the way to these more interactive use cases. I think that's probably a valid argument.

But as you said, you could make the Coil snippet more efficient if it:

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is important, please feel free to bring it up on the next Interledger Community Group Call or in the Gitter chat.

michielbdejong commented 5 years ago

I think @sharafian did a good job at explaining why his system correctly does what it was designed to do.

It's not desirable to have a simpler system alongside Ben's one within this same rfcs repo, so let's stick to the current situation and close this ticket.

In general, to achieve web monetization, I still think passive html tags are better than code injection, but we can continue the discussion of web monetization in general (not specific to this IL-RFC) on the Network Money mailing list or the Web Payments mailing list, if desired.

Thanks for taking the time to answer my question, Ben!