Skip to content

iOS 11.3 new service worker safari hangs on image upload #23244

Closed

Description

@MatteoNY

Build:
Angular CLI: 1.7.3
Node: 8.1.4
OS: darwin x64
Angular: 5.2.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

@angular/cdk: 5.2.4
@angular/cli: 1.7.3
@angular/flex-layout: 5.0.0-beta.14
@angular/material: 5.2.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.7.2
webpack: 3.11.0

New Safari Experimental service worker is on by default and works fine
as long as you do not upload an image in your PWA then it appears to hang. Getting some sort of Firebase storage issue. If I turn off Safari service worker my app works as expected.
Using latest firebase angularfire2 storage with task to show pre-loader (using angularfire2 based on David East's blog (see below). PWA worked fine before iOS 11.3 update but with service worker on by default will fail if uploading an image. In the prior iOS release there was an bug when using the camera if the PWA was added to home screen the camera was disabled. Apple fixed the camera bug with iOS 11.3.
David East's Blog to upload image using Angular Angularfire2:
https://blog.angular.io/file-uploads-come-to-angularfire-6842352b3b47

Getting Firebase error from Safari Desktop macOS High Sierra version 10.13.4 (Apr 2018 update)
code_: "storage/unknown"
message_: "Firebase Storage: An unknown error occurred, please check the error payload for server response."
name_: "FirebaseError"
serverResponse_: "Client uploaded to the wrong offset (262144 instead of 0)."

NOT SURE IF A NEW ANGULAR POLYFILL IS NEEDED TO ENABLE SERVICE WORKERS.

THANKS!

FOUND ISSUES WITH SAFARI AND SERVICE WORKERS ENABLED HANGS ANGULAR PWA USING ANGULARFIRE2 UPLOAD.

  • Chrome (Android) version XX
  • Chrome (iOS) version XX
  • Firefox version XX
  • [ x] Safari (desktop) version XX
  • [ x] Safari (iOS) version XX
  • IE version XX
  • Edge version XX

Activity

  1. markgoho commented on Apr 8, 2018

    @markgoho
    Contributor

    @MatteoNY consider opening an issue over at the AngularFire2 repo for this issue you're experiencing.

    As far as what it takes to enable service workers, there is very good documentation here: https://angular.io/guide/service-worker-intro

  2. added
    area: service-worker
    on Apr 10, 2018
  3. added this to the needsTriage milestone on Apr 10, 2018
  4. MatteoNY commented on Apr 13, 2018

    @MatteoNY
    Author

    Mark: (markgoho) thanks for the suggestion to review the Angular.io docs.

    I subscribe to #AskFirebase on YouTube.com a video on PWAs mentioned that service-workers need to ignore Firebase's dynamic data because it has advanced offline features.
    https://youtu.be/iHqqUoqvYx4

    This was an Ah-ha moment! After reading more about service-workers, I'm not exactly clear on what to put in the ngsw-config.json file to ignore dynamic Firebase. I don't want it to also ignore static assets.

    I've been following PWA's since the last ng-conf and I've taken a course on Udemy where the instructor got into writing a service-worker. My preference is to use the one with the Angular CLI.
    I can experiment with ngsw-config.json file but I'd rather spend the time exploring Angular Elements.

    I have a few suggestions:

    1. A how to guide on Angular.io on how exclude dynamic data from a service (Firebase where it's not needed - as per the video). For example, visit Chrome's network tab and view dynamic/static data and to add a node, for example, under the dataGroups add: ", { name: firebase-dynamic: !**firebase }" in the ngsw-config.json file. I'm making this up, but it would be nice to know.

    2. Add a new feature to Chrome's Lighthouse to use it's magic to inform me that since I'm using Firebase add this to your ngsw-config.json file to ignore dynamic Firebase data (not needed), static data will persist :-). Possibly a URL to a tutorial (suggestion 1) on how to optimize your service-worker when using Firebase.

    As I've mentioned in prior post, if I disable the service-worker via the main.ts ( // navigator.serviceWorker.register('/ngsw-worker.js');). My app works as expected on Safari (Mac and iPhone) as well as the other browsers.

    This appears to not to be a service-worker bug but a configuration for the service-worker.
    I hope the above helps.

    Many thanks,
    Matt

  5. modified the milestones: needsTriage, Backlog on Apr 24, 2018
  6. aSegatto commented on Jul 12, 2018

    @aSegatto

    We are experiencing a similar issue while uploading a text file. We excluded firebase comunications from the ngsw cache by adding :

    
    "dataGroups": [
        {
          "name": "firebase",
          "urls": [
            "https://firebasestorage.googleapis.com/**"
          ],
          "cacheConfig": {
            "timeout":"10s",
            "maxSize": 10,
            "maxAge": "1s",
            "strategy": "freshness"
          }
        }
      ]
    

    in the ngsw-config file, but nothing changed. Error occurs only on safari . We opened an issue #24853

  7. gkalpak commented on Jul 12, 2018

    @gkalpak
    Member

    Just to add some info, (despite what that video says about Angular's SW implementation) I don't think you need any special configuration to not cache specific requests. The SW will only cache what it is explicitly configured to cache.

  8. aSegatto commented on Jul 13, 2018

    @aSegatto

    Ok, how can we further investigate what's happening ? is there a way to see what's going on in the service worker ?
    We believe that posting data to a cloud function without multi part should avoid this issue, but we 'd like to do this as the last option.

  9. gkalpak commented on Jul 13, 2018

    @gkalpak
    Member

    SWs are just javascript code, so you can debug them as usual (add breakpoints etc). That's what I would do if I wanted to investigate an issue like this.

  10. arikanorh commented on Aug 1, 2018

    @arikanorh

    I'm current hitting the same problem. It doesnt work on Safari on iOS. But cant debug since i cant see the console

  11. 9 remaining items

  12. GIOkafor commented on Jan 29, 2019

    @GIOkafor

    following @uufish suggestion I am now using replace-in-file from npm
    I run this after my build.

    It excludes the firebase API from service worker caching...

    const replace = require('replace-in-file');
    const options = {
      files: 'dist/browser/ngsw-worker.js',
      from: `onFetch(event) {`,
      to: `onFetch(event) {
            if (event.request.url.indexOf('firebasestorage.googleapis.com') !== -1) { return; }`,
    };
    
    replace(options)
      .then(changes => {
        console.log('Modified files:', changes.join(', '));
      })
      .catch(error => {
        console.error('Error occurred:', error);
      });
    

    Does that go in your main.ts file?

  13. koraysels commented on Jan 29, 2019

    @koraysels

    @GIOkafor no it is a separate js file, I do this after the build command. To do so you can an script property in your package.json. Or of you use pm2 to deploy you can run it with pm2 after ‘ng build —prod’

  14. avilao commented on Feb 18, 2019

    @avilao

    But that removes caching completely right? Not just for safari.

  15. Robstaer commented on Feb 25, 2019

    @Robstaer

    Is there a new update on this matter? I'm having the same problem: PWA on IOS breaks the image upload to firestorage, both in the webbrowser as well as in the app...

  16. maxime1992 commented on Feb 26, 2019

    @maxime1992

    Had to remove the service worker from prod because of that.
    We've got plenty of tests, unit, integration and also E2E with Cypress but as Cypress doesn't support service workers correctly (few issues but basically it'd also cache the tests) we deactivate them while doing E2E testing. So everything was green and we thought we were ok deploying to prod. 🤕

    As they're doing agressive caching on the client side it's a bit 😱 too and the service worker module should just work flawlessly because it's really really hard after deploying to prod with a service worker to expect all the clients to behave correctly after...

  17. koraysels commented on Feb 26, 2019

    @koraysels

    But that removes caching completely right? Not just for safari.

    No it just disables it for firebasestorage requests...

  18. avilao commented on Mar 4, 2019

    @avilao

    But that removes caching completely right? Not just for safari.

    No it just disables it for firebasestorage requests...

    Sorry my question wasn't specific. It disables firestoredatabase requests in all browsers, right?

  19. Robstaer commented on Mar 14, 2019

    @Robstaer

    Why is this issue closed, even though not resolved yet?
    @koraysels advice cannot be a long-term solution =/

  20. shigurenimo commented on Mar 18, 2019

    @shigurenimo

    @gkalpak Please open this issue again. You can see bugs at this URL on iOS 12.1.4.

    failed with error: Firebase Storage: An unknown error occurred, please check the error payload for server response.
    
  21. gkalpak commented on Mar 18, 2019

    @gkalpak
    Member

    As mentioned in #23244 (comment), this is a limitation in some browser's fetch implementation. There are some work arounds mentioned on this thread and the ability to "properly" work around such limitations is tracked in #21191 (hence this issue is closed).

  22. jek-bao-choo commented on Aug 3, 2019

    @jek-bao-choo

    For those using AngularFire2, this issue is also mentioned
    angular/angularfire#1439
    angular/angularfire#1909

  23. angular-automatic-lock-bot commented on Sep 15, 2019

    @angular-automatic-lock-bot

    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.

  24. locked and limited conversation to collaborators on Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: service-workerfreq1: lowtype: bug/fix

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions