question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

total is undefined in LoadingTask.onProgress

See original GitHub issue

Attach (recommended) or Link to PDF file here: https://jsfiddle.net/p3ybwp7d/1/

Configuration:

  • Web browser and its version: Google Chrome - Version 62.0.3202.75
  • Operating system and its version: Mac OS 10.13
  • PDF.js version: 1.10.97
  • Is a browser extension: No

Steps to reproduce the problem:

Create loading task and add onProgress callback:

let loadingTask: any = PDFJS.getDocument(this.src);

loadingTask.onProgress = (progressData) => {
  // progressData won't contain "total", only "loaded"
};

What is the expected behaviour? (add screenshot) In previous versions, onProgress did return both total and loaded.

What went wrong? (add screenshot) total field is undefined in loadingTask.onProgress callback.

Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension): https://jsfiddle.net/p3ybwp7d/1/

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
Snuffleupaguscommented, Nov 4, 2017

It’s related to fetch, since you can observe the same issue in Firefox too (with the dom.streams.enabled and javascript.options.streams prefs set in about:config).

1reaction
mwakermancommented, Apr 6, 2018

We just updated to 1.10.97 which broke our loading task. As a (hopefully temporary) workaround, we do a header-only fetch for the content-length header beforehand:

const total = await fetch(new Request(documentUrl, { method: 'HEAD', credentials: 'include' }))
    .then(res => parseInt(res.headers.get('content-length'), 10));
    
const loadingTask = window.PDFJS.getDocument({url: documentUrl, withCredentials: true});
loadingTask.onProgress = ({ loaded }) => {
    // do stuff with `loaded` and `total`
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is event.total in XMLHttpRequest always 0, unless ...
Everything seemed to to be just right, but the event.total -value was always 0 (or undefined in the angular-version.
Read more >
Bountysource
total is undefined in LoadingTask.onProgress.
Read more >
JSDoc: Source: api.js
@property {number} total - Total number of bytes in the PDF file. */; /**; * The loading task controls the operations required to...
Read more >
JSDoc: Source: display/api.js
"undefined") {; // The full path is required in the 'url' field. ... _worker = null;; /**; * Unique document loading task id...
Read more >
JSDoc: Source: display/api.js
'undefined') { // The full path is required in the 'url' field. ... _worker = null; /** * Unique document loading task id...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found