angular: Service worker registration failed in Safari angular 8
I updated my application from angular v7 to angular v8 and I have some problems with service workers with Safari. I have same error when enter in www.angular.io
[Error] Service worker registration failed with: TypeError: TypeError: Type error run (polyfills-es2015.75c15c263061f321fee9.js:1:1925) (anonymous function) (polyfills-es2015.75c15c263061f321fee9.js:1:12750) runTask (polyfills-es2015.75c15c263061f321fee9.js:1:2544) _ (polyfills-es2015.75c15c263061f321fee9.js:1:8987) promiseReactionJob
Safari Version 12.1.1 (14607.2.6.1.1) MacOs Mojave v10.14.5 Node v10.16.0
My package.json
{ “dependencies”: { “@angular/animations”: “^8.0.1”, “@angular/cdk”: “^8.0.1”, “@angular/common”: “^8.0.1”, “@angular/compiler”: “^8.0.1”, “@angular/core”: “^8.0.1”, “@angular/forms”: “^8.0.1”, “@angular/material”: “^8.0.1”, “@angular/platform-browser”: “^8.0.1”, “@angular/platform-browser-dynamic”: “^8.0.1”, “@angular/platform-server”: “^8.0.1”, “@angular/pwa”: “^0.800.3”, “@angular/router”: “^8.0.1”, “@angular/service-worker”: “^8.0.1”, “@nguniversal/express-engine”: “^8.0.0-rc.1”, “@nguniversal/module-map-ngfactory-loader”: “^8.0.0-rc.1”, “compression”: “^1.7.4”, “tslib”: “^1.10.0”, “rxjs”: “~6.4.0”, “zone.js”: “~0.9.1” }, “devDependencies”: { “@angular-devkit/build-angular”: “^0.800.3”, “@angular/cli”: “^8.0.3”, “@angular/compiler-cli”: “^8.0.1”, “@angular/language-service”: “^8.0.1”, “@types/express-useragent”: “^0.2.21”, “@types/jasmine”: “^3.3.13”, “@types/jasminewd2”: “^2.0.6”, “@types/node”: “^12.0.8”, “codelyzer”: “^5.1.0”, “express”: “^4.17.1”, “jasmine-core”: “~3.4.0”, “jasmine-spec-reporter”: “~4.2.1”, “karma”: “~4.1.0”, “karma-chrome-launcher”: “~2.2.0”, “karma-coverage-istanbul-reporter”: “~2.0.1”, “karma-jasmine”: “~2.0.1”, “karma-jasmine-html-reporter”: “^1.4.0”, “protractor”: “^5.4.2”, “ts-loader”: “^6.0.2”, “ts-node”: “^7.0.1”, “tslint”: “^5.17.0”, “typescript”: “~3.4.5”, “webpack-cli”: “^3.3.4” } }
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (11 by maintainers)
Commits related to this issue
- fix(service-worker): registration failed on Safari Since Angular v8, `parseUrl()` is called without `relativeTo`, thus `new URL()` is called with `relativeTo = undefined`. Safari does not like it an... — committed to H--o-l/angular by H--o-l 5 years ago
- fix(service-worker): registration failed on Safari Since Angular v8, `parseUrl()` is called with `relativeTo`, thus `new URL()` is called with `relativeTo = undefined`. Safari does not like it and t... — committed to H--o-l/angular by H--o-l 5 years ago
- fix(service-worker): registration failed on Safari Since Angular v8, `parseUrl()` is called without `relativeTo`, thus `new URL()` is called with `relativeTo = undefined`. Safari does not like it an... — committed to H--o-l/angular by H--o-l 5 years ago
- fix(service-worker): registration failed on Safari Since Angular v8, `parseUrl()` is called without `relativeTo`, thus `new URL()` is called with `relativeTo = undefined`. Safari does not like it an... — committed to H--o-l/angular by H--o-l 5 years ago
- fix(service-worker): registration failed on Safari Since Angular v8, `parseUrl()` is called without `relativeTo`, thus `new URL()` is called with `relativeTo = undefined`. Safari does not like it an... — committed to H--o-l/angular by H--o-l 5 years ago
- fix(service-worker): registration failed on Safari Since Angular v8, and commit [b3dda0e], `parseUrl()` can be called without `relativeTo`, thus `new URL()` can be called with `relativeTo = undefined... — committed to H--o-l/angular by H--o-l 5 years ago
- fix(service-worker): registration failed on Safari Since Angular v8, and commit b3dda0e, `parseUrl()` can be called without `relativeTo`, thus `new URL()` can be called with `relativeTo = undefined`.... — committed to H--o-l/angular by H--o-l 5 years ago
- fix(service-worker): registration failed on Safari (#31140) Since Angular v8, and commit b3dda0e, `parseUrl()` can be called without `relativeTo`, thus `new URL()` can be called with `relativeTo = un... — committed to angular/angular by H--o-l 5 years ago
@H--o-l Thanks for your thoughtful reply. Yes you are right. We have found the issue and resolved it and initially it felt like a regression but after doing intense debugging it appears to have been an error occurring due to some library updates on Server Side.
It was indeed a bug that was only showing up in Safari when the ServiceWorker was trying to send a POST request to server and being denied access. Everything was working fine on Chrome and Firefox. Safari was adding
Pragma
andCache-control
headers with the service worker request which were being denied on the server because they weren’t in the allowed headers list. I cannot seem to understand why we are unable to reproduce this error using Postman. Anyways - Yes, what appeared to have been a regression was NOT actually a regression (but it was indeed quite weird issue to debug)@kara Service worker using Safari is not working in Angular 8.2.0 anymore. The POST requests are giving Gateway 504 errors.
UPDATE: This is the error i am getting
2nd UPDATE: Turns out the error was coming in Safari due to some server side configuration. Its not a regression in Angular 8.2.0
Wow, that’s awesome. Great sleuthing, @H--o-l 👏 It seems indeed to be the case that Safari chokes when the second argument is
undefined
(or even''
), even though according to MDN:But it is fine, when the second argument is not provided at all:
So, I guess we could work-around that by changing Adapter#parseUrl() like this:
@H--o-l, would you like to submit a PR with that fix (after verifying that it does indeed work 😁)?
Ok, I change
/
and_
and log all the/ngsw/state
trace :Can you tell me if https://github.com/angular/angular/issues/31061#issuecomment-503631576 seems like a good lead to you ?
No, I tested it in new project with enabled service workers and I faced same issue. But safari loads both module and nomodule scripts.