Skip to content

Commit

Permalink
[Firefox] Block the "load" event until all pages are loaded, to ensur…
Browse files Browse the repository at this point in the history
…e that printing works (bug 1618553)
  • Loading branch information
Snuffleupagus authored and pull[bot] committed May 20, 2024
1 parent 73c04f5 commit 1766039
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,8 @@ const PDFViewerApplication = {
this.load(pdfDocument);
},
exception => {
this._unblockDocumentLoadEvent();

if (loadingTask !== this.pdfLoadingTask) {
return undefined; // Ignore errors for previously opened PDF files.
}
Expand Down Expand Up @@ -1420,6 +1422,8 @@ const PDFViewerApplication = {
});

pagesPromise.then(() => {
this._unblockDocumentLoadEvent();

this._initializeAutoPrint(pdfDocument, openActionPromise);
});

Expand Down Expand Up @@ -2335,6 +2339,19 @@ const PDFViewerApplication = {
return wholeTicks;
},

/**
* Should be called *after* all pages have loaded, or if an error occurred,
* to unblock the "load" event; see https://bugzilla.mozilla.org/show_bug.cgi?id=1618553
* @private
*/
_unblockDocumentLoadEvent() {
if (document.blockUnblockOnload) {
document.blockUnblockOnload(false);
}
// Ensure that this method is only ever run once.
this._unblockDocumentLoadEvent = () => {};
},

/**
* Used together with the integration-tests, to enable awaiting full
* initialization of the scripting/sandbox.
Expand Down
6 changes: 6 additions & 0 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ function webViewerLoad() {
}
}

// Block the "load" event until all pages are loaded, to ensure that printing
// works in Firefox; see https://bugzilla.mozilla.org/show_bug.cgi?id=1618553
if (document.blockUnblockOnload) {
document.blockUnblockOnload(true);
}

if (
document.readyState === "interactive" ||
document.readyState === "complete"
Expand Down

0 comments on commit 1766039

Please sign in to comment.