Re: [w3c/payment-handler] Suggest changing a shape of openWindow() (#300)

> For 'providerResponse', it looks a little redundant to me since the service worker spec allows service worker and its controlled window to contact each other at any moment and developers may have been familiar with it. So I would not introduce new things to keep our spec and implementation simple, and less diverted.

I have a better idea. If we just make `openWindow()`'s `return` promise wait to close the opened window, we can resolve the second issue easily with minimal change. I'll make a patch in Chromium/Blink quickly and then show you.

**Before**
```webidl
Promise<WindowClient> openWindow(USVString url);
```
**After**
```webidl
Promise<void> openWindow(USVString url);
```
**Example**
```js
var paymentResult;

self.addEventListener('message', e => {
  if (!e.data) return;

  if (e.data.action === 'init') {
    e.source.postMessage({ ... });
  } else if (e.data.action === 'response') {
    paymentResult = e.data.responseData;
  }
});

self.addEventListener('paymentrequest', e => {
  e.waitUntil(async() => {
    // The following code should wait to close the opened window
    await e.openWindow("...");

    // If paymentResult is undefined, payment request will be aborted in merchant side.
    // If paymentResult has correct data, payment request will be succeeded.
    await e.respondWith(paymentResult);
  });
});
```

-- 
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/300#issuecomment-393454553

Received on Thursday, 31 May 2018 08:28:51 UTC