angular: FetchEvent.respondWith error iOS/iPadOS 16.4+
Which @angular/* package(s) are the source of the bug?
service-worker
Is this a regression?
Yes
Description
I run an Angular application with version 14.2, and I encouter problems with Safari on iPhones and iPads running 16.4 or higher. The issue I’m having is that my application sometimes (really sometimes) shows the white page of death and sometimes Safari shows the Error: ‘FetchEvent.respondWith received an error: TypeError: Internal error’ without any further information. The app uses the angular service worker (for PWA support) and from what I have read on earlier issues with this kind of error, it might be cache related. Reloading the page solves this issue.
I’m really clueless at the moment how I can even work around this problem.
EDIT:
I was able to reproduce it on angular.io after a lot of refreshes on my Mac:
(Message is in dutch, saying it can’t load the page)
So it seems like there is some bug with the service worker in combination with Safari in general.
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
FetchEvent.respondWith received an error: TypeError: Internal error
Please provide the environment you discovered this bug in (run ng version
)
Angular CLI: 14.2.11
Node: 16.10.0
Package Manager: npm 7.24.0
OS: win32 x64
Angular: 14.2.7
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router
... service-worker
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1402.11
@angular-devkit/build-angular 14.2.11
@angular-devkit/core 14.2.11
@angular-devkit/schematics 14.2.11
@angular/cdk 14.2.5
@angular/cli 14.2.11
@schematics/angular 14.2.11
rxjs 7.5.7
typescript 4.7.4
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 120 (20 by maintainers)
Links to this issue
Commits related to this issue
- fix(service-worker): throw a critical error when `handleFetch` fails On Safari, the cache might fail on methods like `match` with an `Internal error`. Critical errors allows to fallback to `safeFetch... — committed to JeanMeche/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when `handleFetch` fails On Safari, the cache might fail on methods like `match` with an `Internal error`. Critical errors allows to fallback to `safeFetch... — committed to JeanMeche/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when `handleFetch` fails On Safari, the cache might fail on methods like `match` with an `Internal error`. Critical errors allows to fallback to `safeFetch... — committed to JeanMeche/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when `handleFetch` fails On Safari, the cache might fail on methods like `match` with an `Internal error`. Critical errors allows to fallback to `safeFetch... — committed to JeanMeche/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when `handleFetch` fails On Safari, the cache might fail on methods like `match` with an `Internal error`. Critical errors allows to fallback to `safeFetch... — committed to JeanMeche/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when `handleFetch` fails On Safari, the cache might fail on methods like `match` with an `Internal error`. Critical errors allows to fallback to `safeFetch... — committed to JeanMeche/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when `handleFetch` fails (#51885) On Safari, the cache might fail on methods like `match` with an `Internal error`. Critical errors allows to fallback to `... — committed to angular/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when handleFetch fails (#51885). Apply the workaround approved for Angular 16 to Angular 15 as in https://github.com/angular/angular/commit/c3d901eacfe8d03... — committed to janniemeyer/angular by janniemeyer 9 months ago
- fix(service-worker): throw a critical error when handleFetch fails #51885 patched a call site that threw an error but there were 2 others call that needed to be wrapped in the same way by a try/catch... — committed to JeanMeche/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when handleFetch fail This commit is a backport to 15.2 of #51960 and #50378 Throwing `SwCriticalError` allows the driver to fallback to `safeFetch` and en... — committed to JeanMeche/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when handleFetch fails (#51960) #51885 patched a call site that threw an error but there were 2 others call that needed to be wrapped in the same way by a ... — committed to angular/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when handleFetch fail (#51989) This commit is a backport to 15.2 of #51960 and #50378 Throwing `SwCriticalError` allows the driver to fallback to `safeFetc... — committed to angular/angular by JeanMeche 9 months ago
- add workaround for ios https://github.com/angular/angular/issues/50378 — committed to asdman384/exp-spsh by asdman384 6 months ago
- add workaround for ios https://github.com/angular/angular/issues/50378 — committed to asdman384/exp-spsh by asdman384 6 months ago
- add workaround for ios https://github.com/angular/angular/issues/50378 — committed to asdman384/exp-spsh by asdman384 6 months ago
- add workaround for ios https://github.com/angular/angular/issues/50378 — committed to asdman384/exp-spsh by asdman384 6 months ago
- fix(service-worker): throw a critical error when `handleFetch` fails (#51885) On Safari, the cache might fail on methods like `match` with an `Internal error`. Critical errors allows to fallback to `... — committed to ChellappanRajan/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when handleFetch fails (#51960) #51885 patched a call site that threw an error but there were 2 others call that needed to be wrapped in the same way by a ... — committed to ChellappanRajan/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when `handleFetch` fails (#51885) On Safari, the cache might fail on methods like `match` with an `Internal error`. Critical errors allows to fallback to `... — committed to wojtek1150/angular by JeanMeche 9 months ago
- fix(service-worker): throw a critical error when handleFetch fails (#51960) #51885 patched a call site that threw an error but there were 2 others call that needed to be wrapped in the same way by a ... — committed to wojtek1150/angular by JeanMeche 9 months ago
Any chance to see an official fix for this before the iOS 17 release next week?
@legege Have you used your workaround in production? Did you notice any drawbacks?
@gkalpak Sorry for bothering you but I saw you were active in similar topics (#26690 #26500), could you promote this to the angular team? It’s a pretty critical issue in my opinion since PWAs will stop working (at least it’s the case for the 2 I tested) with iOS17 next week
Workaround
I wrote a little script that adds the catch blocks to Angular’s service worker cache calls. It’s not tested thoroughly but it seems to work fine. Maybe it helps someone else.
package.json
scripts/service-worker-workaround.js
Currently angular.io still uses Angular 16.2 (so without any workarounds), so it isn’t a great repro example.
I’ve now a device with ios 17, I’ll try to do a more thorough investigation this week-end !
As far as i can tell the issue on Safari’s side was fixed with yesterday’s 17.2 release.
Looks like there is a fix in IOS 17.2 https://developer.apple.com/documentation/safari-release-notes/safari-17_2-release-notes
Bug 261767 - REGRESSION (iOS 17): PWA startup “FetchEvent.respondWith received an error TypeError: Internal error”
@madmurl0c Thanks, I forgot about that, this is definitly was I was looking for !
I’ve open #51960 !
Will the workaround also be backported to LTS versions 14 and 15?
@gudvincent this is what I wrote to manage the service worker. Hopefully it’ll work.
In
main.ts
:In
app.module.ts
:Feel free to improve this code and share it.
Yes, it’s working now.
There are several people who ask if it will be backported to Angular version 14 and 15, but no one answers. I will try to give some advice. “madmurl0c” script and postinstall solution will work for all versions. Just be aware where you put the script, otherwise correct the path so that it hits ngsw-worker.js:
const ngswWorkerFilePath = path.join(__dirname, '..', 'node_modules', '@angular', 'service-worker', 'ngsw-worker.js');
Maybe you will be able to run service-worker version 16.2.7 in Angular 14 and 15 applications, I don’t know, I haven’t tried. If you compare the servie-worker code from 14 to 16.2.7, there have been minor changes
npm install --save @angular/service-worker@16.2.7
Myself, I have copied Angular’s ngsw-worker.js and called it ngsw-worker-custom.js because I have added a lot of custom code to it. The downside with this solution is that I have to maintain the file myself. I want all the coolness that Angular is making. I’m doing catch for all cache operations for now so my iOS 17 users don’t see errors.
Be aware that you cannot fix a broken browser, in this case I think you can just ensure that your users do not see a white screen with the error message “FetchEvent.respondWith received an error TypeError: Internal error”. And maybe some caching will work…
Looking forward to seeing https://github.com/WebKit/WebKit/pull/18217 land in iOS…
This workaround to prevent that error has landed in
16.2.7
. Please update if you have that issue !cc @madmurl0c
I was facing the same problem today. Updating iOS to v17.2 worked for me. I’m using Angular v14.2.
It is on WebKit side, the rendering engine of Safari.
WebKit is an open source project that has identified and corrected the issue in their latest release.
It is Apple responsibility to include the updated version in Safari.
Since Safari updates with corresponding OS, we know from beta versions that iOS 17.2 (to be released) is including a version of Safari which relies on a corrected version of WebKit.
Hope that clarifies stuff.
Workaround: disable service worker on Safari versions that do not include the patch and trigger the bug. (By detecting corresponding OS version).
I think there is a misunderstanding due to alignment of angular versions with iOS versions. People are reporting that the fix of WebKit landed in the next release of safari from iOS 17.2. With that most likely all angular versions would work as before. The patches for this issue on angular side were more like catching the unhandled errors from the browser when crashing, but it was still not being able to use the service worker as before.
mounted 17.2-beta3 that solve the issue, in the meanwhile @tojacob solution works fine
I ended up non enabling service worker for ios 17. Lots of bugs
Because it is a webkit issue, not an Angular one.
Bug has been identified, resolved in webkit, and awaiting release in iOS.
Hi Folks, does anyone have any update about this? my current status is, the app is opening but still getting errors in the console
when a new version is deployed, the app keeps refreshing and doesn’t work anymore if I don’t reinstall it.
iOS: 17.1 Public Beta Angular: 16.2.8
Exactly, it is the same error. And SwUpdate not working anymore in my case
Looks like 15.2 will get the fix, I got green lit by the team to open #51989 👍
I updated angular to 16.2.7 but still have the same issue. iOS 17.0.2.
@vuthaphai Update to 16.2.7 or look for this workaround on StackOverflow
Not sure if the angular team is even aware of this bug, do you have any idea how to contact them? Maybe we should create a new Issue (with a more specific title like “Urgent! iOS17 breaks PWAs”, this one still says iOS 16.4)? Don’t want to bother the team unnecessarily but this issue seems quite important
Thanks for sharing @Yang-LiYing. I’ve integrated your changes (plus logging) in a branch here to troubleshoot with latest version: https://github.com/legege/angular/tree/ios17-fetch-repro
I confirm this is “working” (workaround). So far, I’ve seen the error being caught at ERR9 and ERR12 (see service worker console), but I guess it can surface in other areas.
Not an easy one to fix…
I’m also experiencing this with all iOS 17 public beta to date. @Yang-LiYing Could you explain which error catching you’ve implemented?
An update to this issue, the white page error was caused by a bug on Apple’s side, which is fixed by version 16.5: https://bugs.webkit.org/show_bug.cgi?id=256219
The other error shown in de browser is still present, even on iOS 17 beta. An repro will be difficult because it seems to be a timing issue related to communicating with the browser cache. In some rare cases it seems the cache is not ready yet to communicate with causing the Angular or browser’s service worker to run into issues. Debugging is difficult because this happens before the application is loaded.
But is there an official information on the release date? And since this is such a critical bug why don’t they backport it to 17.1.X with a patch release?
Hello All
Anyone can explain to me exactly this issue is MacOS OR Safari OR Angular side ???
Why is this closed? This is causing problems for my users currently
I tested the angular.io webapp. Good news it’s a PWA. If we install it on an iPad with IOS 17, then we switch to Plane mode, and then we launch it, we have the error we are talking about on this issue. The good news is that there is an app to test (offline), and it is angular.io
Hi, I did not apply the postinstall fix yet. I think you need to reinstall the PWA after going back to 16.2.7. At least, that’s what helped me.
Sometimes it’s blank screen, sometimes it has same can’t open page error
Quick update: the change that applies a workaround to avoid ServiceWorker crashing in Safari was released today in Angular v15.2.10, v16.2.8 and will also be available in upcoming v17.
@JeanMeche will the fix be available for Angular 15 as well ? Thanks for working on this issue !
Sorry I don’t have access to any apple device in the upcoming days, but… If I understand it correctly you worked around “ERR9”, but “ERR12” is still not fixed.
This part is still missing in the official fix. I hope it works to find the issue 😃
The question was asked before, but hasn’t had an answer yet as far as I can tell:
Will the workaround also be backported to LTS versions 14 and 15?
@hardik047 Could be because the old service worker was still loaded.
@madmurl0c The workaround was merged and should land in the next patch version (16.2.7 should land tomorrow or thursday I believe)
No debug log is empty…
Definitely, I agree, this looks like a Safari bug. The only thing that I’m saying that it seems that angular is doing something specific that triggers it, which likely means that it can be avoided.
I only have the issue with homescreen apps, and I can’t navigate at will in those. Since I switched my own PWA to workbox I cannot just add a hidden link there, either, so I’ll have to set up a test app that includes a link to
/ngsw/state
, and I don’t have enough time for that atm. I’ll look into it tonight, but maybe someone else can beat me to it 😏I’ve notified the team, we will investigate that !
Just to sum up, I’ve seen multiple reports of that issue :
Just to caution: as far as I can tell, the workaround is not a fix — the app may still break if the device is offline and the browser cache has expired.
I have switched to workbox and can confirm that the worker generated by workbox works fine. Whatever triggers this bug, it must be specific to @angular/service-worker .
Has anybody tried updating @angular/service-worker package to the last vestion?