You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-07-28] [$250] [Sentry: APP-2D7] Web Notification illegal constructor crash #93835
src/libs/Notification/LocalNotification/BrowserNotifications.ts:58
new Notification(title, { body, icon, data, ... })
Suspected cause
BrowserNotifications uses new Notification() directly, which is not supported in all browsers (e.g. Samsung Internet); should use ServiceWorkerRegistration.showNotification() instead.
Reproduction
Unknown — see Sentry events linked from the Sentry issue.
The local evidence matches this recurring failure shape: native callback assumes current policy/report still exists. Here, src/libs/Notification/LocalNotification/BrowserNotifications.ts:17 and src/libs/Notification/LocalNotification/BrowserNotifications.ts:23 do not agree on the same APP, reportID, LocalNotification value, so the user-visible path can show a missing or stale state even though nearby data already has the needed context.
What changes do you think we should make in order to solve the problem?
Update src/libs/Notification/LocalNotification/BrowserNotifications.ts:17 to derive APP, reportID, LocalNotification from the matched app state path that owns this flow before the value is consumed.
Carry the same normalized value through src/libs/Notification/LocalNotification/BrowserNotifications.ts:23; that follows the safer family move to add the guard at the ownership boundary, not only at render, so the write/optimistic/read paths agree instead of only changing the visible component.
Keep the change inside the Sentry Crash, Null/Undefined, Native Hybrid surface and avoid changing do not hide crashes with blanket catch, native platform differences.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
Add or update a regression in tests/unit/**/*.ts for the exact issue flow: [$250] [Sentry: APP-2D7] Web Notification illegal constructor crash.
Cover the counter-case near src/libs/Notification/LocalNotification/BrowserNotifications.ts:17 so valid existing APP, reportID, LocalNotification behavior still works.
Manually repeat the issue steps after the patch and confirm the visible state/action is no longer stale.
What alternative solutions did you explore? (Optional)
I would not add a broad new condition outside these referenced paths; the safer fix is to keep APP, reportID, LocalNotification consistent at the first read/write boundary shown above.
On Android-based browsers (Samsung Internet, Chrome on Android) the page context is forbidden from constructing a Notification; the constructor throws TypeError: Illegal constructor. These browsers only allow notifications via ServiceWorkerRegistration.showNotification().
The guard that runs first only checks permission, never whether the constructor is usable:
So the chain is: window.Notification exists and Notification.permission === 'granted' → canUseBrowserNotifications() resolves true → new Notification(...) throws. Because that throw happens inside the .then() callback at line 51 with no .catch(), it surfaces as an unhandled promise rejection → the global onunhandledrejection handler reports it (APP-2D7). This matches every symptom: web-only, /r/:reportID, Samsung Internet on Android.
What changes do you think we should make in order to solve the problem?
There are two distinct things here: (1) stop the crash, and (2) actually deliver the notification on affected browsers. They have very different cost/risk, so I'd land them separately.
Step 1 — stop the unhandled rejection (the actual reported bug). Wrap the construction in try/catch and add a .catch() to the promise chain so an unsupported constructor degrades to "no local notification" instead of an unhandled rejection. This alone resolves APP-2D7 with near-zero regression risk:
Step 2 — restore delivery on affected browsers via the service worker. Prefer registration.showNotification(title, {body, icon, data, silent, tag}) when a registration is available, falling back to the (try/catch-guarded) constructor only when there is none. A service worker is already registered in production:
// Soft-fail: app must continue working even if SW registration fails (Safari Private mode, etc.).
// eslint-disable-next-line no-console
console.warn('[SW] registration failed',error);
});
});
}
Important feasibility constraint that changes the shape of Step 2: notifications shown via showNotification() do not return a Notification instance, so the current click/close wiring and the in-memory notificationCache cannot work as-is:
Clicks on an SW-shown notification can only be observed inside the service worker via the notificationclick event — the page cannot attach onclick to them, so there is no "equivalent app-level listener." But our service worker is fully generated by Workbox GenerateSW, which emits the entire file and offers no hook to add a notificationclick listener:
So Step 2 requires migrating the build from GenerateSW to InjectManifest with a small custom SW source that (a) handles notificationclick (focus an existing client or open /r/:reportID, posting a message back to the page so existing onClick behavior is preserved), and (b) lets clearNotifications use registration.getNotifications() + notification.close() (matching on data) instead of the cache:
Because Step 2 touches the build pipeline and SW lifecycle, I'd ship Step 1 first to kill the crash immediately, then do Step 2 as a scoped follow-up rather than blocking the crash fix on a build migration.
What alternative solutions did you explore? (Optional)
Use registration.showNotification() + notificationclick without changing the build (the approach in the other posted proposals). This is not implementable on main: with GenerateSW there is nowhere to register a notificationclick handler, and clicks on SW notifications are not observable from the page, so click-to-open-report would silently break. Hence the InjectManifest migration called out above.
try/catch only, no SW delivery. This is exactly Step 1 and is sufficient to close APP-2D7, but it permanently drops local notifications on Samsung Internet, so I scoped Step 2 to recover them.
Feature-detect and disable local notifications on affected browsers. Strictly worse than Step 2 — it removes a working feature for those users instead of routing them through the supported SW path.
push() shows notifications by calling the new Notification() constructor directly at BrowserNotifications.ts:58.
On Android-based browsers (Samsung Internet, Chrome on Android) the Notification constructor is forbidden and throws TypeError: Illegal constructor — these browsers only permit notifications via ServiceWorkerRegistration.showNotification().
The guard that runs first, canUseBrowserNotifications(), only checks permission, not whether the constructor is usable. It relies on NotificationPermission.getStatus(), which returns granted whenever window.Notification exists and permission is granted.
So the failure chain is:
window.Notification exists + permission granted → canUseBrowserNotifications() resolves true → new Notification(...) throws → because the throw happens inside the .then() callback at line 51 with no .catch(), it surfaces as an unhandled promise rejection → caught by the global onunhandledrejection handler → reported as APP-2D7.
This explains every symptom in the report: web-only, /r/:reportID (report comment notifications), Samsung Internet on Android, and the auto.browser.global_handlers.onunhandledrejection mechanism.
What changes do you think we should make in order to solve the problem?
When a service-worker registration is available, use registration.showNotification(title, {body, icon, data, silent, tag}) instead of new Notification(...).
Fall back to the direct constructor only when no registration exists, and wrap that construction in try/catch.
Add a .catch() to the canUseBrowserNotifications() chain so any unsupported path degrades gracefully instead of becoming an unhandled rejection.
Because showNotification() does not return a Notification instance, the click/close wiring and the in-memory notificationCache (lines 17 + 68–76 + 184–191) must move to the SW model: handle clicks via the notificationclick event, and implement clearNotifications with registration.getNotifications() + notification.close() (matching on data) instead of the cache.
What alternative solutions did you explore? (Optional)
Minimal stop-the-bleed: wrap the new Notification(...) call in try/catch and add .catch() to the promise chain. This silences the crash but drops the notification entirely on affected browsers, so the service-worker approach is preferred for actually delivering them.
Note on existing proposals
Two proposals are already posted. lorretheboy's proposal correctly and thoroughly identifies the root cause and a sound fix — this analysis independently confirms it against the current code. The earlier proposal by godzillaxbox19982014-lgtm is generic boilerplate that does not engage with the actual Notification constructor mechanism and should be disregarded.
Next Steps for Contributor+ team: To accept:@MelvinBot implement [this](https://github.com/Expensify/App/issues/93835#issuecomment-4732180029) to create a draft PR. To refine:@MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.
⚠️@aswin-s Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
@lorretheboy can you please accept the job below? Please reply here and tag me once you have.
If you're not sent an offer in Upwork when you're assigned to an issue, please tag me. If an Upwork job exists, please submit a proposal. https://www.upwork.com/jobs/~022084481636816458622
Activity
melvin-bot commentedon Jun 17, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @mananjadhav (
External)melvin-bot commentedon Jun 17, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022067266019042576521
godzillaxbox19982014-lgtm commentedon Jun 17, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
[$250] [Sentry: APP-2D7] Web Notification illegal constructor crash
What is the root cause of that problem?
I traced this to the path that handles
APP, reportID, LocalNotification:BrowserNotifications):const notificationCache: Record<string, Notification> = {};canUseBrowserNotifications):function canUseBrowserNotifications(): Promise<boolean> {getStatus):return NotificationPermission.getStatus().then((status) => {src/libs/Notification/LocalNotification/BrowserNotifications.ts:17andsrc/libs/Notification/LocalNotification/BrowserNotifications.ts:23do not agree on the sameAPP, reportID, LocalNotificationvalue, so the user-visible path can show a missing or stale state even though nearby data already has the needed context.What changes do you think we should make in order to solve the problem?
src/libs/Notification/LocalNotification/BrowserNotifications.ts:17to deriveAPP, reportID, LocalNotificationfrom the matched app state path that owns this flow before the value is consumed.src/libs/Notification/LocalNotification/BrowserNotifications.ts:23; that follows the safer family move to add the guard at the ownership boundary, not only at render, so the write/optimistic/read paths agree instead of only changing the visible component.What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
tests/unit/**/*.tsfor the exact issue flow: [$250] [Sentry: APP-2D7] Web Notification illegal constructor crash.src/libs/Notification/LocalNotification/BrowserNotifications.ts:17so valid existingAPP, reportID, LocalNotificationbehavior still works.What alternative solutions did you explore? (Optional)
APP, reportID, LocalNotificationconsistent at the first read/write boundary shown above.lorretheboy commentedon Jun 17, 2026
🚨 Edited by proposal-police: This proposal was edited at 2026-06-17 15:47:29 UTC.
Proposal
What is the root cause of that problem?
push()shows a notification by calling thenew Notification()constructor directly:App/src/libs/Notification/LocalNotification/BrowserNotifications.ts
Lines 58 to 64 in 6ea10e7
On Android-based browsers (Samsung Internet, Chrome on Android) the page context is forbidden from constructing a
Notification; the constructor throwsTypeError: Illegal constructor. These browsers only allow notifications viaServiceWorkerRegistration.showNotification().The guard that runs first only checks permission, never whether the constructor is usable:
App/src/libs/Notification/notificationPermission/index.ts
Lines 13 to 18 in 6ea10e7
So the chain is:
window.Notificationexists andNotification.permission === 'granted'→canUseBrowserNotifications()resolvestrue→new Notification(...)throws. Because that throw happens inside the.then()callback at line 51 with no.catch(), it surfaces as an unhandled promise rejection → the globalonunhandledrejectionhandler reports it (APP-2D7). This matches every symptom: web-only,/r/:reportID, Samsung Internet on Android.What changes do you think we should make in order to solve the problem?
There are two distinct things here: (1) stop the crash, and (2) actually deliver the notification on affected browsers. They have very different cost/risk, so I'd land them separately.
Step 1 — stop the unhandled rejection (the actual reported bug). Wrap the construction in
try/catchand add a.catch()to the promise chain so an unsupported constructor degrades to "no local notification" instead of an unhandled rejection. This alone resolves APP-2D7 with near-zero regression risk:App/src/libs/Notification/LocalNotification/BrowserNotifications.ts
Lines 51 to 78 in 6ea10e7
Step 2 — restore delivery on affected browsers via the service worker. Prefer
registration.showNotification(title, {body, icon, data, silent, tag})when a registration is available, falling back to the (try/catch-guarded) constructor only when there is none. A service worker is already registered in production:App/src/setup/platformSetup/index.ts
Lines 74 to 82 in 6ea10e7
Important feasibility constraint that changes the shape of Step 2: notifications shown via
showNotification()do not return aNotificationinstance, so the current click/close wiring and the in-memorynotificationCachecannot work as-is:App/src/libs/Notification/LocalNotification/BrowserNotifications.ts
Lines 68 to 76 in 6ea10e7
Clicks on an SW-shown notification can only be observed inside the service worker via the
notificationclickevent — the page cannot attachonclickto them, so there is no "equivalent app-level listener." But our service worker is fully generated by WorkboxGenerateSW, which emits the entire file and offers no hook to add anotificationclicklistener:App/config/webpack/webpack.common.ts
Lines 135 to 161 in 6ea10e7
So Step 2 requires migrating the build from
GenerateSWtoInjectManifestwith a small custom SW source that (a) handlesnotificationclick(focus an existing client or open/r/:reportID, posting a message back to the page so existingonClickbehavior is preserved), and (b) letsclearNotificationsuseregistration.getNotifications()+notification.close()(matching ondata) instead of the cache:App/src/libs/Notification/LocalNotification/BrowserNotifications.ts
Lines 184 to 191 in 6ea10e7
Because Step 2 touches the build pipeline and SW lifecycle, I'd ship Step 1 first to kill the crash immediately, then do Step 2 as a scoped follow-up rather than blocking the crash fix on a build migration.
What alternative solutions did you explore? (Optional)
registration.showNotification()+notificationclickwithout changing the build (the approach in the other posted proposals). This is not implementable onmain: withGenerateSWthere is nowhere to register anotificationclickhandler, and clicks on SW notifications are not observable from the page, so click-to-open-report would silently break. Hence theInjectManifestmigration called out above.MelvinBot commentedon Jun 17, 2026
Proposal
What is the root cause of that problem?
push()shows notifications by calling thenew Notification()constructor directly atBrowserNotifications.ts:58.On Android-based browsers (Samsung Internet, Chrome on Android) the
Notificationconstructor is forbidden and throwsTypeError: Illegal constructor— these browsers only permit notifications viaServiceWorkerRegistration.showNotification().The guard that runs first,
canUseBrowserNotifications(), only checks permission, not whether the constructor is usable. It relies onNotificationPermission.getStatus(), which returnsgrantedwheneverwindow.Notificationexists and permission is granted.So the failure chain is:
window.Notificationexists + permissiongranted→canUseBrowserNotifications()resolvestrue→new Notification(...)throws → because the throw happens inside the.then()callback at line 51 with no.catch(), it surfaces as an unhandled promise rejection → caught by the globalonunhandledrejectionhandler → reported as APP-2D7.This explains every symptom in the report: web-only,
/r/:reportID(report comment notifications), Samsung Internet on Android, and theauto.browser.global_handlers.onunhandledrejectionmechanism.What changes do you think we should make in order to solve the problem?
Prefer the service-worker notification path, which is the only supported way to show notifications on the affected browsers. The app already registers a service worker in production.
In
push():registration.showNotification(title, {body, icon, data, silent, tag})instead ofnew Notification(...).try/catch..catch()to thecanUseBrowserNotifications()chain so any unsupported path degrades gracefully instead of becoming an unhandled rejection.Because
showNotification()does not return aNotificationinstance, the click/close wiring and the in-memorynotificationCache(lines 17 + 68–76 + 184–191) must move to the SW model: handle clicks via thenotificationclickevent, and implementclearNotificationswithregistration.getNotifications()+notification.close()(matching ondata) instead of the cache.What alternative solutions did you explore? (Optional)
Minimal stop-the-bleed: wrap the
new Notification(...)call intry/catchand add.catch()to the promise chain. This silences the crash but drops the notification entirely on affected browsers, so the service-worker approach is preferred for actually delivering them.Note on existing proposals
Two proposals are already posted.
lorretheboy's proposal correctly and thoroughly identifies the root cause and a sound fix — this analysis independently confirms it against the current code. The earlier proposal bygodzillaxbox19982014-lgtmis generic boilerplate that does not engage with the actualNotificationconstructor mechanism and should be disregarded.Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/93835#issuecomment-4732180029)to create a draft PR.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal.
aswin-s commentedon Jun 17, 2026
🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.
github-actions commentedon Jun 17, 2026
46 remaining items
mananjadhav commentedon Jul 31, 2026
@mountiny Do we have any reports on this issue? Or should this wait more for the payout?
mountiny commentedon Jul 31, 2026
This is ready for payment, the event did not happen for new versions
@mananjadhav you also have access to Sentry to check btw
mananjadhav commentedon Aug 2, 2026
It's a sentry issue. We don't need a checklist for this one.
mallenexpensify commentedon Aug 4, 2026
Payment Summary
Contributor: @lorretheboy paid $250 via Upwork
Contributor+: @mananjadhav due $250 via NewDot
@lorretheboy can you please accept the job below? Please reply here and tag me once you have.
If you're not sent an offer in Upwork when you're assigned to an issue, please tag me. If an Upwork job exists, please submit a proposal.
https://www.upwork.com/jobs/~022084481636816458622
lorretheboy commentedon Aug 4, 2026
@mallenexpensify Thx, I accepted it
garrettmknight commentedon Aug 4, 2026
$250 approved for @mananjadhav
mallenexpensify commentedon Aug 5, 2026
@lorretheboy paid, summary updated above. Thx.