Title: zone.js: `unhandledrejection` listeners are never called by zone.js's own dispatch (`eventTask.invoke(evt)` passes the event as the task) · Issue #72159 · angular/angular · GitHub
Open Graph Title: zone.js: `unhandledrejection` listeners are never called by zone.js's own dispatch (`eventTask.invoke(evt)` passes the event as the task) · Issue #72159 · angular/angular
X Title: zone.js: `unhandledrejection` listeners are never called by zone.js's own dispatch (`eventTask.invoke(evt)` passes the event as the task) · Issue #72159 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? zone.js Is this a regression? No Description zone.js forwards an unhandled ZoneAwarePromise rejection to unhandledrejection listeners registered on window through findPromiseRejectio...
Open Graph Description: Which @angular/* package(s) are the source of the bug? zone.js Is this a regression? No Description zone.js forwards an unhandled ZoneAwarePromise rejection to unhandledrejection listeners register...
X Description: Which @angular/* package(s) are the source of the bug? zone.js Is this a regression? No Description zone.js forwards an unhandled ZoneAwarePromise rejection to unhandledrejection listeners register...
Opengraph URL: https://github.com/angular/angular/issues/72159
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"zone.js: `unhandledrejection` listeners are never called by zone.js's own dispatch (`eventTask.invoke(evt)` passes the event as the task)","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\nzone.js\n\n### Is this a regression?\n\nNo\n\n### Description\n\n\nzone.js forwards an unhandled ZoneAwarePromise rejection to `unhandledrejection` listeners registered on `window` through `findPromiseRejectionHandler` in `packages/zone.js/lib/browser/browser.ts` (zone.js 0.16.3, as in the Angular v22.2.6 tree):\n\n```ts\n// lib/browser/browser.ts, findPromiseRejectionHandler (line 313)\nconst evt = new PromiseRejectionEvent(evtName, {\n promise: e.promise,\n reason: e.rejection,\n});\neventTask.invoke(evt);\n```\n\nA listener added to `window` with the patched `addEventListener` is an event task created with `useG: true` (`OPTIMIZED_ZONE_EVENT_TASK_DATA`, `lib/common/events.ts` line 84), and for such a task the `ZoneTask` constructor does not make a closure:\n\n```ts\n// lib/zone-impl.ts, ZoneTask constructor (lines 1417-1418)\nif (type === eventTask && options && (options as any).useG) {\n this.invoke = ZoneTask.invokeTask;\n}\n```\n\n`ZoneTask.invokeTask` is the static `invokeTask(task, target, args)` (line 1426), so `eventTask.invoke(evt)` passes the event as the task: `task.zone.runTask(...)` throws a TypeError because `evt.zone` is undefined. `handleUnhandledRejection` (`lib/common/promise.ts` line 82) swallows the error with `catch (err) {}`, so the listener is never called and nothing is reported.\n\nzone.js's own global event callback calls the same function with the task first: `task.invoke(task, target, [event])` (`lib/common/events.ts` line 239). Calling it that way in `findPromiseRejectionHandler`, `eventTask.invoke(eventTask, global, [evt])`, looks like the fix for `useG` tasks. That is a suggestion only; we have not tested it against the suite.\n\n#### Why the zone.js test still passes in Chrome and Safari\n\n`packages/zone.js/test/common/zone.spec.ts`, \"should surface unhandled promise rejections via unhandledrejection event (if the flag is enabled)\", passes in Chrome and Safari for a different reason. In those two browsers `PromiseRejectionEventInit.promise` is still typed `Promise\u003cany>` (Blink `third_party/blink/renderer/core/events/promise_rejection_event_init.idl`; WebKit `Source/WebCore/dom/PromiseRejectionEvent.idl`). So `new PromiseRejectionEvent(..., {promise: zoneAwarePromise})` resolves the ZoneAwarePromise thenable into a new native promise, which rejects with the same reason, and nothing handles it. The browser itself then fires a native `unhandledrejection` with that native promise, and the listener receives that event. The `An error was thrown in a Promise outside a test` line in Chrome's test log is jasmine's handler seeing the same native rejection.\n\nThe HTML Standard changed the member to `required object promise` in whatwg/html#9897 (merged 2023-12-12). Firefox ships that (`dom/webidl/PromiseRejectionEvent.webidl`), so no native promise is made and the listener is never called. whatwg/html#11547 records that Chrome and Safari still differ from the spec here. As soon as a browser follows the current spec, the test fails there, and zone.js applications never receive `unhandledrejection` for ZoneAwarePromise rejections. That happens in Firefox today, and in any browser engine that follows the current spec, as Firefox does.\n\n\n### Related issues\n\n#51357 and #55590 report that `new PromiseRejectionEvent(...)` in the same function throws when `e.promise` is undefined, which happens when `DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION` is `true` (the default since #52492). This report is the failure behind that one: with the flag `false`, as zone.js's own browser tests set it, the event constructs, and dispatch then fails at `eventTask.invoke(evt)`. Fixing the constructor's input alone will not make listeners fire.\n\n**Expected:** zone.js calls the listener with the event it built (its `promise` is the ZoneAwarePromise, `reason` is `'Error happened :('`) in every browser, whatever the browser's `PromiseRejectionEventInit` type.\n\n### Please provide a link to a minimal reproduction of the bug\n\nSelf-contained page below (no link needed).\n\n\nServe this page next to `zone.umd.js` (zone.js 0.16.3, `bundles/zone.umd.js`) from any static HTTP server and open it. The first script sets the same flag the zone.js browser tests set (`test/browser-zone-setup.ts`).\n\n```html\n\u003c!doctype html>\u003cbody>\n\u003cscript>window.__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = false;\u003c/script>\n\u003cscript src=\"zone.umd.js\">\u003c/script>\n\u003cscript>\nconst log = (...a) => console.log(a.map(String).join(' '));\nwindow.onerror = () => {};\nconst sym = Zone.__symbol__('unhandledPromiseRejectionHandler');\nconst orig = Zone[sym];\n// Only records whether zone.js's own dispatch throws; it constructs no event itself.\nZone[sym] = function (e) {\n try { orig.call(this, e); log('zone dispatch returned'); } catch (err) { log('zone dispatch threw: ' + err); }\n};\nwindow[Zone.__symbol__('enable_native_microtask_draining')] = true;\nlet calls = 0;\nZone.current.fork({name: 'probe'}).run(() => {\n window.addEventListener('unhandledrejection', (e) => {\n calls++;\n log('listener call ' + calls + ': reason=' + e.reason +\n ' native promise=' + (e.promise instanceof window[Zone.__symbol__('Promise')]));\n });\n const s = document.createElement('script');\n s.innerHTML = \"Promise.reject('Error happened :(')\";\n document.body.append(s);\n});\nsetTimeout(() => log('result: listener calls=' + calls), 100);\n\u003c/script>\n```\n\nThe wrapper calls the original handler inside a `try`, so the TypeError that zone.js swallows shows up in the console.\n\n#### Results (2026-11-22)\n\n| Browser | zone.js's dispatch | listener calls |\n|---|---|---|\n| Chrome for Testing 157 | `TypeError: Cannot read properties of undefined (reading 'runTask')` | 1: the event's promise is a native promise, not the ZoneAwarePromise |\n| Safari 27.0 | `TypeError: undefined is not an object (evaluating 'task.zone.runTask')` | 1: the event's promise is a native promise |\n| Firefox 159.0 | `TypeError: can't access property \"runTask\", task.zone is undefined` | 0 |\n\nzone.js's own dispatch throws in all three browsers. Chrome and Safari call the listener only through the native rejection that their `Promise\u003cany>` conversion creates.\n\n\n### Please provide the exception or error you saw\n\n```\nChrome 157: TypeError: Cannot read properties of undefined (reading 'runTask')\nSafari 27: TypeError: undefined is not an object (evaluating 'task.zone.runTask')\nFirefox 159: TypeError: can't access property \"runTask\", task.zone is undefined\n```\n\nThe error is swallowed by the `catch (err) {}` in `handleUnhandledRejection` (`lib/common/promise.ts` line 82).\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```\nzone.js 0.16.3 (Angular v22.2.6 repository, `packages/zone.js`)\nChrome for Testing 157, Safari 27.0, Firefox 159.0 on macOS\n```\n\n### Anything else?\n\nwhatwg/html#9897 (merged 2023-12-12) changed `PromiseRejectionEventInit.promise` to `required object`; whatwg/html#11547 tracks Chrome and Safari still converting it to a native promise.\n","author":{"url":"https://github.com/bcardarella","@type":"Person","name":"bcardarella"},"datePublished":"2026-11-22T16:19:36Z","url":"https://github.com/angular/angular/issues/72159"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9305f3ab-4b55-af08-d69b-e0015f050c67 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8256:1D768B:83C2D8:AB2D96:6B062D2B |
| html-safe-nonce | 67cc06e3f5fd337134df955b9c1960ccafc51e7f9cbed6e18397802fdf2edc6a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjU2OjFENzY4Qjo4M0MyRDg6QUIyRDk2OjZCMDYyRDJCIiwidmlzaXRvcl9pZCI6IjkwNjUxNTA3ODY0MDUwMTg5MjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6294f0c1b1a0f13aa2fb835e200d7478b3be2af86d69ea406adb072fbceba0e5 |
| hovercard-subject-tag | issue:6544724812 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/72159/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ac5f2db7ff9b6214aa232690a3c1fe36777bd04afaed52340e02eb56246b2df8/angular/angular/issues/72159 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ac5f2db7ff9b6214aa232690a3c1fe36777bd04afaed52340e02eb56246b2df8/angular/angular/issues/72159 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? zone.js Is this a regression? No Description zone.js forwards an unhandled ZoneAwarePromise rejection to unhandledrejection listeners register... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bcardarella |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7f961de5dd5c5d4aca24d33f8b3ffb3fb8b2ef53d0a4f32f01f0a790e512f6d3 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 494ea0bb1e0feef734a83e2628697647755e8864 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width