From 055b27e7735ada12a88296aa99c2a2a06e3568c1 Mon Sep 17 00:00:00 2001 From: Hoel IRIS Date: Tue, 22 Dec 2020 16:37:16 +0100 Subject: [PATCH] feat(service-worker): Add to ErrorHandler that the error is from SW With Angular v11.0.4 and commit [_fix(service-worker): handle error with ErrorHandler_](https://github.com/angular/angular/pull/39990/commits/552419d) Angular start to send all service worker registration errors to the Angular standard `ErrorHandler.handleError()` interface, instead of logging them in the console. But service worker registration errors are a lot different than other code errors: - They are frequent, for example, they happen a lot with Chrome v84, Chrome v85, Firefox 84, and Samsung Internet v13. - Most applications can run even without a registered service worker. Use case example: - All errors send to `ErrorHandler.handleError()` show a `window.confirm` pop-up, so developers see the error right away during development, and users of the application have a huge error message before trying to use a broken application. - All errors from service worker registration are ignored, so users are not annoyed in that case. With the actual code, inside `ErrorHandler.handleError()`, we can't differentiate a service worker registration error from any other error, and service worker registration errors are already not clear at all, so we are losing a valuable piece of information. I propose to add a "source" of the error, like that service worker registration errors are cachable inside `ErrorHandler.handleError()`. --- packages/service-worker/src/module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/service-worker/src/module.ts b/packages/service-worker/src/module.ts index 0bc5e92c0c61d0..3c150e10e22f2a 100644 --- a/packages/service-worker/src/module.ts +++ b/packages/service-worker/src/module.ts @@ -130,7 +130,7 @@ export function ngswAppInitializer( () => readyToRegister$.pipe(take(1)).subscribe( () => navigator.serviceWorker.register(script, {scope: options.scope}).catch(err => { const errorHandler = injector.get(ErrorHandler); - errorHandler.handleError(err); + errorHandler.handleError({source: 'Service worker registration', error: err}); }))); }; return initializer;