-
Couldn't load subscription status.
- Fork 41
Open
Description
Introduction
Currently, there are some known issues in openWindow() API.
- First, when window client's focus state is changed, it's not clear how it works.
- Tab switching
- Explicit
windowClient.focus()calls
- Second, in SW side, there is no way to detect that opened window's state is changed.
- The
pagevisibilitychange,beforeunloadevents are unhelpful. (Normative what happens when users closing the window opened by PaymentRequestEvent.openWindow #299) - For example, when users click
Xbutton, if the opened window can not send a response to SW, thenrespondWith()'s input promise may be pending forever during SW life time.
- The
- Third, when users click
refreshbutton, the input data (coming from SW to window) may be lost.- For example, users might unintentially use
pull to refreshduring scrolling page on Chrome mobile. In the opened window, PH authors can try to store the receive data to persistent storage(e.g. Indexed DB) but the refresh might happen before finishing to store the data.
- For example, users might unintentially use
Proposal
I'd suggest changing a shape of openWindow API. (based on #97)
Before
Promise<WindowClient> openWindow(USVString url);After
Promise<PaymentHandlerResponse> openWindow(USVString url, optional object data);Additionally, we will have to define the following interfaces to use in opened window.
partial interface Navigator {
[SecureContext, SameObject] readonly attribute PaymentHandlerContainer paymentHandler;
};
[SecureContext, Exposed=Window]
interface PaymentHandlerContainer {
readonly attribute object data;
void providerResponse(PaymentHandlerResponse response);
};PaymentHandlerContainershould be exposed to opened window only.PaymentHandlerContainer.datashould be synced with thedatapassed in when callingopenWindow().PaymentHandlerContainer.providerResponse()is only allowed in opened window and when it is called, should resolveopenWindow()'s result promise.
Example
SW side
self.addEventListener('paymentrequest', e => {
e.respondWith(e.openWindow('...', {
id: 'xxxxx',
param1: 'param1',
param2: 'param2',
}));
});Opened window
window.addEventListener('load', e => {
assert 'xxxxx' === navigator.paymentHandler.data.id;
assert 'param1' === navigator.paymentHandler.data.param1;
assert 'param2' === navigator.paymentHandler.data.param2;
...
navigator.paymentHandler.provideResponse({
method: 'basic-card',
data: {}
});
});WDYT?
/cc @rsolomakhin, @gogerald
Metadata
Metadata
Assignees
Labels
No labels