Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

marcoscaceres
Copy link
Member

@marcoscaceres marcoscaceres commented Sep 3, 2025

Closes #111

The main change is the introduction of a new algorithm for setting the badge for installed web applications by app ID is added, including permission checks. To reduce duplication, we now have a dedicated "set badge value" algorithm, which is now called from multiple places, reducing duplication and making the badge-setting process more consistent.

Badge value setting refactor:

  • Introduced a new "set badge value" algorithm that centralizes the logic for updating a badge based on the optional contents value, replacing previous inline implementations.
  • Updated the main badge-setting algorithm to delegate to the new "set badge value" algorithm, improving maintainability and reducing repeated code.

New installed web application badge API:

  • Added a new algorithm, "set the application badge for installed web application," which allows setting a badge by app ID, includes permission checks, and uses the centralized badge value logic for consistency.

Minor formatting/clarity:

  • Minor formatting changes for readability and clarity in the badge-setting steps.
    This change (choose at least one, delete ones that don't apply):

  • Adds new normative requirements

Implementation commitment (delete if not making normative changes):


Preview | Diff

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new algorithm for setting the application badge for installed web applications by app ID, with appropriate permission checks. The change refactors badge value setting logic to reduce code duplication by extracting a common "set badge value" algorithm that can be reused across different badge-setting contexts.

  • Extracted badge value setting logic into a reusable "set badge value" algorithm
  • Added new "set the application badge for installed web application" algorithm with permission validation
  • Updated existing badge-setting algorithm to use the centralized badge value logic

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

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

this seems sensible to me

@marcoscaceres
Copy link
Member Author

On the Push API side w3c/push-api#402

index.html Outdated
<li>If the [=user agent=] requires [=express permission=] to
[=badge/set=] the application badge, then:
<ol>
<li>Let |permissionState| be the result of [=getting the current
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be nice if user agents had the option to separate this into another permission - I can imagine situations where I'd be okay with having a badge shown but I don't want to see any notifications.

In my ideal world, even if a user agent doesn't think badging requires express permission for badging I'd like to be able to opt out of it.

Are we able to add a more granular permission later?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's complicated :(

That (showing the badge) controlled by the OS, so that gets us back to not requiring the granular permission. But yes, the Notifications API itself needs to control this, because it is ultimately the source of truth and policy enforcement point here.

We might need to discuss this with @annevk.

Copy link
Member

@annevk annevk Sep 9, 2025

Choose a reason for hiding this comment

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

I see this text was removed from the PR?

Declarative Web Push will continue to require the notification permission, mainly because there's always a notification and badging is an aside, but I could see the Badge API not requiring it as it's not explicitly exposed. But it would be weird if in some user agents it only shows up after the notification permission is obtained. That would not be a great story for web developers.

Copy link
Member Author

@marcoscaceres marcoscaceres Sep 10, 2025

Choose a reason for hiding this comment

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

@annevk, take a look at the discussion in #110

On the one hand, there is a nice quality here in that it leaves showing the badge entirely under the user's control.

The other nice quality, on macOS at least, is that it automatically and unobtrusively prompts for notification permission when .setAppBadge() is called.

Irrespective, setting the badge has succeeded, so the permission check doesn't actually need to come into play here.

In #110, @mkruisselbrink suggests maybe having an API addition whereby a developer could check if badging requires notification permission to show up (at the platform/browser level). That could solve the problem of having to do platform/UA sniffing, while being privacy preserving.

something like at static (joke name):

Notification.platfromWillShowBadgeWithoutRequestingPermission;

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that might be reasonable; slightly better bike shed color: Notification.showingAppBadgeRequiresPermission.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, and I guess it wouldn't expose any more information because you should be able to infer what that bit is set to from the user-agent.

👍 from me.

Choose a reason for hiding this comment

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

I agree that having such a field makes sense. From experimenting a while ago it seemed to me that the macOS OS level permissions behavior was such that a macOS application does not need notifications permissions to display an app badge if it doesn't otherwise interact with the notifications system in any way (which is why app badging works at all in PWAs on Chrome on mac today), but as soon as an application does anything with notifications a previously visible app badge will disappear until/unless the user approved notifications permission. With that it might not be quite true that it is entirely derivable from the user agent, but we might still just return true for all sites checking that field on Chrome on macOS, as I don't think the OS exposes a similar field and it's probably not worth trying to keep track of it on the Chrome side.

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 need to think about this a bit... but I wonder if this could be a fine grained permissions policy check like: navigator.permissions.query("notifications-badging");.

Also, that might allow us to have an all around better permissions policy behavior for this feature.... it's currently restricted to same-origin domain. We should make it work like any other feature with respect to permissions policy.

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.

Set an application badge without platform object

4 participants