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

Remove the temporary "visibilitychange" listener, in PDFViewer, with AbortSignal.any() #18873

Merged
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
27 changes: 17 additions & 10 deletions web/pdf_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,22 +673,29 @@ class PDFViewer {

// Handle the window/tab becoming inactive *after* rendering has started;
// fixes (another part of) bug 1746213.
const hiddenCapability = Promise.withResolvers();
function onVisibilityChange() {
if (document.visibilityState === "hidden") {
hiddenCapability.resolve();
const hiddenCapability = Promise.withResolvers(),
ac = new AbortController();
document.addEventListener(
"visibilitychange",
() => {
if (document.visibilityState === "hidden") {
hiddenCapability.resolve();
}
},
{
signal:
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
typeof AbortSignal.any === "function"
? AbortSignal.any([signal, ac.signal])
: signal,
}
}
document.addEventListener("visibilitychange", onVisibilityChange, {
signal,
});
);

await Promise.race([
this._onePageRenderedCapability.promise,
hiddenCapability.promise,
]);
// Ensure that the "visibilitychange" listener is removed immediately.
document.removeEventListener("visibilitychange", onVisibilityChange);
ac.abort(); // Remove the "visibilitychange" listener immediately.
}

async getAllText() {
Expand Down