Skip to content
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

Periodic Background Sync #367

Closed
1 of 3 tasks
mugdhalakhani opened this issue Apr 29, 2019 · 27 comments
Closed
1 of 3 tasks

Periodic Background Sync #367

mugdhalakhani opened this issue Apr 29, 2019 · 27 comments
Assignees
Labels
Progress: propose closing we think it should be closed but are waiting on some feedback or consensus Provenance: Fugu Review type: Already shipped Already shipped in at least one browser Topic: fetch and preload Things that live on top of (but close to) networking. Topic: powerful APIs APIs that reach into your life. Topic: privacy Venue: WICG

Comments

@mugdhalakhani
Copy link

mugdhalakhani commented Apr 29, 2019

Góðan dag TAG!

I'm requesting a TAG review of:

You should also know that...
The spec is in review, so this is more of an opportunity to review the proposed API.

We'd prefer the TAG provide feedback as (please select one):

  • open issues in our GitHub repo for each point of feedback
  • open a single issue in our GitHub repo for the entire review
  • leave review feedback as a comment in this issue and @-notify [github usernames]
@lknik lknik added Progress: unreviewed Review type: CG early review An early review of general direction from a Community Group and removed Progress: untriaged labels May 22, 2019
@ylafon ylafon added Topic: fetch and preload Things that live on top of (but close to) networking. Needs spec and removed Needs spec labels May 22, 2019
@kenchris kenchris added Topic: powerful APIs APIs that reach into your life. Missing: venue and removed Needs spec labels May 22, 2019
@lknik
Copy link
Member

lknik commented May 22, 2019

Discussed in Reykjavik.

I see there is an initial privacy writeup (happy it's started) + permission. Permissions by default?

@kenchris
Copy link

The explainer talks about the browser being able to respect 'do not disturb' - would it also be able/intended to respect metered connections/roaming and power save mode? Would be good to add to the explainer then

@mugdhalakhani
Copy link
Author

Thanks!

We've exposed a periodic-background-sync permission through the Permissions API. Using that permission may show a permission request to the user, depending on the browser implementation. The feature must only be available on secure origins, and may be further restricted to installed web apps only, based on the browser implementation.
The frequency of the periodic task is decided by the browser, and the browser may base that on the user's engagement with the site.

Notifications are suppressed by the OS in DND mode, and so we don't feel that the Periodic Background Sync spec needs to define any special treatment of DND. Please let us know if you disagree.

Regarding changing behavior on metered connections and in power save mode, we're of the opinion that this should be by way of guidance, rather than a requirement.
Implementations should be conservative about data usage on metered networks, and should respect the device's battery saving mode, if it has one. The browser implementation is better positioned to make these decisions, based on the unique requirements of the user. For instance, data plans are becoming cheap in India and not everyone has access to wifi. So disabling the feature on mobile networks might not be the right decision for that demographic.

I'm happy to include words to that effect in the explainer. I'll update it soon. :)

Thanks for the feedback!

@cherukumilli
Copy link

@mugdhalakhani
Does this feature work on an installed app on desktops OS'es like Mac OS? or is this feature limited to only Andriod OS?

@mugdhalakhani
Copy link
Author

It'll work for PWAs on Desktop as well.

@hadleybeeman
Copy link
Member

Thanks for this, @mugdhalakhani! We're looking at this in our face-to-face TAG meeting in Tokyo.

We're curious about your thoughts on @kenchris's question. If the user can't specify behaviour on things like battery life and metered connections, is that going to confuse the user? We are thinking specifically about the example of tethering on your phone, where your browser assumes it's on a fat pipe while in fact you want the connection to use as little data as possible. We'd welcome your thoughts.

And we're happy to see that you've exposed the permissions through the Permissions API. It also raises the question though about what happens in browsers that haven't implemented the Permissions API? Also, how should a user revoke the permission? (Revoking is linked to the previous paragraph too.)

@mugdhalakhani
Copy link
Author

Thanks for the question Hadley.

We have to distinguish between controls the developer has for this API, and those the user does. Our reasoning is that the developer can't reliably differentiate a metered connection from an unmetered one, any better than the browser can. The browser doesn't need to rely on the developer correctly setting these levers when it can detect these situations itself.

You are right that there may be cases when the browser might not detect the type of connection correctly, like the tethering example you gave.
The user can, through mechanisms such as turning on "Data Saver" mode, indicate to all apps on the device that data should be consumed conservatively. It is recommended that the browser not send periodicsync events when in Data Saver mode and connected to cellular networks. (see bug for Chrome here: https://bugs.chromium.org/p/chromium/issues/detail?id=529351)
I've sent a PR to the explainer to include this recommendation, thanks for pointing it out:
beverloo/periodic-background-sync#16

Regarding your other question, note that Permissions API is simply a way for the developer to query the status of this permission through Javascript. A user prompt may or may not be shown to the user, depending on the browser implementation. Chrome's current implementation automatically denies 'periodic-background-sync' for any request made from outside a PWA and no user prompt is shown. My point is that even if the browser has an implementation of the Permissions API, the user might not be prompted for a permission.

However, the spec can mandate that the user or the user agent on behalf of the user grant permission before this API can be used. (I'm looking at https://notifications.spec.whatwg.org/#permission-model for inspiration). I've proposed adding words to this effect in the PR as well:
beverloo/periodic-background-sync#16

How to revoke the permission is again browser implementation dependent and will be done through the browser's UI. The Permission API spec mandates that the browser implementation must notify the appropriate components when the user revokes permission for a capability for a site.
(https://www.w3.org/TR/permissions/#reacting-to-revocation)

@mugdhalakhani
Copy link
Author

@hadleybeeman, the Chrome origin trial for the API is coming to an end, and I was wondering if my answers to your previous questions make sense, and if you had any other comments about the API.

@kenchris
Copy link

kenchris commented Nov 27, 2019

Hi there,

We read about the discussions at TPAC: https://jakearchibald.com/2019/service-workers-tpac/

and were wondering about the steps going forward? It seems that background fetch can cover many of the same use-cases and we wonder whether you are still pursuing background sync.

In a way we feel that background sync is changing the core behavior of the web. One of the sales pitches that I have heard for PWAs is that, unlike native apps, if you don't use them, then they don't update and don't waste your data plans. Basically, you can install a PWA and not use it for a year and only when you open it up (or load the web site) it is able to update itself via the SW and regular caching.

It feels like background sync changes all of that, and thus a core tenet of the web, at least as long as there are no strong restrictions on how often and how long after last use background sync can be active.

This also touches a bit on silent push notifications (which are currently not allowed - they need to show UI), these could potentially be used to sync in a similar fashion. We understand that background sync can be limited by the platform (they are just a hint) but what makes them radically different?

@beverloo @jaffathecake

@mugdhalakhani
Copy link
Author

mugdhalakhani commented Nov 27, 2019

The discussion at TPAC focussed on one-off Background Sync Let's focus on Periodic Background Sync here.

  1. Background Fetch is designed to handle long-running downloads and uploads that can't be serviced within the execution time of a serviceworker event. They're also one-off, i.e., a new background fetch needs to be registered for each set of logical downloads. Because these can persist for long periods of time, across browser restarts, it's important to show persistent UI for the duration of background fetches. Periodic Background Sync solves a different problem. It enables a website to get repeated opportunities for updating state and content after registration, provided there's ongoing user engagement with the site.

  2. The way Chrome has implemented Periodic Background Sync, and the recommendation given in the spec is to cap the frequency of periodicSync events, and tie it in with user engagement with the origin. This means that if you stop using an installed PWA, we stop sending periodicSync events. The origin won't be able to keep consuming data and resources in that case.

  3. Web Push requires developers to code up a server that speaks the Push protocol, in order to send updates. It also causes the browser to be woken up to service the push event whenever the developer thinks is appropriate. Periodic Background Sync is different in that it gives the control of when to allow sites to update, to the browser. This allows the browser to optimize resources by clubbing updates of various PWAs while being respectful of user choices such as Data Saving mode, and prioritizing apps the user engages with more in the usage of these resources. A happy side effect is that it's easier to use for developers than Web Push is.

  4. We've added a 'periodic-background-sync' permission to the Permission API which will allow browsers to build their own privacy model for the API. The browser may choose to show an audit style UI to the user to avoid surprising them, or automatically deny permission on behalf of the user when the capability isn't considered safe. Chrome for instance, only allows the capability to be used from installed web apps.

Let me know if this answers your questions. @beverloo, @jaffathecake, feel free to add to this.

@kenchris
Copy link

kenchris commented Dec 2, 2019

Thanks for the answers, this sounds good. I didn't know that there was a one-off background sync as well, but I found it here: https://github.com/WICG/BackgroundSync/blob/master/explainers/sync-explainer.md

Are you thinking about adding some UI notification showing that the site is sync'ing in case users would want to block that? or do you expect the sync to be so fast that that doesn't make sense?

Is there a restriction on how long you can spend in a sync event? I know that SWs are killed if they spend too much time.

@kenchris
Copy link

kenchris commented Mar 4, 2020

I think it would be a good idea to turn off sync when the Save-Data header is present

https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/save-data/

@ylafon
Copy link
Member

ylafon commented Mar 4, 2020

@kenchris and I were reviewing this specification during our Wellington F2F.
One aspect is that there is currently no way for servers administrators to block such traffic.
It would be good to be able to flag those requests (via a HTTP header) so that servers can deny traffic if unwanted. Also, in case of HTTP error (4xx status), the periodic sync should be unregistered.

@kenchris kenchris added Progress: in progress Progress: pending external feedback The TAG is waiting on response to comments/questions asked by the TAG during the review and removed Progress: unreviewed labels May 27, 2020
@kenchris
Copy link

@mugdhalakhani, @KenjiBaheux any update?

@kenchris kenchris added the Review type: Already shipped Already shipped in at least one browser label May 27, 2020
@kenchris
Copy link

According to https://goo.gle/fugu-api-tracker this is already shipping in Chrome since M80

@webmaxru
Copy link

@kenchris Just FYI: my PR to update MDN with Periodic Background Sync availability was approved at the beginning of May: mdn/browser-compat-data#6030
So the correct status should appear at CanIUse and MDN docs.

@kenchris
Copy link

It is shipping in M80 according to https://chromestatus.com/features/5689383275462656

image

@webmaxru
Copy link

This is exactly what I submitted :)

@mugdhalakhani
Copy link
Author

Yes this API has already been shipped in Chrome, sorry for the delayed response and thanks for the suggestions!

@kenchris and I were reviewing this specification during our Wellington F2F.
One aspect is that there is currently no way for servers administrators to block such traffic.
It would be good to be able to flag those requests (via a HTTP header) so that servers can deny traffic if unwanted.
The website is able to stop periodic sync by calling 'unregister' anytime through their service worker. Are you suggesting adding a way for IT admins to block all periodicSync traffic for a given site? They're able to do so by auto-denying the periodic-background-sync permission. In Chrome, that's possible by disabling the "Background Sync" content setting for the site.

Also, in case of HTTP error (4xx status), the periodic sync should be unregistered.
This is also possible today but the developer needs to encode this. The idea is to let the web app sync whatever resources they like periodically. To that end, the browser simply sends periodicSync events to the service worker and the service Worker in turn sends any fetch requests to their server. The browser isn't initiating the fetches (giving more flexibility to the website to execute whichever fetches they like), and doesn't look at the responses from them either. The service worker can thus look for a 4xx response and call 'unregister'.

Let me know if you think the browser should do things differently.
@KenjiBaheux FYI.

@plinss plinss added this to the 2020-09-07-f2f milestone Aug 24, 2020
@ylafon
Copy link
Member

ylafon commented Sep 24, 2020

Hi, thank you for your response.
@kenchris and I were looking at this during our f2f.
Regarding the unregister on 4xx response, I think that it is important to have that, an error core (4xx or 5xx) should trigger an unregister to avoid zombie WebAppSec doing slow DDoS (if triggered by enough clients), so unregistering on errors mitigate that issue.

@plinss plinss removed this from the 2020-09-21-F2F-Cork milestone Oct 14, 2020
@kenchris
Copy link

Ping, did anyone consider @ylafon 's last comment?

@mugdhalakhani
Copy link
Author

mugdhalakhani commented Jan 29, 2021

ylafon@'s suggestion of triggering an unregister on 4xx or 5xx errors makes sense to me. I've filed WICG/periodic-background-sync#3 to track the update to the spec.

CC @beverloo, @jakearchibald

@kenchris kenchris removed Progress: in progress Progress: pending external feedback The TAG is waiting on response to comments/questions asked by the TAG during the review Progress: stalled labels Feb 9, 2021
@torgo torgo added the Progress: propose closing we think it should be closed but are waiting on some feedback or consensus label Feb 9, 2021
@kenchris
Copy link

kenchris commented Feb 9, 2021

Thanks for filing the issue @mugdhalakhani - I don't think there is much more for us to do here, so I propose closing. Thanks for bringing this to the TAG

@mugdhalakhani
Copy link
Author

Thanks for all the feedback here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Progress: propose closing we think it should be closed but are waiting on some feedback or consensus Provenance: Fugu Review type: Already shipped Already shipped in at least one browser Topic: fetch and preload Things that live on top of (but close to) networking. Topic: powerful APIs APIs that reach into your life. Topic: privacy Venue: WICG
Projects
None yet
Development

No branches or pull requests