w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)
Other
595 stars 56 forks source link

Proposal: audible notifications (play a sound with a notification) #349

Open hanguokai opened 1 year ago

hanguokai commented 1 year ago

Overview

When send a notification, play a sound at the same time by specifying an audio file which length is usually about a second. Typical application scenarios like alarms, reminders, notifications, and battery level changes, etc.

This is a strong functional requirement from developers. You can search for "play sound" or "audio notification" in extension developers forum, StackoverFlow, browser's bug trackers and this project, there are many related discussions. So, I don't need to prove the usefulness of this feature.

API

browser.notifications.create(
  id,
  {
    type: "basic",
    iconUrl: "icon.png",
    audio: "notification-sound.mp3", // a new field in NotificationOptions
    title,
    message
  }
)

Web Notification API vs Extension Notification API

Although the functions of these two APIs are similar, the application scenarios of web and extension are obviously different (extensions are more like native apps), which leads to the fact that Web API will be more conservative, while extension API can be more aggressive. So, I think the extension API should support this feature.

Workaround

Note: This api is mainly used from background.

In MV2, event page or background page can play sound directly and easily, i.e. new Audio('sound.mp3').play().

In MV3, service worker can't play sound directly, Chrome supplies the offscreen api as a temporary workaround for general purpose DOM functions.

Because playing a sound with a notification is a very common and highly demanded feature, I think extension notification API should have built-in support for it.

Rob--W commented 1 year ago

As noted in today's meeting (https://github.com/w3c/webextensions/pull/357 , will be published at https://github.com/w3c/webextensions/blob/main/_minutes/2023-03-02-wecg.md), the browser vendors are neutral towards this feature, provided that the flag is advisory and not mandatory. Advisory, in case the platform does not support audio notifications or if the user has chosen to disable/mute audio notifications.

hanguokai commented 1 year ago

The issue claims that the feature is common and highly demanded. Does anyone have data that backs this claim? - A question in the meeting note.

Let me give some links that can reflect the needs of developers and users.

Stackoverflow:

Developers Forum:

Issue Trackers:

Extensions in Web Stores:

Real user reviews from Web Stores:

If you expand the audio notification feature from the web platform to mobile and desktop platforms, you will find more developer and user needs and instances.