Implement Badging API

,

AI-generated summary

The discussion centers on implementing the Badging API for installed Progressive Web Apps (PWAs) to display notification indicators on app icons. Falco introduces the API, noting it’s currently available via Chrome trial on Windows and macOS, with Meta already using it in Light and Dark Themes. codinghorror and david demonstrate how to install and test the feature on Windows and macOS, showing visual examples of badges appearing after notifications. sam points out the lack of navigation controls in PWA windows and suggests adding a minimal UI panel via theme components. Falco shares CSS code to style scrollbars for standalone PWAs. anon82467725 expresses excitement for Discourse PWA support on Chrome OS. Falco confirms Discourse added support in 2019 but didn’t trigger badges when apps were closed — a limitation now being addressed anon82467725. Falco also announces iOS support. merefield and Tris20 request visual enhancements like flashing or color changes for better visibility, citing Microsoft Teams’ orange glow as inspiration. Tris20 also details browser compatibility: Chrome and Edge work natively, Firefox requires an add-on, and Brave mirrors Chrome. Instructions for enabling auto-start on Chrome and Edge are included with screenshots.

There is a new web API that allows installed web apps to show a icon to warn the user about pending notifications.

Explainer: badging/explainer.md at main · w3c/badging · GitHub

Currently, this is only available for websites who sign up to the trial, and only on Windows and Mac OS using Google Chrome. (Meta has this enabled on Light and Dark Themes).

This is how the looks on Windows:

Before a notification

image

After a notification

image

9 Likes

Here’s how to test this in Windows on Chrome (latest version 73, just released today):

  • go to the three dots menu at the upper right in Chrome
  • select More Tools → Create Shortcut
  • tick the “Open as window” checkbox
  • select Create

Like so

I’ll try it out .. it works!

5 Likes

This is very cool! On mac, it’s the same process to install the app. Then when you launch it you get a super minimal PWA window:

And the notification badge in the dock:

9 Likes

The huge omission here is that there is no back/forward or reload button. Kind of wish we had some minimal responsive PWA panel that we add when we detect PWA cause you can figure this out this is going on from JavaScript.

Step 1 here of course is a theme component.

6 Likes

You can also detect it from CSS, here is one thing I added as a theme-component to the Dark Theme here in Meta:

@media all and (display-mode: standalone) {
    
    //blink-based browsers (don't work on safari, which exposes a JS only API for this)
    ::-webkit-scrollbar {
        background: $secondary;
    }
    ::-webkit-scrollbar-thumb {
        background: $header_primary-medium;
    }
    ::-webkit-scrollbar-corner {
        background: $secondary;
    }
    
    //firefox
    body {
        scrollbar-color: $header_primary-medium $secondary;
    }
}
6 Likes

Another day, another feature! As with any new PWA feature, I wonder how well it works with Discourse… :thinking:

I’m excited to try it out. Badge notifications for the Discourse PWA in Chrome OS sounds absolutely amazing!

2 Likes

We added support for the badging API back in early 2019, but we don’t call it when the app is closed at the moment as it wasn’t supported back then.

2 Likes

And that is changing now, right?

2 Likes

Happy to report that the work we did here also gives us badging on latest iOS

6 Likes

Falco, is there a possibility there could be a flashing or change of background colour behaviour if the notification value changes? (Cancelled by an open click) I’m not familiar with the API here.

2 Likes

Would love this also. Particularly useful in cases where the Branding Icon is dark and the notificaiton doesn’t show up so well.

image

As much as I dislike MSTeams, the gentle orange glow is ok as an example. Something like that would be a very nice touch.

More than just Chrome:

A quick update on the supported browsers:

Brave: Works the same as Chrome
Firefox: Requires an add-on
Edge: Works the same as chrome, and it offers you the option to auto-start the app when you install it:

To autostart the app in chrome

  1. Click the three dots

  2. Click App-Info

  3. Click settings (Einstellung in German)

  4. Configure accordingly. In this case “App beim Anmelden started” is the option we ware looking for

1 Like