Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken progress with a service worker #427

Closed
BrightSoul opened this issue Apr 8, 2019 · 1 comment
Closed

Broken progress with a service worker #427

BrightSoul opened this issue Apr 8, 2019 · 1 comment

Comments

@BrightSoul
Copy link

BrightSoul commented Apr 8, 2019

Hello everyone and thanks for such a useful project!
I'm using Evaporate version 2.1.4 in a Progressive Web Application (w/ service worker, if that's important) and the multipart upload is working wonderfully well. It's just the progress that's not reporting correctly and I can't understand why. First of all, here's my code.

Evaporate.create({
    aws_key: "REDACTED",
    bucket: "REDACTED",
    awsRegion: "REDACTED",
    awsSignatureVersion: "4",
    computeContentMd5: true,
    logging: false,
    customAuthMethod: function(signParams, signHeaders, stringToSign, dateString, canonicalRequest) { return myCustomAuth(canonicalRequest); },
    cryptoMd5Method: function (data) { return md5.base64(data); },
    cryptoHexEncodedHash256: function (data) { return sha256.hex(data); }
}).then(function(ev) {
    var params = {
        name: "REDACTED",
        file: fileReference,
        complete: function ()
        {
            //do nothing
        },
        progress: function (percent, stats) {
            console.log(percent, stats);
        }
    };

    ev.add(params);
});

As you can see, I'm logging to console both the percent value and the stats object. Here's what I see in the console. Percent stays at 0 for a while, and then suddenly goes up to 1. At times, it will stay at 0 for the whole upload duration. A very few times it's indeed working correctly but I wasn't yet able to determine in which conditions. This happens in Chrome, Firefox and Edge so it's not browser dependent.

progress

Any advice on what might be causing this?
Thanks

@BrightSoul BrightSoul changed the title Broken progress Broken progress with a service worker Apr 8, 2019
@BrightSoul
Copy link
Author

BrightSoul commented Apr 8, 2019

Nevermind, this might actually be related to this:
w3c/ServiceWorker#1141

I was listening to the fetch event in the service worker. As soon as I removed this, it started working correctly.

self.addEventListener('fetch', function(e) {
  var dataUrl = 'v1';
  if (e.request.url.indexOf(dataUrl) > -1) {
    e.respondWith(fetch(e.request));
  } else {
    e.respondWith(
      caches.match(e.request).then(function(response) {
        if (!response) {
          //console.log("Couldn't fetch from response", e.request.url);
        }
        return response || fetch(e.request);
      })
    );
  }
});

I'm closing the issue as it's not directly related to Evaporate but I'm leaving this comment here since it could be useful to someone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant