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

Consistently remove the "visibilitychange" listener in PDFViewer (PR 14388 follow-up) #17508

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions web/pdf_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ class PDFViewer {
return params;
}

#onePageRenderedOrForceFetch() {
async #onePageRenderedOrForceFetch() {
// Unless the viewer *and* its pages are visible, rendering won't start and
// `this._onePageRenderedCapability` thus won't be resolved.
// To ensure that automatic printing, on document load, still works even in
Expand All @@ -635,7 +635,7 @@ class PDFViewer {
!this.container.offsetParent ||
this._getVisiblePages().views.length === 0
) {
return Promise.resolve();
return;
}

// Handle the window/tab becoming inactive *after* rendering has started;
Expand All @@ -646,20 +646,17 @@ class PDFViewer {
return;
}
resolve();

document.removeEventListener(
"visibilitychange",
this.#onVisibilityChange
);
this.#onVisibilityChange = null;
};
document.addEventListener("visibilitychange", this.#onVisibilityChange);
});

return Promise.race([
await Promise.race([
this._onePageRenderedCapability.promise,
visibilityChangePromise,
]);
// Ensure that the "visibilitychange" listener is always removed.
document.removeEventListener("visibilitychange", this.#onVisibilityChange);
this.#onVisibilityChange = null;
}

async getAllText() {
Expand Down Expand Up @@ -821,14 +818,6 @@ class PDFViewer {

this.eventBus._off("pagerendered", this._onAfterDraw);
this._onAfterDraw = null;

if (this.#onVisibilityChange) {
document.removeEventListener(
"visibilitychange",
this.#onVisibilityChange
);
this.#onVisibilityChange = null;
}
};
this.eventBus._on("pagerendered", this._onAfterDraw);

Expand Down