Re: [w3c/push-api] Retry push event (#300)

> To that end the specification doesn't detail how userVisibleOnly works or what the conditions are - those are implementation specific.

I think that you should define that to avoid future problems...

Example: We decide to use Background Sync to fetch and display the notifications (the `sync` is registered from the `push` event). It works. It also respects privacy and **complies with the spec**, by displaying some notifications. Then arrives a new browser vendor (e.g. Apple) or simply a new browser version which has a different interpretation of your spec and breaks our system. Is that a browser bug? Or is that a bug of our system? **Who should fix that?**

> Because of the asynchronous and ephemeral nature of Service Workers, this actually is a really hard problem

I think that current browser implementation of `userVisibleOnly` are already using similar techniques... If you try to trigger some `push` without displaying notifications browsers will not complain. Even Chrome, as you may know, has greatly relaxed the restrictions about `userVisibleOnly`. 

In general I don't think that it is a big problem to attach two counters to a service worker registration in order to detect the number of push events and number of notification displayed. Even one counter is enough if you prefer... you can use +1 and -1 on the same counter and you make sure that it stays in a range around zero (e.g. [0, 10]). If a websites goes out of that range then you display a default notification to the user that informs him that the website is running in background...

What are the **pros**? You can process the `push` event the way you want... (e.g. using reliable technologies like Background sync or other future technologies)

What are the **cons**? I don't see any problem. Privacy is preserved because a website cannot run in background without displaying notifications.

IMHO if you don't allow to do that in the spec, the only effect will be to have worst code with the exact same effects (also for privacy!). 

If you follow my suggestion, then developers can use this confidently:

```
self.addEventListener('push', function(event) { 
  sync.register('downloadAndDisplayNotifications');
});
```

Otherwise they will write this (same effect as above... bad code):

```
self.addEventListener('push', function(event) { 
  try {
    downloadAndDisplayNotifications()
  } catch(error) { // catch network error
    sync.register('downloadAndDisplayNotifications');
  }
});
``` 


-- 
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/push-api/issues/300#issuecomment-419940133

Received on Monday, 10 September 2018 14:48:06 UTC