[$250] Notification – Have no sound for notification received
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: 9.0.72-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team
Action Performed:
- Go to https://staging.new.expensify.com/
- Log in as user A
- Open chat with user B
- As user B send message to user A
- Notice that user A receive a notification
Expected Result:
Notification is with sound
Actual Result:
Notification is without sound
Workaround:
Unknown
Platforms:
- [ ] Android: Standalone
- [ ] Android: HybridApp
- [ ] Android: mWeb Chrome
- [ ] iOS: Standalone
- [ ] iOS: HybridApp
- [ ] iOS: mWeb Safari
- [x] MacOS: Chrome / Safari
- [x] MacOS: Desktop
Screenshots/Videos
https://github.com/user-attachments/assets/81254557-0a12-412a-96f8-0300b73a586e
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~021866271667566111224
- Upwork Job ID: 1866271667566111224
- Last Price Increase: 2024-12-10
Issue Owner
Current Issue Owner: @jayeshmangwani
Triggered auto assignment to @RachCHopkins (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.
Can repro!
Job added to Upwork: https://www.upwork.com/jobs/~021866271667566111224
Triggered auto assignment to Contributor-plus team member for initial proposal review - @jayeshmangwani (External)
Edited by proposal-police: This proposal was edited at 2024-12-24 09:19:58 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue
Browser notifications in New Expensify are displaying without sound when new messages arrive.
What is the root cause of that problem?
- Chrome on macOS has a known bug preventing notification sounds from working
- Current implementation uses
silent: trueby default inBrowserNotifications.ts - Different browsers handle notification sounds inconsistently, leading to potential double-sound issues in some browsers
What changes do you think we should make in order to solve the problem?
- Use consistent
silent: trueapproach with custom sound implementation:
notificationCache[notificationID] = new Notification(title, {
body,
icon: String(icon),
data,
silent: true, // Prevent browser-native sounds
tag,
});
if (!silent) {
playSound(SOUNDS.RECEIVE); // Play our custom sound
}
- Update default behavior in
BrowserNotifications.ts:
// Change from
push(title, body, icon, data, onClick, true);
// To
push(title, body, icon, data, onClick, false); // Enable sound by default
This solution ensures consistent notification sounds across all web platforms while avoiding double-sound issues in browsers like Safari.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
N/A
What alternative solutions did you explore? (Optional)
adding silent: true to the new Notification.
notificationCache[notificationID] = new Notification(title, {
body,
icon: String(icon),
data,
silent: true,
tag,
});
If this is a bug from the Chrome web browser and it's fixed, we could expect double notifications but with this, only our custom sound via playSound(SOUNDS.RECEIVE) will play and the default browser notification sound will be suppressed.
Result (Sound on)
https://github.com/user-attachments/assets/d841fe52-51f3-4e8c-b6da-16c673baab1a
Proposal
Please re-state the problem that we are trying to solve in this issue.
- Notification is without sound
What is the root cause of that problem?
- In web, if we want to show notification with sound, we call something like:
new Notification(title, {
silent: false,
});
The silent read-only property of the Notification interface specifies whether the notification should be silent, i.e., no sounds or vibrations should be issued regardless of the device settings. This is controlled via the silent option of the Notification() constructor.
-
But the Chrome notification sounds stopped working on MacBook, this bug are reported in here. In Safari, it still works well.
-
Even if the above issue is fixed, the notification still cannot have sound in case the message is not the modified expense message because we are usiing
silent: truein:
https://github.com/Expensify/App/blob/082e14b9bc1259c329c7cd186ee8f21c0397f6fb/src/libs/Notification/LocalNotification/BrowserNotifications.ts#L125
The 6th param is true.
What changes do you think we should make in order to solve the problem?
- Solution to fix the 1st problem, where the notification sound does not work in macOS Chrome:
- Since this issue occurs only on macOS Chrome and not on all platforms, we should consistently use silent: true and play our custom sound separately. Why always use silent: true? If we set silent: false in Safari (where the issue doesn't occur), the notification will produce two sounds: the default sound triggered by silent: false and our custom sound. This duplication can lead to an undesirable user experience.
Based on that, the logic:
https://github.com/Expensify/App/blob/082e14b9bc1259c329c7cd186ee8f21c0397f6fb/src/libs/Notification/LocalNotification/BrowserNotifications.ts#L64-L70 can be:
notificationCache[notificationID] = new Notification(title, {
body,
icon: String(icon),
data,
silent: true,
tag,
});
if (!silent) {
playSound(SOUNDS.RECEIVE); // The sound can be decided later.
}
- Solution to fix the 2nd problem, has no sound when the message received is not expense modified message.
- We just need to update the 6th param in:
https://github.com/Expensify/App/blob/082e14b9bc1259c329c7cd186ee8f21c0397f6fb/src/libs/Notification/LocalNotification/BrowserNotifications.ts#L125
from true to false, or just need to remove that param since its default value is already false.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
- We need to create a test for the function push with the two test cases are when the
silentparam istrueorfalse. If it isfalse, need to make sure there is no sound is triggred.
What alternative solutions did you explore? (Optional)
- In MacOS Chrome, we call:
if (!silent) {
playSound(SOUNDS.RECEIVE); // The sound can be decided later.
}
- With other platforms, leave it as it is.
if (!silent && Browser.getBrowser() === CONST.BROWSER.CHROME && !Browser.isMobile()) {
// Play custom sound here
}
@RachCHopkins, @jayeshmangwani Whoops! This issue is 2 days overdue. Let's get this updated quick!
Not overdue, testing the above 2 proposals
@JoshIri360 and @truph01 , did you receive the notification sound on desktop in the current version?
No I didn't, tested in chrome and safari.
No I didn't, tested in chrome and safari.
Thanks! So we don’t get sound on the web (Chrome + Safari) or desktop either, right? Just confirming so I can test solutions on those platforms.
No I didn't, tested in chrome and safari.
Thanks! So we don’t get sound on the web (Chrome + Safari) or desktop either, right? Just confirming so I can test solutions on those platforms.
Yes, exactly.
@jayeshmangwani In Macos Safari, it works well. The issue only appears in Macos Chrome. But you need to hard-code the 6th param to false:
https://github.com/Expensify/App/blob/082e14b9bc1259c329c7cd186ee8f21c0397f6fb/src/libs/Notification/LocalNotification/BrowserNotifications.ts#L125
before testing the sound notification if you want the sound is triggered by sending a message.
Thanks for the explanation @truph01. I feel that your proposal is quite similar to @JoshIri360, I’ve already tested their proposal, and it works fine on Safari, Chrome, and desktop.
it works fine on Safari, Chrome, and desktop.
In safari, that solution can introduce the bug when the sound is triggered 2 times. Did you encounter it? @jayeshmangwani
No @truph01 , I have tested it a few times on Safari and only received one notification sound.
I have tested it a few times on Safari and only received one notification sound.
That means this bug appears in both Chrome and Safari from your side, right?
Yes, that’s correct, which is why I asked for confirmation earlier. For me, neither Safari nor Chrome is producing any sound.
Here is the video from my side, the sound is triggered in Safari:
https://github.com/user-attachments/assets/8cecc9f9-fbc5-4721-acb0-c21d9195e59b
Can you share the notification setting from your device, please? Here is mine: