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

Update progress meter should work #1419

Closed
arantius opened this issue Sep 23, 2011 · 7 comments
Closed

Update progress meter should work #1419

arantius opened this issue Sep 23, 2011 · 7 comments
Milestone

Comments

@arantius
Copy link
Collaborator

See #1053

When downloading a script update, currently the download meter never fills, it just appears empty, then at some later point disappears.

@arantius
Copy link
Collaborator Author

So! It was a little annoying to shfit things around so that enough progress data could flow where it needed to be, but rather straightforward. Once I did that, however, I started trying to actually track progress, and I can't find a way to download a file and (reliably) actually know how much of it has been downloaded, while the download is happening -- rather crucial for a progress meter.

The problem is basically that user scripts are text files, and likely to be gzip encoded. The only reliably "total length" data we have is the "Content-Length" HTTP header. In the case of gzip compression however, that number cannot be compared to the "length we've downloaded so far" and I get stuck.

@sizzlemctwizzle
Copy link
Contributor

Use a progress listener?

var req = new XMLHttpRequest();
res.open('GET', 'script.user.js', true);
req.addEventListener("progress", function(evt) {
  var loaded = evt.loaded;
  var total = evt.total;
  var percentLoaded = Math.floor(loaded / total) * 100;
});
res.send(null);

@arantius
Copy link
Collaborator Author

In that case, "total" is the http-header-content-length value. In the example I was testing (very repetitive comment text) it was 1701, although the final "total" value was well over 400,000 (thanks to gzip decompression). That's exactly the problem I was describing.

Other tests with nsIWebBrowserPersist and its progressListener went better, but it's not consistently used in ScriptDownloader now. Thus #1458.

@sizzlemctwizzle
Copy link
Contributor

Are the loaded and total values consistent in relation to each other? After all it's just relative. You just need a percent, right?

@arantius
Copy link
Collaborator Author

No. -Gzip is not deterministic.- Edit: the length output of gunzip is not a fixed ratio based on the length of its input, it depends on the actual content.

@sizzlemctwizzle
Copy link
Contributor

And the evt.total is the length of the original file, not the gzipped file? And the value given by evt.loaded is how much of the gzipped file has been downloaded? If that's true then how does anybody get download progress bars right?

@Martii
Copy link
Contributor

Martii commented Oct 29, 2011

Just a note here... some servers aren't configured or capable of sending the file size on the request and basically a 0, 1, 2, 3, ... 100% meter is not always possible which is when the "cylon" (or some other names too rich for posting) meter is usually used. Since GM can install from anywhere this should be a factor to consider as well as dynamically generated scripts that don't know until they are finished.

#1451 might be a good mid to short term solution until this gets fully explored and developed.

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

3 participants