Open stefhak opened 8 years ago
If the service worker is running while a page is open it can just proxy this request, no? If the service worker is running while there's no page open, there's a problem. I don't think we're quite ready yet for user interface to go into workers (if ever).
I was thinking about the second situation (page closed). The SW could check if the page has obtained persistent permission for the origin to use persist()
by using the Permission API, and if so call persist()
(but not if the permission state is prompt
). In fact, persist()
could just fail if called from a Worker if there is no stored permission to use it. Just a thought.
I agree, UI in workers is not something we should do.
So at the time the user gave permission or the user agent determined the origin should get permission, there was no open page? I guess that's something we could consider...
Exactly, that's the scenario.
Why can't the page do this as part of setting up push?
The use case is using a ServiceWorker to fetch and store objects (e.g. as a reaction on a web push) to have them ready when the user visits the site. Having the objects persisted would be an advantage. I understand the issue of a ServiceWorker prompting the user for permission, but can't that be sorted by having the web page asking for persisted permission to persist, and that is also valid for the SW script (having the same origin)? The SW script could then check using the permission API if it has permission to persist(), and skip calling persist() if not.