[w3c/payment-handler] SW registration code unclear/incorrect (#223)

The sample service worker registration code included in the spec is potentially misleading in that it gives the impression that a payment handler is ready to handle payments before it actually is.

The registration example code at https://w3c.github.io/payment-handler/#register-example registers a service worker in a typical way:

```js
  const { registration } = await navigator.serviceWorker.register('/sw.js');
  await addInstruments(registration);
```

My understanding is that after these two lines have been executed, the service worker defined in `sw.js` is not necessarily active: the service worker controlling the page may be a previous service worker (one not able to handle payment-specific events such as `onpaymentrequest`) and therefore at this point it would *not* be appropriate to tell that user that they can e.g. "Now Pay with Bob Pay."

Whilst the sample code doesn't not explicitly make this claim, I think many readers unfamiliar with the details of the service worker lifecycle would assume that after the service worker is registered and instruments added, the user is ready to go with Bob Pay. Instead, a [more complicated algorithm](https://github.com/w3c/ServiceWorker/issues/770) must be followed to determine the point at which `sw.js` is active.

/cc @jakearchibald

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/payment-handler/issues/223

Received on Monday, 20 November 2017 13:53:38 UTC