<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Peter-Paul Koch</title>
    <description>The latest articles on DEV Community by Peter-Paul Koch (@ppk).</description>
    <link>https://dev.to/ppk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F650466%2F73748ee4-64da-4bd7-b56a-574aafeaa8c3.jpeg</url>
      <title>DEV Community: Peter-Paul Koch</title>
      <link>https://dev.to/ppk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ppk"/>
    <language>en</language>
    <item>
      <title>WMS changes part 2: Background information</title>
      <dc:creator>Peter-Paul Koch</dc:creator>
      <pubDate>Tue, 26 Oct 2021 09:09:23 +0000</pubDate>
      <link>https://dev.to/coil/wms-changes-part-2-background-information-45m9</link>
      <guid>https://dev.to/coil/wms-changes-part-2-background-information-45m9</guid>
      <description>&lt;p&gt;In &lt;a href="https://dev.to/coil/wms-changes-part-1-breaking-changes-flj"&gt;part 1&lt;/a&gt; we treated two upcoming breaking changes in web monetization. This article looks ahead to potential other changes, and introduces you to the reasoning behind them. It also gives one piece of background.&lt;/p&gt;

&lt;p&gt;These changes will not take place immediately, but they will likely come into effect somewhere in 2022.&lt;/p&gt;

&lt;h2&gt;
  
  
  New events
&lt;/h2&gt;

&lt;p&gt;Currently the Coil extension supports four events; you can read more about them &lt;a href="https://dev.to/coil/the-web-monetization-meta-tag-and-api-3eh9"&gt;here&lt;/a&gt;. These events are going to be revised, in particular because there is no error event that warns you of monetization stream errors.&lt;/p&gt;

&lt;p&gt;The changing of the event model may be breaking change; we can't say yet because it's not yet certain exactly what the new events are going to be.&lt;/p&gt;

&lt;h3&gt;
  
  
  Errors
&lt;/h3&gt;

&lt;p&gt;As with any request over the Internet, a lot can go wrong with web monetization requests. The Interledger protocol (ILP) that underlies web monetization is able to handle some of these problems itself. A payment request or response, or delivery of a receipt, may go wrong. Much like TCP, ILP has some built-in error correction mechanisms.&lt;/p&gt;

&lt;p&gt;These corrected errors do not have to be reported to a web page, just as regular JavaScript events do not report TCP problems. It's only when ILP cannot recover from an error and gives up that browsers should be notified and should fire an event. Thus you as a web developer know that something exceptional has happened, and can react appropriately.&lt;/p&gt;

&lt;p&gt;You might, for instance, decide to pause access to paid content, or decide to continue giving the user access for a while longer, until, for instance, several error messages have come in.&lt;/p&gt;

&lt;p&gt;The problem with errors is that there are so many types. A networking error like the one described above is one of them, and it’s a complicated one. Will the extension fire an error event if a single payment or receipt goes missing? Or only when a whole string of them disappear? That has not been decided yet.&lt;/p&gt;

&lt;p&gt;Simpler errors include the inability to connect a certain payment pointer (the pointer is probably wrong), or receiving invalid JSON as a response. Error events should certainly be fired in circumstances like these that prevent normal monetization.&lt;/p&gt;

&lt;p&gt;Maybe a property should be added that states the nature of the error; incorrect pointer, invalid JSON, or network error. You'll likely want to do different things in these circumstances. This, too, has yet to be decided.&lt;/p&gt;

&lt;h3&gt;
  
  
  Monetization as a state machine
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/WICG/webmonetization/issues/220"&gt;A first attempt&lt;/a&gt; has been made to define the states a web monetization stream can be in. In the future, the &lt;code&gt;state&lt;/code&gt; property will reflect the state of the stream. Currently discussed values include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;error&lt;/code&gt;: an error has occurred, as discussed above&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;active&lt;/code&gt;: all's going well&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;paused&lt;/code&gt;: monetization possible, but not occurring right now; maybe the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag has been temporarily disabled&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;idle&lt;/code&gt;: monetization possible, but the stream hasn't started yet.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Maybe the &lt;code&gt;paused&lt;/code&gt; and &lt;code&gt;idle&lt;/code&gt; values are going to be combined — that depends on how much difference there is between the two states.&lt;/p&gt;

&lt;h2&gt;
  
  
  pointers
&lt;/h2&gt;

&lt;p&gt;Currently, if you want to access the payment pointer you do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.monetization.pointer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The payment pointer contains the content of the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag, for instance &lt;code&gt;$url.of.server/myID&lt;/code&gt;. Here several changes will take place as well:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;code&gt;document&lt;/code&gt; will change to &lt;code&gt;navigator&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; the payment pointer will be in a &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag, not a &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag and will become a valid URL instead of the current &lt;code&gt;$&lt;/code&gt;-prepended string&lt;/li&gt;
&lt;li&gt; Maybe the internal logic of &lt;code&gt;pointer&lt;/code&gt; will change as well.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://dev.to/coil/wms-changes-part-1-breaking-changes-flj"&gt;Part 1&lt;/a&gt; discussed the first two changes. Here we’ll discuss the final change. Changing &lt;code&gt;pointer&lt;/code&gt;’s internal logic would probably be a breaking change.&lt;/p&gt;

&lt;h3&gt;
  
  
  Multiple pointers
&lt;/h3&gt;

&lt;p&gt;Currently a document can have only one payment pointer at a time. Future iterations of the specification might change this — consider, for instance, an article with three authors who split the money evenly. The document would need three payment pointers. But which one of them should be in &lt;code&gt;pointer&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;The likely answer is: none of them. Future versions of the spec will likely have a collection &lt;code&gt;pointers&lt;/code&gt; that contains all payment pointers in the document. Maybe there will be an &lt;code&gt;activePointer&lt;/code&gt; or &lt;code&gt;activePointers&lt;/code&gt; property as well to denote payment pointers that are currently active — though it's unclear as yet how 'active pointers' will be defined.&lt;/p&gt;

&lt;p&gt;In fact, it's not yet completely clear how to define multiple payment pointers. Multiple &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tags? One tag with all the pointers? And if the three authors in the example do not split the proceeds evenly but, for instance, 50% / 25% / 25%, how are we going to add that information to the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;? And to the JavaScript API?&lt;/p&gt;

&lt;p&gt;These questions have to be solved before &lt;code&gt;pointer&lt;/code&gt; can change.&lt;/p&gt;

&lt;h2&gt;
  
  
  media queries
&lt;/h2&gt;

&lt;p&gt;Currently web monetization works at the HTML and JavaScript levels. It might be a good idea to bring the third leg of the front-end stool, CSS, into the mix as well. Maybe a monetization media query could be useful. Something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.hidden-content {
    display: none;
}

@media all and (monetization: true) {
    .hidden-content {
        didplay: block;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The question is exactly how it's going to be implemented. &lt;a href="https://github.com/WICG/webmonetization/issues/189"&gt;The current discussion&lt;/a&gt; sees two options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; A simple boolean flag: a page is either monetized or not monetized. This is what the simple example code above does.&lt;/li&gt;
&lt;li&gt; A more nuanced system where the source of the payment stream is also considered. Examples could be &lt;code&gt;ads&lt;/code&gt;, &lt;code&gt;subscription&lt;/code&gt;, &lt;code&gt;webmonetization&lt;/code&gt;, or other payment options.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The second option is clearly the most forward-thinking one, but also harder to implement. Once they support web monetization natively browsers will know if a page is web-monetized or not, but how will it learn a page is ad-monetized? Or subscription-monetized? We can probably find a solution, but it will take time.&lt;/p&gt;

&lt;p&gt;Maybe the media query will be implemented before all these issues are solved. It's possible we'll just start with the &lt;code&gt;webomnetization&lt;/code&gt; and &lt;code&gt;none&lt;/code&gt; values and add new ones as they are implemented. Thus the example above might become:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.hidden-content {
    display: none;
}

@media all and (monetization: webmonetization) {
    .hidden-content {
        didplay: block;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This discussion is still in its infancy, and it will take some time before a monetization media query actually exists.&lt;/p&gt;

&lt;p&gt;With that, you are now up to speed on the near future of web monetization. We’ll let you know if new functionalities appear in the extension, or browsers start to support web monetization natively, or if the specification changes significantly.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>WMS changes part 1: Breaking changes</title>
      <dc:creator>Peter-Paul Koch</dc:creator>
      <pubDate>Tue, 12 Oct 2021 10:00:08 +0000</pubDate>
      <link>https://dev.to/coil/wms-changes-part-1-breaking-changes-flj</link>
      <guid>https://dev.to/coil/wms-changes-part-1-breaking-changes-flj</guid>
      <description>&lt;p&gt;In this two-part series we will look at recent developments in the Web Monetization specification and the Coil extension. This article discusses two upcoming breaking changes, while the &lt;a href="https://dev.to/coil/wms-changes-part-2-background-information-45m9"&gt;next one&lt;/a&gt; treats several planned changes that won’t take effect immediately, as well as one piece of background.&lt;/p&gt;

&lt;p&gt;This year, two breaking changes will be introduced in the &lt;a href="https://webmonetization.org/specification.html"&gt;Web Monetization specification&lt;/a&gt; and the Coil extension. The payment pointer will move from the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; to the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag, and the JavaScript &lt;code&gt;monetization&lt;/code&gt; interface will move from &lt;code&gt;document&lt;/code&gt; to &lt;code&gt;navigator&lt;/code&gt;. We will discuss those two changes and what you have to do to adjust your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; to &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;When a user with the Coil extension — or, in the future, a browser that supports web monetization — visits a monetized page the browser has to fetch a JSON file with monetization information. The location of this file has to be defined somewhere. Where?&lt;/p&gt;

&lt;p&gt;One of the decisions made in the &lt;a href="https://dev.to/coil/an-update-from-the-web-monetization-workshop-3ppd"&gt;Web Monetization workshop&lt;/a&gt; was to move this definition from the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag to the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;

&lt;h3&gt;
  
  
  The old situation
&lt;/h3&gt;

&lt;p&gt;The Coil extension currently uses &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt;; for instance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="monetization" content="$url.of.server/someID"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Browsers now download the JSON file from &lt;code&gt;url.of.server/someID&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In the first draft of web monetization this tag was useful because &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tags do not have any default behavior, and Coil's extension could do anything it liked. Since web monetization was a new idea Coil needed to be able to work unimpeded by earlier decisions and functionalities already baked into browsers. Thus, using a neutral tag like &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; was a good idea.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;Meanwhile web monetization is entering a new stage, where it has to be made ready for formal specification and native browser support. Use of &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; is starting to restrict the future standard and the current implementations. By contrast there are several reasons why &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; is more future-friendly.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; specifies a relationship of the HTML document it appears in with an external resource, while &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; gives more information about the HTML document itself. From the browsers' perspective, web monetization is an external resource. It doesn't have anything to do with the rendering process of the page; it merely defines external functionality. Thus, &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; is the correct tag to use here.&lt;/p&gt;

&lt;p&gt;In addition, &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; has some useful functionalities that are already built into browsers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;, browsers already have a fetching mechanism for downloading external assets such as style sheets and favicons. Adding the monetization JSON file as a new one is fairly easy.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;’s &lt;code&gt;referrerpolicy&lt;/code&gt; attribute allows you to decide how much information about the page the user is visiting browsers will send while they fetch the JSON.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; allows you to decide what to do about cross-origin policies. If browsers fetch the JSON file, what kind of information about the user will be sent to the payment end-point? From a privacy perspective the best answer is None, and the &lt;code&gt;crossorigin="anonymous"&lt;/code&gt; attribute makes sure nothing is sent. Still, it allows web developers to define other &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS"&gt;CORS policies&lt;/a&gt; if necessary.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;disabled&lt;/code&gt; attribute allows web authors to disable the monetization link if they want to pause monetization.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag is equivalent to a &lt;code&gt;Link&lt;/code&gt; HTTP header. HTTP headers allow monetization information to be added to non-HTML documents as well — such as a PDF with an article that you'd like to monetize. Right now neither the specification nor the extension support this, but it can be easily added in the future.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Again, the main reason for the switch is that &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; contains these functionalities out of the box. It is possible to add all of them to &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt;, but why bother if browsers already offer a perfectly good alternative? You can read more about &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; vs. &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; in &lt;a href="https://github.com/WICG/webmonetization/issues/19#issuecomment-705407129"&gt;this discussion&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Changes to your pages
&lt;/h3&gt;

&lt;p&gt;The switch to &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; is a breaking change because you have to add a &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; to your website instead of &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt;. Fortunately that's quite simple. If you have this &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="monetization" content="$url.of.server/someID"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you replace it with this &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link rel="monetization" href="https://url.of.server/someID"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you see, the &lt;code&gt;content/href&lt;/code&gt; of the two is not exactly the same. The current &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag does not use a URL, but the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag is required to — it should link to an external resource, after all, and browsers can only find that resource if you use a proper URL. In this simple example, replacing the custom &lt;code&gt;$&lt;/code&gt; by the standard &lt;code&gt;https://&lt;/code&gt; is all that's necessary.&lt;/p&gt;

&lt;p&gt;Unfortunately there are also more complex cases, where &lt;code&gt;&amp;lt;meta content&amp;gt;&lt;/code&gt; does not map to &lt;code&gt;&amp;lt;link href&amp;gt;&lt;/code&gt; one on one. Be sure to read the &lt;a href="https://paymentpointers.org/syntax-resolution/#resolution"&gt;payment pointer syntax&lt;/a&gt; article in order to convert all your pointers correctly.&lt;/p&gt;

&lt;p&gt;The current Coil extension supports both &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;, so it should seamlessly switch between the two. Even if it finds both tags in the HTML the extension will make sure only one payment occurs. Once browsers start supporting web monetization natively they will only recognize &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; and ignore &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting the payment pointer
&lt;/h3&gt;

&lt;p&gt;The only minor outstanding problem is the way you change the payment pointer. Up until now the only way to do so was to change the &lt;code&gt;content&lt;/code&gt; attribute of the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="monetization" content="$url.of.server/someID" id="paymentPointer"&amp;gt;

function changePointer() {
    let meta = document.querySelector('#paymentPointer');
    meta.setProperty('content','$url.of.server/myOtherID');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's ugly, but it works. (For more information about the current JavaScript API, see &lt;a href="https://dev.to/coil/the-web-monetization-meta-tag-and-api-3eh9"&gt;this earlier article&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;Once you use &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;, though, you have to write a slightly different script, and if you use both &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; you have to change both of them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="monetization" content="$url.of.server/someID" id="paymentPointer"&amp;gt;
&amp;lt;link rel="monetization" href="https://url.of.server/someID" id="otherPaymentPointer"&amp;gt;

function changePointer() {
    let meta = document.querySelector('#paymentPointer');
    meta.setProperty('content','$url.of.server/myOtherID');
    let link = document.querySelector('#otherPaymentPointer');
    link.setProperty('href','https://url.of.server/myOtherID');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not impossible, but it's not very developer-friendly, either. What we need is a way to set the payment pointer directly in the API instead of messing about with HTML attributes. Ideally, it would be something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function changePointer() {
    document.monetization.pointer = 'https://url.of.server/myOtherID';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Right now the extension supports getting the payment pointer in &lt;code&gt;monetization.pointer&lt;/code&gt;, but not setting it. While a settable &lt;code&gt;pointer&lt;/code&gt; is under discussion in the standards track, it turns out there are some issues that make it unlikely it will be implemented in the manner shown above. We’ll get back to this problem in the &lt;a href="https://dev.to/coil/wms-changes-part-2-background-information-45m9"&gt;second part&lt;/a&gt; of this series.&lt;/p&gt;

&lt;h2&gt;
  
  
  document to navigator
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;monetization&lt;/code&gt; interface is a collection of useful properties and events that let you monitor the monetization state of your web pages. The full current API &lt;a href="https://dev.to/coil/the-web-monetization-meta-tag-and-api-3eh9"&gt;is described here&lt;/a&gt;. Up until now it was a part of &lt;code&gt;document&lt;/code&gt;, but it’s going to switch to &lt;code&gt;navigator&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This, too, is a breaking change, and it has similar reasons as the switch from &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; to &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  From document to navigator
&lt;/h3&gt;

&lt;p&gt;At the moment the monetization interface is part of the &lt;code&gt;document&lt;/code&gt;; for instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.monetization.state
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's going to move to &lt;code&gt;navigator&lt;/code&gt;, and this line of code will become:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;navigator.monetization.state
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Appending &lt;code&gt;monetization&lt;/code&gt; to &lt;code&gt;document&lt;/code&gt; has never made a lot of sense. Furthermore, &lt;code&gt;document.monetization&lt;/code&gt; is a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag, and that has never made any sense either.&lt;/p&gt;

&lt;p&gt;In addition, appending &lt;code&gt;monetization&lt;/code&gt; to the document could cause problems. It's possible to create a new document in JavaScript, and if &lt;code&gt;monetiztion&lt;/code&gt; would be appended to that document it would also be monetized. This could lead to odd situations that it's better to prevent than repair.&lt;/p&gt;

&lt;p&gt;Besides, the existence of web monetization is a top-level function of the browser, and not of the page. Moving it to &lt;code&gt;navigator&lt;/code&gt;, especially in conjunction with moving the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag to a &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag, makes excellent sense. Also, &lt;code&gt;navigator.monetization&lt;/code&gt; will no longer be a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The Coil extension will add &lt;code&gt;navigator.monetization&lt;/code&gt; later this year — right now the road map says November. The Puma browser, which uses the Coil extension, will add it a few weeks later. For now they will also continue to support &lt;code&gt;document.monetization&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Changes to your pages
&lt;/h3&gt;

&lt;p&gt;Although there will be a transition period where the extension supports both, eventually support for &lt;code&gt;document.monetization&lt;/code&gt; will end, and by that time this will become a breaking change.&lt;/p&gt;

&lt;p&gt;That is, in the future any script that still uses &lt;code&gt;document.monetization&lt;/code&gt; will break, since it cannot find the &lt;code&gt;document.monetization&lt;/code&gt; interface. It should look for &lt;code&gt;navigator.monetization&lt;/code&gt; instead, and you will have to code that explicitly. It’s best to do it right now so that you won’t have to worry again.&lt;/p&gt;

&lt;p&gt;I advise you to do the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Throughout your scripts, change &lt;code&gt;document.monetization&lt;/code&gt; to &lt;code&gt;navigator.monetization&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt; Add the following snippet at the start of your script:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (!navigator.monetization) {
    navigator.monetization = document.monetization
}

if (navigator.monetization) {
    // your scripts that use navigatior.monetization go here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;navigator.monetization&lt;/code&gt; does not exist, make it an alias of &lt;code&gt;document.monetization&lt;/code&gt;. If your user’s browser does not support monetization &lt;code&gt;document.monetization&lt;/code&gt; will not exist, either, but that’s OK.&lt;/p&gt;

&lt;p&gt;Then check again if &lt;code&gt;navigator.monetization&lt;/code&gt; exists. If it’s either supported natively or it’s an alias of &lt;code&gt;document.monetization&lt;/code&gt; your script will run. If it’s still &lt;code&gt;undefined&lt;/code&gt; your script will fail gracefully.&lt;/p&gt;

&lt;p&gt;With that we have treated the upcoming changes in the Coil extension. Meanwhile, the Web Monetization standard remains in development, and it will likely introduce more changes. &lt;a href="https://dev.to/coil/wms-changes-part-2-background-information-45m9"&gt;The next part&lt;/a&gt; in this series takes a look at a few.&lt;/p&gt;

</description>
      <category>webmonetization</category>
      <category>webdev</category>
      <category>coil</category>
    </item>
    <item>
      <title>The future of web monetization</title>
      <dc:creator>Peter-Paul Koch</dc:creator>
      <pubDate>Tue, 13 Jul 2021 10:02:53 +0000</pubDate>
      <link>https://dev.to/coil/the-future-of-web-monetization-2n3</link>
      <guid>https://dev.to/coil/the-future-of-web-monetization-2n3</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/coil/let-s-talk-about-money-47i5"&gt;Part 1&lt;/a&gt; of this series made clear why web monetization is a good thing. &lt;a href="https://dev.to/coil/how-it-works-1b1"&gt;Part 2&lt;/a&gt; described the Coil system at high level, while &lt;a href="https://dev.to/coil/the-web-monetization-meta-tag-and-api-3eh9"&gt;part 3&lt;/a&gt; took a look at all those pesky details you need to know about.&lt;/p&gt;

&lt;p&gt;In this article we’ll talk about the future. The immediate future mostly consists of a proper web monetization standard. For the more distant future the crucial question is how much interest there will be in web monetization, and whether the current model will remain intact or will change — and if so, how.&lt;/p&gt;

&lt;h2&gt;
  
  
  Standard
&lt;/h2&gt;

&lt;p&gt;Coil is working on properly specifying web monetization, including the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag and API we discussed, with W3C. A &lt;a href="https://webmonetization.org/specification.html"&gt;draft standard&lt;/a&gt; is already available, but, as usual, these things take time.&lt;/p&gt;

&lt;p&gt;The proposed draft is currently under discussion in the &lt;a href="https://www.w3.org/community/wicg/"&gt;Web Platform Incubator Community Group&lt;/a&gt;, where proposals for new standards from unexpected corners can be discussed and, ideally, groomed for official W3C status.&lt;/p&gt;

&lt;p&gt;What a WICG proposal needs most is practical implementation and usage data. Typically, this is easy to do for a browser vendor that can just include the proposal in its browser and see what happens next.&lt;/p&gt;

&lt;p&gt;It’s harder for parties such as Coil who do not own a browser. That’s why uptake of the extension and creative use of the API, is so important: not only will user feedback improve the eventual specification, it will also convince other parties (read: browser vendors) that there is a serious use case for web monetization and a specification.&lt;/p&gt;

&lt;p&gt;Eventually, web monetization should be supported natively, but that requires buy-in from the vendors. Right now only &lt;a href="https://www.pumabrowser.com/"&gt;Puma&lt;/a&gt; implemented the proposal. Samsung Internet &lt;a href="https://medium.com/samsung-internet-dev/bringing-web-monetization-with-coil-to-samsung-internet-4be5ecfb7703"&gt;added the Coil add-on&lt;/a&gt; to the curated on-device list, which indicates a solid interest in web monetization — though without a Blink implementation it cannot proceed any further. The other browsers have not yet taken any steps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.grantfortheweb.org/"&gt;Grant for the Web&lt;/a&gt; made a technical scholarship available that allowed &lt;a href="https://community.webmonetization.org/wmfirefox/exploring-integration-of-web-monetization-into-the-web-platform-grant-report-1-5ama"&gt;a Firefox&lt;/a&gt; &lt;a href="https://community.webmonetization.org/wmfirefox/bringing-web-monetization-to-the-web-platform-grant-report-2-2fff"&gt;implementation&lt;/a&gt; to be written, although it has not yet been added to the browser. They are still &lt;a href="https://www.grantfortheweb.org/blog/browser-technical-scholar"&gt;looking for&lt;/a&gt; someone to port it to other engines.&lt;/p&gt;

&lt;h2&gt;
  
  
  New features
&lt;/h2&gt;

&lt;p&gt;As soon as a proposal is implemented people start &lt;a href="https://github.com/wicg/webmonetization/issues/"&gt;asking about&lt;/a&gt; new features, or updates of existing features. This is no different for Web Monetization.&lt;/p&gt;

&lt;p&gt;One question is about RSS. If you monetize your blog, but you also offer the full content as an RSS feed, could you monetize that feed? It &lt;a href="https://github.com/WICG/webmonetization/issues/70"&gt;turns out&lt;/a&gt; that Atom already has a &lt;code&gt;&amp;lt;link rel="monetization"&amp;gt;&lt;/code&gt; that could be used — provided RSS readers start doing something with this information, most likely transferring it to the page’s &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag. As far as I know no RSS reader actually does so as yet.&lt;/p&gt;

&lt;p&gt;Another interesting &lt;a href="https://github.com/WICG/webmonetization/issues/133"&gt;set of questions&lt;/a&gt; was asked around future functionality of the Web Monetization agent (currently the extension, but in the future the browsers). Would users be allowed to decide when they pay and how much? Either on a per-case basis or with block and allow lists?&lt;/p&gt;

&lt;p&gt;And what if you have multiple extensions of different vendors installed. (That’s currently not an issue, since Coil is the only web monetization provider, but it might well become a problem in the future.)&lt;/p&gt;

&lt;p&gt;What about donating a one-time sum to a specific page? That would be great for newspaper sites, who could decide to open their content to anyone who tips at least, I don’t know, $0.50 or so. One question is how long these users would retain access to that content, and if it’s for more than just the current session, where the fact that they have paid for the content will be stored. There are privacy issues here.&lt;/p&gt;

&lt;p&gt;One question I have is if there should be a CSS way of showing extra content in addition to the JavaScript way. Something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media all and (monetization: monetized) {
    #extraContent {
        display: block;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sounds cool, but exactly when is a page monetized? When monetization has started (and the &lt;code&gt;monetizationstart&lt;/code&gt; event fires in JavaScript)? That sounds reasonable, but it may take a few seconds, so it may take a little while before the extra content becomes visible, which could lead to a jagged user experience. On the other hand, the current extra content scripts that use &lt;code&gt;monetizationstart&lt;/code&gt; have the same problem. A media query would not make things worse.&lt;/p&gt;

&lt;p&gt;I’m not saying that this is the greatest idea ever. Instead, I want to encourage you to think about a broad range of topics in order to figure out whether monetization, or the tools we have at our disposal, can be extended even more, and in which ways. Creative thinking is very useful in this phase of the specification.&lt;/p&gt;

&lt;h2&gt;
  
  
  The future of web monetization
&lt;/h2&gt;

&lt;p&gt;Still, new features are only part of the story. The other, and perhaps more exciting, part is how web monetization is going to develop in the future and how it will change the web.&lt;/p&gt;

&lt;p&gt;Stephanie Rieger wrote &lt;a href="https://yiibu.github.io/web-monetization/"&gt;a great paper&lt;/a&gt; about that future, and if you’re interested in web monetization beyond the details of the current implementation I recommend that you read it.&lt;/p&gt;

&lt;p&gt;I won’t attempt to summarize it here, but Stephanie’s main focus is describing three possible futures for web monetization and using these as a a lens to discuss some problems we have to solve.&lt;/p&gt;

&lt;p&gt;Will web monetization&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; allow the web to continue to work as it has in the past, just with more money for independent content creators? This is the most likely short-term outcome.&lt;/li&gt;
&lt;li&gt; lead to one or two large monetizers that maintain payment streams from users to creators, leading to tiered access system akin to cable TV that concentrates on in-network content, however that may be defined — but the definition is being done by these large monetizers.&lt;/li&gt;
&lt;li&gt; be extended to a complete virtual wallet system, where users may donate whatever they want, and monetization providers allow users to buy gift baskets with various tips. Also, there may be micro-subscriptions for a limited amount of time, or even donations for a specific image, phrase, or other bit of content — something you would retweet today.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Stephanie treats pros and cons of each model without extolling one over the others. It’s possible that one of her models is exactly on the mark, or that the future of monetization is found in a mix of these models.&lt;/p&gt;

&lt;p&gt;Above all, reading this paper allows you to think ahead and decide what kind of future you would prefer, and why. And that, more than the details of the current system, is what’s most important in this exciting start-up phase of Web Monetization.&lt;/p&gt;

</description>
      <category>webmonetization</category>
      <category>coil</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The Web Monetization meta tag and API</title>
      <dc:creator>Peter-Paul Koch</dc:creator>
      <pubDate>Tue, 06 Jul 2021 10:00:33 +0000</pubDate>
      <link>https://dev.to/coil/the-web-monetization-meta-tag-and-api-3eh9</link>
      <guid>https://dev.to/coil/the-web-monetization-meta-tag-and-api-3eh9</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/coil/let-s-talk-about-money-47i5"&gt;Part 1&lt;/a&gt; of this series made clear why web monetization is a good thing. &lt;a href="https://dev.to/coil/how-it-works-1b1"&gt;Part 2&lt;/a&gt; described the Coil system at high level. In this third article we're going to take a closer look at details: the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag and the JavaScript API.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developers.coil.com/"&gt;Coil developer site&lt;/a&gt; contains more information about technical topics, including a few example scripts.&lt;/p&gt;

&lt;h2&gt;
  
  
  The meta tag
&lt;/h2&gt;

&lt;p&gt;During the sign-up process for Coil and Interledger you set up a wallet, which enables you to receive payments. You are given a payment pointer for that wallet in the form &lt;code&gt;$url.of.server/someID&lt;/code&gt;. In order to monetize a page you should add a &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag on that page that contains this pointer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="monetization" content="$url.of.server/someID"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Right now you need tthe Coil extension to read out the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag — but in the future, when browsers support web monetization natively, they will do so themselves. If a page contains multiple monetization &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt;tags the extension uses the first one and ignores the others.&lt;/p&gt;

&lt;p&gt;All this works without JavaScript. Neither the current extension nor the future standard are reliant on scripting for the initiation of a payment stream. If you want to get any information, though, or if you want to change the payment stream’s direction, you need JavaScript.&lt;/p&gt;

&lt;p&gt;You can change the payment pointer by changing the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt;tag. It's ugly, but it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="monetization" content="$url.of.server/someID" id="paymentPointer"&amp;gt;

function changePointer() {
    let meta = document.querySelector('#paymentPointer');
    meta.setProperty('content','$url.of.server/myOtherID');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The plugin will pick up on this change even in the middle of a session and divert all future payments to the new payment pointer.&lt;/p&gt;

&lt;p&gt;One reason to do so is a collaborative article. If an article has, say, three authors, JavaScript could pick one of them at random and send the payment stream their way. Technically, you do this by switching the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt;tag's content, as shown above. See &lt;a href="https://webmonetization.org/docs/probabilistic-rev-sharing/"&gt;this article&lt;/a&gt; for more information.&lt;/p&gt;

&lt;p&gt;You could also use the Intersection Observer to figure out which page element is in view right now, and change the payment pointer based on that information. This could be useful if one page shows art by several creators, for instance. &lt;a href="https://coil.com/p/sabinebertram/Web-Monetized-Image-Gallery-Intersection-Observer-Demo-/HY5nl9NT"&gt;This article&lt;/a&gt; gives an overview and a code example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Future: link
&lt;/h3&gt;

&lt;p&gt;In the future specification the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag will likely change to a link tag, like this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link rel="monetization" content="https://url.of.server/someID"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reasons are complex and can be &lt;a href="https://github.com/WICG/webmonetization/issues/19#issuecomment-705407129"&gt;read here&lt;/a&gt;. The &lt;a href="https://community.webmonetization.org/wmfirefox/exploring-integration-of-web-monetization-into-the-web-platform-grant-report-1-5ama"&gt;upcoming Firefox implementation&lt;/a&gt; uses this link, and not a &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That means that in the future any script that changes the payment pointer has to be rewritten, possibly changing the pointer in both the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; and the link tag. For that reason it would be nicer if the JavaScript API offered a direct, imperative way of setting the pointer, like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.monetization.pointer = '$url.of.server/someOtherID';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Right now the API doesn’t support this, although it is one of the many ideas &lt;a href="https://github.com/wicg/webmonetization/issues/"&gt;under discussion&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript API
&lt;/h2&gt;

&lt;p&gt;Since we’re on the topic anyway, let’s discuss the &lt;a href="https://webmonetization.org/docs/api/"&gt;JavaScript API&lt;/a&gt;. It’s a light-weight, useful thing to have in your back pocket while messing about with payment streams. It consists of the &lt;code&gt;document.monetization&lt;/code&gt; container, three events, and one property.&lt;/p&gt;

&lt;p&gt;This API is part of the proposed standard, and if browsers start supporting web monetization natively they’ll take over this API as well. In that sense, current extension serves as a polyfill and scripts you write now will continue to work in the future.&lt;/p&gt;

&lt;h3&gt;
  
  
  document.monetization
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;document.monetization&lt;/code&gt; is the container for all API functionality, and its presence indicates that your current visitor supports monetization:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (document.monetization) {
    // user may monetize you;
    // find out and do something
} else {
    // user is certain not to monetize you
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;document.monetization&lt;/code&gt; is a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; DOM node that is not inserted into the document. Thus you can read &lt;code&gt;document.monetization.nodeName&lt;/code&gt; and most other DOM properties, even though there is no practical reason to do so.&lt;/p&gt;

&lt;p&gt;Making it a DOM node allows the firing of the custom monetization events we’ll treat in a moment. Without this trick it appears to be quite difficult to fire custom events from extensions, though specific information is surprisingly hard to find.&lt;/p&gt;

&lt;h3&gt;
  
  
  state
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;document.monetization.state&lt;/code&gt; contains information about the current monetization state. It can take three values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;started&lt;/code&gt;: a monetization stream has started and you will receive money. At least one valid Interledger package has been received.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pending&lt;/code&gt;: a monetization stream has not yet started, but the extension is trying to connect.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;stopped&lt;/code&gt;: no monetization stream possible: the page has no &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag, or the pointer is invalid.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If no &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag is found the initial state is &lt;code&gt;stopped&lt;/code&gt;. If a &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag is present the initial state is &lt;code&gt;pending&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag contains no valid payment pointer the state becomes &lt;code&gt;stopped&lt;/code&gt;. If a valid payment pointer is present the extension connects to the Interledger server and waits for the first package. Once that package arrives the state becomes &lt;code&gt;started&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The state remains &lt;code&gt;started&lt;/code&gt; even if the connection drops — the extension keeps track of the time spent on the site, after all.&lt;/p&gt;

&lt;p&gt;If you change the payment pointer the extension first goes to &lt;code&gt;pending&lt;/code&gt; and then to either &lt;code&gt;started&lt;/code&gt; or &lt;code&gt;stopped&lt;/code&gt;, depending on the validity of the new pointer.&lt;/p&gt;

&lt;p&gt;So this snippet tells you if the user is currently paying you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (document.monetization &amp;amp;&amp;amp; document.monetization.state === 'started') {
    // user is currently paying you
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Events
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;document.monetization&lt;/code&gt; allows you to capture four events, three of which mirror the &lt;code&gt;state&lt;/code&gt; property pretty closely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;monetizationpending&lt;/code&gt;: a monetization stream is being started up, but is not sending payments yet. Fires when the &lt;code&gt;state&lt;/code&gt; is set to &lt;code&gt;pending&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;monetizationstart&lt;/code&gt;: a monetization stream has started. Fires when the &lt;code&gt;state&lt;/code&gt; is set to &lt;code&gt;started&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;monetizationprogress&lt;/code&gt;: a new single payment has arrived. See below.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;monetizationstop&lt;/code&gt;: a monetization stream has stopped. Fires when the &lt;code&gt;state&lt;/code&gt; is set to &lt;code&gt;stopped&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Typically, when a payer enters a payee’s page and a &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag is present. the &lt;code&gt;monetizationpending&lt;/code&gt; event will fire, followed by a &lt;code&gt;monetizationstart&lt;/code&gt; event and an indeterminate amount of &lt;code&gt;monetizationprogress&lt;/code&gt; events. If the payment pointer is invalid &lt;code&gt;monetizationstop&lt;/code&gt; fires.&lt;/p&gt;

&lt;p&gt;This is exactly the same sequence as with the &lt;code&gt;state&lt;/code&gt; property, except that no event will fire if no &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag is present. The sequence restarts at &lt;code&gt;pending&lt;/code&gt; whenever you change the payment pointer.&lt;/p&gt;

&lt;p&gt;The information the events deliver allows you to build a basic script to show/hide extra content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (document.monetization) {
    let extraContent = document.querySelector('#extraContent');
    document.monetization.addEventListener('monetizationstart',function() {
        extraContent.style.display = 'block'; 
        // or any other way of showing content
    });
    document.monetization.addEventListener('monetizationstop',function() {
        extraContent.style.display = 'none'; 
    });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, this script is fairly easy to hack, and won't work without JavaScript being enabled. It’s not suited for serious use, especially not in web development sites. Still, it serves as an example of using the monetization events.&lt;/p&gt;

&lt;h3&gt;
  
  
  monetizationprogress
&lt;/h3&gt;

&lt;p&gt;The monetizartionprogress event fires whenever an Interledge package with a non-zero sum arrives from the Coil servers, which is generally every second or so. It contains information about the amount that's been paid so far, and you could use it to build a &lt;a href="https://webmonetization.org/docs/counter/"&gt;micropayment counter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If the connection drops the payment stream also drops and the monetizationprogress event stops firing. If the connection is restored the event resumes after a new connection to the Interledger server has been made. As we saw before, the extension keeps track of the time the user has spent on your site, and the first payment after the restoration of the connection will pay for that entire time. Thus, you cannot assume that the payer stopped paying just because monetizationprogress stops firing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Event properties
&lt;/h3&gt;

&lt;p&gt;If you want to find out wha the current payment status is you can use the special properties of these events. All these are properties of &lt;code&gt;event.detail&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;amount&lt;/code&gt; is the amount contained in the current Interledger package, as an integer.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;assetCode&lt;/code&gt; is a code for the currency, either a cryptocurrency or a real one.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;assetScale&lt;/code&gt; is the number of places past the decimal for the amount. This serves to keep &lt;code&gt;amount&lt;/code&gt; an integer.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;paymentPointer&lt;/code&gt; is the payment pointer the extension read from the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;receipt&lt;/code&gt; is a proof of payment sent back to the payer.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;requestID&lt;/code&gt; is a transient ID temporarily assigned to your payment stream.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For instance, this gives you the amount the last package delivered:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.monetization.addEventListener('monetizationprogress',function(e){
    let amt = e.detail.amount;
    let scale = e.detail.assetScale;
    let code = e.detail.assetCode;
    let amount = amt * Math.pow(10,-scale);
    let printableAmount = code + ' ' + amount;
    // do something with amount or printableAmount
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;paymentPointer&lt;/code&gt; contains the same information as the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag. &lt;code&gt;receipt&lt;/code&gt; and &lt;code&gt;requestID&lt;/code&gt; contain values that are internal to the Interledger packages. You can use it to write a &lt;a href="https://webmonetization.org/docs/receipt-verifier/"&gt;receipt verifyer&lt;/a&gt; if you like.&lt;/p&gt;

&lt;p&gt;Reading out the amount of money an Interledger package contains requires the amount-related properties. For instance, if &lt;code&gt;amount&lt;/code&gt; is 17 and &lt;code&gt;assetScale&lt;/code&gt; is 3 you received 17*10^-3, or 0.017, of the currency indicated in &lt;code&gt;assetCode&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That concludes our study of the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag and API. In the &lt;a href="https://dev.to/coil/the-future-of-web-monetization-2n3"&gt;final part&lt;/a&gt; we’ll take a look at web monetization’s future, which includes a formal W3C standard.&lt;/p&gt;

</description>
      <category>webmonetization</category>
      <category>coil</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How Coil works</title>
      <dc:creator>Peter-Paul Koch</dc:creator>
      <pubDate>Tue, 29 Jun 2021 10:07:16 +0000</pubDate>
      <link>https://dev.to/coil/how-it-works-1b1</link>
      <guid>https://dev.to/coil/how-it-works-1b1</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/coil/let-s-talk-about-money-47i5"&gt;Part 1&lt;/a&gt; of this series made clear why web monetization is a good thing and we web developers should start paying for our articles and documentation. In this second article we’ll take a look at how Coil works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Register with Coil
&lt;/h2&gt;

&lt;p&gt;First, both payer and payee should register with Coil. Unfortunately, for payees this process is not yet as streamlined as it could be.&lt;/p&gt;

&lt;p&gt;For now payees need to register both with Coil and with an Interledger-enabled wallet where you can receive payments. This double sign-up is annoying, and you need to remember both sets of credentials. Coil is working on integrating the Interledger part into its service, but this integration has not yet finished at the time of writing.&lt;/p&gt;

&lt;p&gt;And what, you might ask, is Interledger? It is &lt;a href="https://interledger.org/"&gt;an open protocol&lt;/a&gt; for exchanging money - initially between cryptocurrency servers, but now also to regular bank accounts. This series will not treat Interledger in more detail, but it is the technical basis for any web monetization system, Coil and all future ones. Stephanie Rieger wrote a great, non-technical &lt;a href="https://yiibu.github.io/web-monetization/the-present/what-is-the-interledger-protocol/"&gt;introduction to Interledger&lt;/a&gt; for those who are interested.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Add meta tag
&lt;/h2&gt;

&lt;p&gt;During sign-up payees are given a payment pointer for that wallet in the form &lt;code&gt;$url.of.server/someID&lt;/code&gt;. You should insert a &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag into each page that you want to monetize, like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="monetization" content="$url.of.server/someID"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells Coil where to send payments to. We’ll take a closer look at this &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag in the next part of this series.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Install extension
&lt;/h2&gt;

&lt;p&gt;The payer should &lt;a href="https://help.coil.com/docs/membership/coil-extension/index.html"&gt;install&lt;/a&gt; the Coil extension in order to actually pay money.&lt;/p&gt;

&lt;p&gt;The only browser to support the draft Web Monetization specification is the Gecko-based &lt;a href="https://www.pumabrowser.com/"&gt;Puma Browser&lt;/a&gt; for Android. Until more browsers support the standard natively you will have to use an &lt;a href="https://help.coil.com/docs/membership/coil-extension/index.html"&gt;extension&lt;/a&gt;. A Safari extension is not yet available, but all other major browsers have one.&lt;/p&gt;

&lt;p&gt;The extension works with HTTPS and HTTP connections, but not with FILE connections — something to keep in mind during testing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Restrict content
&lt;/h2&gt;

&lt;p&gt;The payee can offer extra content to paying visitors. In the future this might become a vital feature. For instance, you could decide that your blog posts are only visible to users that pay you for the first two weeks or so, after which the paywall will be removed. Or you may keep access to some vital articles restricted to paying users forever.&lt;/p&gt;

&lt;p&gt;At the moment hiding content can only be done via a fairly easy to hack &lt;a href="https://webmonetization.org/docs/exclusive-content/"&gt;scripting solution&lt;/a&gt; that we’ll take a closer look at in the next part. A server-side solution is not yet available at the time of writing, though Coil is aware of its importance.&lt;/p&gt;

&lt;p&gt;Coil created a &lt;a href="https://wordpress.org/plugins/coil-web-monetization/"&gt;Wordpress plugin&lt;/a&gt;, and more plugins for other systems are in the works. Still, the most important feature would be a server-side solution to detect the presence of a monetization stream, so that the server can decide whether to send extra content or not. This feature is lacking as of right now, and the Wordpress plugin also relies on JavaScript to show and hide extra content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Privacy
&lt;/h2&gt;

&lt;p&gt;Coil is serious about privacy. It retains the minimum amount of data it needs to function. It needs to know who you are for its core service (duh) but does not divulge that information to anyone you pay or anyone who pays you. Every payment you make is an anonymous transaction.&lt;/p&gt;

&lt;p&gt;The extension you install in your browser must be able to see the Interledger wallet it should pay to (duh), but does not store the URLs of sites you visited. The payee does not get any information about you, either, except for the amount of money you paid.&lt;/p&gt;

&lt;p&gt;The extension needs permission to read your browsing history. For obscure reasons this is necessary to deliver payments. Coil does not actually read your browser history.&lt;/p&gt;

&lt;p&gt;For more information you should read the &lt;a href="https://help.coil.com/docs/general-info/privacy-policy/index.html"&gt;Coil privacy statement&lt;/a&gt;, which is one of the clearest ones I've ever read.&lt;/p&gt;

&lt;h2&gt;
  
  
  The payment stream
&lt;/h2&gt;

&lt;p&gt;If you added the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag to your site, and a user with the Coil extension visits you, you're getting paid. How much? How does it work?&lt;/p&gt;

&lt;p&gt;Coil pays out US$0.36 per hour for every visitor of your site. That's not a huge amount of money, but if several thousands of people visit your page for 10 minutes each ... well, you can do the math. Web monetization is about a large number of people paying a small amount each.&lt;/p&gt;

&lt;p&gt;There's a catch here. All payers give Coil a fixed amount per month, currently US$5, and if Coil has spent that amount they can give no more. In order to prevent sites you visit later in your billing month getting nothing, Coil starts throttling the payer's payments once $4.50 is spent, and pays a lower amount.&lt;/p&gt;

&lt;p&gt;Coil intentionally pays a flat rate. If payers or payees would be able to set prices they would initiate a race to the bottom, where payees would ask for less and less money in order to attract more payers, while payers would cap their payments at the lowest possible level. Since this state of affairs is almost indistinguishable from the current free-content model, Coil decided to short-circuit it by establishing flat rates. See &lt;a href="https://github.com/WICG/webmonetization/issues/139"&gt;this discussion&lt;/a&gt; for more informtion.&lt;/p&gt;

&lt;p&gt;Technically, every second or so the extension sends out an Interledger request and, ideally, receives a positive response. At that time a tiny amount is transferred from payer to payee. This process does not need JavaScript to run, though there are JavaScript events that allow you to monitor the process. We’ll get back to those in the next part.&lt;/p&gt;

&lt;p&gt;For each request the extension reads out the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag anew. Thus, if the tag's contents have been changed in the mean time, the extension automatically redirects the payment stream to the new ID.&lt;/p&gt;

&lt;p&gt;If the payer loses their connection the payment stream will stop, but the extension will remember how much time the payer spent on the payee's site. Once the connection is restored the extension will calculate the balance and send out an Interledger request for that amount. This information is lost if the payer closes their browser window before the connection is restored, however.&lt;/p&gt;

&lt;p&gt;If a monetized page disappears into the background, for instance because the user opens another tab, the payment stream is supposed to stop, only to resume when the user brings the page to the foreground. However, my tests indicate that this is not actually the case, and that the payment stream continues even while the page is in the background. This is an unsolved problem at the time of writing — maybe my tests are incorrect; maybe it’s a bug in the extension; maybe the payment stream is supposed to continue.&lt;/p&gt;

&lt;p&gt;Now we have a bird’s eye overview of how Coil works. &lt;a href="https://dev.to/coil/the-web-monetization-meta-tag-and-api-3eh9"&gt;Part 3&lt;/a&gt; will describe the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag and the JavaScript API, and in &lt;a href="https://dev.to/coil/the-future-of-web-monetization-2n3"&gt;part 4&lt;/a&gt; we’ll take a look at the future, which includes a formal W3C standard.&lt;/p&gt;

</description>
      <category>webmonetization</category>
      <category>coil</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Let's talk about money</title>
      <dc:creator>Peter-Paul Koch</dc:creator>
      <pubDate>Tue, 22 Jun 2021 09:38:10 +0000</pubDate>
      <link>https://dev.to/coil/let-s-talk-about-money-47i5</link>
      <guid>https://dev.to/coil/let-s-talk-about-money-47i5</guid>
      <description>&lt;p&gt;Let's talk about money!&lt;/p&gt;

&lt;p&gt;Let's talk about how hard it is to pay small amounts online to people whose work you like and who could really use a bit of income. Let's talk about how &lt;a href="https://coil.com"&gt;Coil&lt;/a&gt; aims to change that.&lt;/p&gt;

&lt;p&gt;Taking a subscription to a website is moderately easy, but the person you want to pay must have enabled them. Besides, do you want to purchase a full subscription in order to read one or two articles per month?&lt;/p&gt;

&lt;p&gt;Sending a one-time donation is pretty easy as well, but, again, the site owner must have enabled them. And even then it just gives them ad-hoc amounts that they cannot depend on.&lt;/p&gt;

&lt;p&gt;Then there's Patreon and Kickstarter and similar systems, but Patreon is essentially a subscription service while Kickstarter is essentially a one-time donation service, except that both keep part of the money you donate.&lt;/p&gt;

&lt;p&gt;And then there’s ads ... Do we want small content creators to remain dependent on ads and thus support the entire ad ecosystem? I, personally, would like to get rid of them.&lt;/p&gt;

&lt;p&gt;The problem today is that all non-ad-based systems require you to make conscious decisions to support someone — and even if you’re serious about supporting them you may forget to send in a monthly donation or to renew your subscription. It sort-of works, but the user experience can be improved rather dramatically.&lt;/p&gt;

&lt;p&gt;That’s where Coil and the Web Monetization Standard come in.&lt;/p&gt;

&lt;h3&gt;
  
  
  Web Monetization
&lt;/h3&gt;

&lt;p&gt;The idea behind Coil is that you pay for what you consume easily and automatically. It's not a subscription - you only pay for what you consume. It's not a one-time donation, either - you always pay when you consume.&lt;/p&gt;

&lt;p&gt;Payments occur automatically when you visit a website that is also subscribed to Coil, and the amount you pay to a single site owner depends on the time you spend on the site. Coil does not retain any of your money, either — everything goes to the people you support.&lt;/p&gt;

&lt;p&gt;In this series of four articles we'll take a closer look at the architecture of the current Coil implementation, how to work with it right now, the proposed standard, and what's going to happen in the future.&lt;/p&gt;

&lt;h3&gt;
  
  
  Overview
&lt;/h3&gt;

&lt;p&gt;So how does Coil work right now?&lt;/p&gt;

&lt;p&gt;Both the payer and the payee need a Coil account to send and receive money. The payee has to add a &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag with a Coil payment pointer to all pages they want to monetize. The payer has to install the Coil extension in their browsers. You can see this extension as a polyfill. In the future web monetization will, I hope, be supported natively in all browsers.&lt;/p&gt;

&lt;p&gt;Once that's done the process works pretty much automatically. The extension searches for the &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tag on any site the user visits. If it finds one it starts a payment stream from payer to payee that continues for as long as the payer stays on the site.&lt;/p&gt;

&lt;p&gt;The payee can use the JavaScript API to interact with the monetization stream. For instance, they can &lt;a href="https://webmonetization.org/docs/exclusive-content/"&gt;show extra content&lt;/a&gt; to paying users, or &lt;a href="https://webmonetization.org/docs/counter/"&gt;keep track&lt;/a&gt; of how much a user paid so far. Unfortunately these functionalities require JavaScript, and the hiding of content is fairly easy to work around. Thus it is not yet suited for serious business purposes, especially in web development circles.&lt;/p&gt;

&lt;p&gt;This is one example of how the current system is still a bit rough around the edges. You’ll find more examples in the subsequent articles. Until the time browsers support the standard natively and you can determine your visitors’ monetization status server-side these rough bits will continue to exist. For the moment we will have to work with the system we have.&lt;/p&gt;

&lt;p&gt;This article series will discuss all topics we touched on in more detail.&lt;/p&gt;

&lt;h3&gt;
  
  
  Start now!
&lt;/h3&gt;

&lt;p&gt;For too long we have accepted free content as our birthright, without considering the needs of the people who create it. This becomes even more curious for articles and documentation that are absolutely vital to our work as web developers.&lt;/p&gt;

&lt;p&gt;Take a look at &lt;a href="https://developers.coil.com/community/who-is-web-monetized"&gt;this list&lt;/a&gt; of currently-monetized web developer sites. Chances are you'll find a few people whose work you used in the past. Don't they deserve your direct support?&lt;/p&gt;

&lt;p&gt;Free content is not a right, it's an entitlement. The sooner we internalize this, and start paying independent voices, the better for the web.&lt;/p&gt;

&lt;p&gt;The only alternative is that all articles and documentation that we depend on will written by employees of large companies. And employees, no matter how well-meaning, will reflect the priorities and point of view of their employer in the long run.&lt;/p&gt;

&lt;p&gt;So start now.&lt;/p&gt;

&lt;p&gt;In order to support them you should invest a bit of time once and US$5 per month permanently. I mean, that’s not too much to ask, is it?&lt;/p&gt;

&lt;p&gt;Set up a Coil account (which must include a wallet account). &lt;a href="https://hammedbabatunde.hashnode.dev/monetizing-your-contents-as-a-content-creator"&gt;This article&lt;/a&gt; offers the best overview of the two-step process. Then &lt;a href="https://help.coil.com/docs/membership/coil-extension/index.html"&gt;install&lt;/a&gt; the Coil extension in your browsers. A Safari extension is not yet available.&lt;/p&gt;

&lt;p&gt;Then read on about how Coil actually works. In &lt;a href="https://dev.to/coil/how-it-works-1b1"&gt;part 2&lt;/a&gt; we will present a high-level overview of how Coil works right now. &lt;a href="https://dev.to/coil/the-web-monetization-meta-tag-and-api-3eh9"&gt;Part 3&lt;/a&gt; will describe all those pesky details you need to know, and in &lt;a href="https://dev.to/coil/the-future-of-web-monetization-2n3"&gt;part 4&lt;/a&gt; we’ll take a look at the future, which includes a formal W3C standard.&lt;/p&gt;

</description>
      <category>webmonetization</category>
      <category>coil</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
