{"id":2339,"date":"2020-02-06T22:27:34","date_gmt":"2020-02-06T22:27:34","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=2339"},"modified":"2020-02-20T16:37:48","modified_gmt":"2020-02-20T16:37:48","slug":"zone-js-gives-errors-if-promise-code-is-patched-via-external-js-after-zone-is-loaded","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=2339","title":{"rendered":"Zone.js gives errors if Promise code is patched via external js after zone is loaded"},"content":{"rendered":"<p>When integrating a microapp which uses the Yoti identity platform for age verification, I hit issues where other microapps would fail to load after the Yoti\/age verification microapp had loaded.<\/p>\n<p>The following error appeared on the browser console:-<\/p>\n<blockquote><p>Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.<br \/>\nMost likely cause is that a Promise polyfill has been loaded after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. If you must load one, do so before loading zone.js.)<br \/>\nat Function.push..\/node_modules\/zone.js\/dist\/zone.js.Zone.assertZonePatched (polyfills.js:6911)<br \/>\nat new NgZone (vendor.js:42512)<br \/>\nat getNgZone (vendor.js:43220)<br \/>\nat PlatformRef.push..\/node_modules\/@angular\/core\/fesm5\/core.js.PlatformRef.bootstrapModuleFactory (vendor.js:43116)<br \/>\nat vendor.js:43162<br \/>\nat <a href=\"http:\/\/www.yoti.com\/:1\">www.yoti.com\/:1<\/a><\/p><\/blockquote>\n<p>A similar instance of this issue, where Bing loads after zone.js and similarly patches promise code, is detailed <a href=\"https:\/\/github.com\/angular\/zone.js\/issues\/465\">here<\/a>.<\/p>\n<p>In my case the culprit was the Yoti client SDK, which did the patching\/overwriting. A temporary fix, which worked successfully, was to load the Yoti SDK in index.html, prior to the angular bootstrap process, and remove\/disable my existing code which loaded the SDK dynamically via a script tag (after zone had loaded).<\/p>\n<p>My final solution was to use an Angular app initializer token, which permits a custom initialise function to be created. This can perform\u00a0 an asynchronous operation to be performed which returns a promise to the app initialiser, which allows bootstrapping to continue only when the promise has succeeded.<\/p>\n<p>The details of this implementation are in a separate post, <strong><a href=\"https:\/\/salientsoft.co.uk\/?p=2346\">here<\/a><\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When integrating a microapp which uses the Yoti identity platform for age verification, I hit issues where other microapps would fail to load after the Yoti\/age verification microapp had loaded. The following error appeared on the browser console:- Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten. Most likely cause is that a Promise [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[198,77],"tags":[],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2339"}],"collection":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2339"}],"version-history":[{"count":3,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2339\/revisions"}],"predecessor-version":[{"id":2358,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2339\/revisions\/2358"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}