Merge pull request #18873 from Snuffleupagus/visibilitychange-AbortSignal-any

Remove the temporary "visibilitychange" listener, in `PDFViewer`, with `AbortSignal.any()`
This commit is contained in:
Tim van der Meij 2024-10-08 20:41:43 +02:00 committed by GitHub
commit 233ac1773d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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() {