Skip to content

Expose pushManager on Window #393

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

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from

Conversation

annevk
Copy link
Member

@annevk annevk commented Nov 19, 2024

This is part of the Declarative Web Push initiative (see #360) and mainly makes sense when that is supported, although could be independently supported in theory.

This makes window.pushManager work by making push subscriptions tied to a scope rather than a service worker registration. Most often push subscriptions remain 1:1 with service worker registrations, but the scope whose serialized path is "/" is treated specially from now on and can exist independently.

This obsoletes #368.

The following tasks have been completed:

  • Modified Web platform tests (link to pull request)

Implementer support:

  • Chromium
  • Gecko
  • WebKit

Preview | Diff

This is part of the Declarative Web Push initiative (see #360) and mainly makes sense when that is supported, although could be independently supported in theory.

This makes window.pushManager work by making push subscriptions tied to a scope rather than a service worker registration. Most often push subscriptions remain 1:1 with service worker registrations, but the scope whose serialized path is "/" is treated specially from now on and can exist independently.

This obsoletes #368.
@annevk annevk mentioned this pull request Nov 19, 2024
4 tasks
@annevk annevk mentioned this pull request Nov 19, 2024
@saschanaz
Copy link
Member

saschanaz commented Nov 19, 2024

@asutherland previously had a strong opinion that notifications should be paired with registration instead of scope in #205, so adding him as a reviewer.

(Although now I see #368 (comment))

@annevk annevk mentioned this pull request Dec 5, 2024
4 tasks
annevk added a commit that referenced this pull request Dec 5, 2024
This introduces a new feature whereby push messages conforming to a certain JSON format directly create an end user notification and show it (possibly preceded by an enhanced push event).

In addition to showing a notification, the app badge can be updated as well.

This builds on whatwg/notifications#213 which adds URL members to notifications.

Exposing PushManager outside of service workers is handled by #393.
Copy link
Member

@saschanaz saschanaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first round of review. Looks mostly fine but with some questions.

subscription</a> having the new keys as |newSubscription|.
If the <a>user agent</a> has to change the keys of a [=push subscription=] for any reason
and the [=push subscription=]'s [=associated service worker registration=] is non-null,
it MUST [=refresh=] the [=push subscription=].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Reviewer note: this change is an editorial refactoring to reuse the term "refresh")

</h2>
<p>
A <a>user agent</a> or <a>push service</a> MAY choose to <dfn>refresh</dfn> a <a>push
subscription</a> at any time, for example because it has reached a certain age.
subscription</a> whose [=associated service worker registration=] is non-null at any
time, for example because it has reached a certain age.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean a subscription without an SWR is never supposed to be refreshed? I think the Firefox push server will keep its logic to auto-clear subscriptions (we do that when an inactive subscription is being spammed and gets a huge amount of message queue). cc @jrconlin

[SecureContext]
partial interface ServiceWorkerRegistration {
interface mixin PushManagerAttribute {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorta weird name when it's a mixin and not an attribute. Bikeshedding: PushManagerBase (kinda following WebGL), PushManagerCommon (kinda following TextDecoder/Encoder), PushManageable (kinda following Animatable), PushManagerSource (kinda following FontFaceSource), PushManagerMixin (kinda following ARIAMixin and PaintTimingMixin), etc etc...

Not strongly against the current name though, especially it's just a spec-only name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a mixin that holds an attribute. Anyway, happy to change to whatever.

</li>
<li>If [=this=] is a {{Window}} object, then set |scope| to the result of running the
[=basic URL parser=] given "`/`" and |global|'s <a>associated <code>Document</code></a>'s
[=Document/URL=].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would fail for about:blank, but I guess that's fine as this is restricted to SecureContext.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're correct that there might be some failure scenarios here this needs to account for.

</li>
<li>If |subscription| is non-null:
<ol>
<li>If there is an error with |subscription|, then [=queue a global task=] on the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence now sounds like there's an error field on subscriptions, but given the previous sentence was "Let subscription be the result of obtaining registration's push subscription. If there is an error, ..." it was more about an error while obtaining the subscription.

I think either we should throw earlier in the subscription obtaining steps or just remove this step, as the obtaining steps are now clearer and infallible (except the existing null check)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep this as this is not something I was aiming to change in this PR. I'm not really sure how to do it earlier though without getting very verbose.

</li>
<li>If |subscription| is null, then resolve |promise| with null.
</li>
<li>If there is an error with |subscription|, reject |promise| with a {{DOMException}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Same about error, might be nicer if we throw in the obtaining steps or just skip this. It's unclear what a caller should do if this function throws, so maybe implementations should just pretend that no subscription exists if it's corrupted or something. If there's a good reason to throw error, it would be nice to have a note about that.)

<li>If |registration|'s [=associated push subscription=] is non-null, then set
|subscription| to |registration|'s [=associated push subscription=].
</li>
<li>Set |scope| to |registration|'s [=service worker registration/scope URL=].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the scope URL is the root path then this is also accessible from window, right? I assume that's the intention.

@saschanaz
Copy link
Member

Neither this PR nor #385 changes the step 2 in section 10.4 Recieving a Push Message:

  1. Let registration be the service worker registration corresponding to the push message.
  2. If registration is not found, abort these steps.

Without changing that I think the window-subscribed push messages would be ignored.

<p>
A [=push subscription=] is considered to have a <dfn for=
"push subscription">window-accessible scope</dfn> when its [=push subscription/scope=] is
a [=/list=] of [=list/size=] 1 and [=push subscription/scope=][0] is the empty string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the scope seems to be a list of string, but right above it's defined as a URL struct, which looks like a conflict.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this should look at the scope's path instead of scope.

annevk added a commit that referenced this pull request Mar 3, 2025
This introduces a new feature whereby push messages conforming to a certain JSON format directly create an end user notification and show it (possibly preceded by an enhanced push event).

In addition to showing a notification, the app badge can be updated as well.

This builds on whatwg/notifications#213 which adds URL members to notifications.

Exposing PushManager outside of service workers is handled by #393.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants