Messenger notifications and Dock badge blocked by outdated selectors (tested fix)
A tested source patch is available on this branch, commit 6d732e44a39faf331bb76211c541c3d8e87a2510. It changes three source files. Creating a pull request through GitHub returned a CreatePullRequest permissions error, so I am sharing the diagnosis and proposed fix here.
On the current Messenger layout, Caprine 2.61.0 can receive messages without producing desktop notifications or updating the Dock badge, despite notifications and badges being enabled. This patch restores message detection and initial badge updates, and makes the macOS Dock bounce for each incoming message instead of for any change in the unread-conversation count.
Reproduction
Environment tested: Caprine 2.61.0, Electron 29.0.1, macOS 27.0 on Apple Silicon, French Messenger interface, messenger.com.
- Enable Caprine notifications and badges in macOS, and enable the unread badge and Dock bounce preferences in Caprine.
- Launch Caprine with unread conversations already present.
- Put Caprine in the background and receive a new message, including in an already-unread conversation.
Before the patch, native notifications and the Dock badge were missing. The old Dock logic also cannot bounce for another message in an already-unread conversation, because the number of unread conversations does not increase.
Causes and changes
- The load handler waits for the badge navigation before installing the message observers. If its selector never matches, message monitoring never starts. Install the message observers before waiting for this optional navigation.
- Several conversation class attributes no longer match the live layout. Refresh the four notification-related selectors from the observed DOM.
String.prototype.replaceAll(/ /, '.')throws because the regular expression is not global. UsereplaceAll(' ', '.')when building the unread-marker selector.- Find unread counters through navigation links with
aria-labelandfocus_targetinstead of an exact generated class string, and update the badge immediately after registering its observer. - Move the macOS Dock bounce from unread-count changes to the incoming-notification handler. Retain the focus, Do Not Disturb and bounce-preference checks, and respect muted notifications. This also avoids bouncing when conversations are marked read.
Validation
npm testpasses: TypeScript compilation, XO and Stylelint. XO reports the 19 existing TODO-comment warnings.- 22 local regression checks pass against the compiled source using synthetic fixtures: text/emoji notifications, mutation deduplication, ignoring read/unrelated changes, startup without badge navigation, initial/count/zero badge updates, and per-message bounce with focus and mute settings. These supplemental checks were run separately from the repository's existing test command.
- An equivalent local patch to the installed 2.61.0 app generated a native macOS notification for a real incoming message. The Dock badge and bounce were both visually confirmed by the tester.
- macOS suppressed the notification banner while screen sharing was active. Its delivery was confirmed in the system log; visual banner presentation outside screen sharing has not been separately confirmed.
Scope
This targets the existing implementation on main, based on commit c3cbcf9. It is narrower than the migration in #2379 and does not change the Messenger domain. The refreshed conversation selectors still depend on Messenger's generated classes, so other account layouts and future markup changes may require further work. Windows and Linux have not been tested manually.
Source: sindresorhus/caprine