Repository navigation
Description
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"
}
}
Activity
Squidy06 commentedon Jun 17, 2019
@naturalfreak did you find a solution?
naturalfreak commentedon Jun 18, 2019
No, I tested it in new project with enabled service workers and I faced same issue. But safari loads both module and nomodule scripts.
hassanasad commentedon Jun 18, 2019
I can report similar issue - Its not working on my existing project, i created a new one following the steps mentioned here https://angular.io/guide/service-worker-getting-started and its giving same Rejected promise issue.
TypeError: TypeError: Type errorSafari 12.1.1 (14607.2.6.1.1)
NG versions
gkalpak commentedon Jun 19, 2019
Sorry, I don't have access to Safari 😞
After spending quite some time trying to debug this on SauceLabs, I finally gave up (because SauceLabs seems to be behaving strangely - sometimes giving the error and sometimes not 🤷♂).
If someone with native access to Safari 12 could debug this further and provide more info, I would be happy to help.
Things I would try out:
ngsw-worker.jswith the v7 ngsw-worker.js (and leave everything else the same).@angular/service-workercode inmain-es2015.jswith the v7 code.optimizationturned off inangular.json.optimizationturned on butbuildOptimizerturned off inangular.json.H--o-l commentedon Jun 19, 2019
Hey @gkalpak.
I'm just in front of the error in a Safari v11.1.2.
I try the v7
ngsw-worker.jsand I can confirm it register without error, while the v8.0.1 do not register.I'm not sure to understand the flowing line, can you give us more details?
I will try the rest, thanks!
gkalpak commentedon Jun 19, 2019
Thx, @H--o-l. So, are you saying that just by replacing
ngsw-worker.jswith the v7 version it starts working (while leaving everything else unchanged, including leaving@angular/service-workerto v8)?If that's the case, then it shouldn't be hard to identify the issue, because the changes in
ngsw-worker.jsbetween v7 and v8 are minimal.H--o-l commentedon Jun 19, 2019
Yes exactly
Great suggestion.
Maybe I found the line:
If I apply the following patch to the
ngsw-worker.jsfile, I do not have the issue anymore,It register but goes in
SAFE_MODEorEXISTING_CLIENT_ONLYwith:In Chrome the same service worker works fine.
gkalpak commentedon Jun 19, 2019
That's strange. I wonder if Safari doesn't like cche names that include
/.Could you try (a) to replace
/with_and (2) log more info about the error?H--o-l commentedon Jun 19, 2019
I have a better diff, that make more sense.
My assumption is that safari does not like that the second argument of
parseUrl()is missing.With that change the service worker is in the
NORMALstate, and works offline.H--o-l commentedon Jun 19, 2019
Sorry the diff was inverted:
H--o-l commentedon Jun 19, 2019
Ok, I change
/and_and log all the/ngsw/statetrace :Can you tell me if #31061 (comment) seems like a good lead to you ?
gkalpak commentedon Jun 19, 2019
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:
parseUrl(url: string, relativeTo?: string): {origin: string, path: string, search: string} { - const parsed = new URL(url, relativeTo); + const parsed = !relativeTo ? new URL(url) : new URL(url, relativeTo); return {origin: parsed.origin, path: parsed.pathname, search: parsed.search}; }@H--o-l, would you like to submit a PR with that fix (after verifying that it does indeed work 😁)?
H--o-l commentedon Jun 19, 2019
Thanks a lot @gkalpak for the final kick & diff!
It works great in my environment for what I see.
I opened the PR, I let you tell me there you think about it.
Thanks again!
naturalfreak commentedon Jun 19, 2019
Thanks @gkalpak, I tested these modifications and everything works as expected in my projects.
fix(service-worker): registration failed on Safari (#31140)
hassanasad commentedon Aug 5, 2019
@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
H--o-l commentedon Aug 6, 2019
@hassanasad Thanks for your comment.
An aswer that is mine only, I'm not part of the Angular team:
Your bug does not seem related to this issue which is closed, because the bug was found and fixed.
If you have an issue configuring your service worker for the first time, you should ask on stackoverflow.
If you have notice a regression, or have found a bug (you have to be pretty sure), please open a new issue.
When opening a new issue, all details needed to be able to assist you will be asked and organized, that is why it's important to open a seperate issue.
Finally, seen your error I think it's:
It's not against you, and you are right to ask when you have issue.
But first be sure to have debug a bit, and search already existing answers on Internet a lot.
Otherwise you may not receive answer at all.
hassanasad commentedon Aug 6, 2019
@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
PragmaandCache-controlheaders 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)
angular-automatic-lock-bot commentedon Sep 15, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.