-
Notifications
You must be signed in to change notification settings - Fork 42
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
SW registration code unclear/incorrect #223
Comments
Absolutely. As far as I remember, that part was in the spec, but it seems to be removed now[1]. I guess that it was just a mistake that it was removed. When we moved from PaymentApp API to PaymentHandler API, there are much changes. So, it's just missed. (I think) @ianbjacobs, Is there any special reason why the spec text was removed? [1] https://github.com/w3c/payment-handler/pull/107/files#diff-eacf331f0ffc35d4b482f1d15a887d3bL828 |
Hi all, @romandev, I suspect any changes to code that created problems are mistakes. :) I suggest that you and @rsolomakhin look at the code and fix / restore anything that's needed. (I am not sure to be of much help here.) Ian |
@ianbjacobs Thank you. |
navigator.serviceWorker.register('/sw.js');
const registration = await navigator.serviceWorker.ready;
await addInstruments(registration); …should be fine. Btw, |
@romandev Thank you for volunteering the send the the pull request to the spec. Chromium/Blink implementation is already correct. I had to use the |
Like other service worker family features, we should only allow instrument.set() in active service worker. This fixes w3c#223 issue.
Like other service worker family features, we should only allow instrument.set() in active service worker. This fixes w3c#223 issue.
Like other service worker family features, we should only allow instrument.set() in active service worker. This fixes w3c#223 issue.
@rsolomakhin, is this issue still relevant? Ian |
According to w3c/ServiceWorker#920, they decided not to wait until active worker. We should use |
Thank you @romandev |
Like other service worker family features, we should only allow instrument.set() in active service worker. This fixes w3c#223 issue.
Like other service worker family features, we should only allow instrument.set() in active service worker. This fixes #223 issue.
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:
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 asonpaymentrequest
) 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 must be followed to determine the point at which
sw.js
is active./cc @jakearchibald
The text was updated successfully, but these errors were encountered: