Remove the temporary "visibilitychange" listener, in PDFViewer, with AbortSignal.any()
This is similar to a lot of other code, where we've been replacing explicit `removeEventListener`-calls. Given the somewhat limited availability of `AbortSignal.any()`, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static#browser_compatibility), this event listener will no longer be immediately removed in older browsers (however that should be fine).
This commit is contained in:
parent
81cf42df47
commit
31b0a496fd
@ -673,22 +673,29 @@ class PDFViewer {
|
|||||||
|
|
||||||
// Handle the window/tab becoming inactive *after* rendering has started;
|
// Handle the window/tab becoming inactive *after* rendering has started;
|
||||||
// fixes (another part of) bug 1746213.
|
// fixes (another part of) bug 1746213.
|
||||||
const hiddenCapability = Promise.withResolvers();
|
const hiddenCapability = Promise.withResolvers(),
|
||||||
function onVisibilityChange() {
|
ac = new AbortController();
|
||||||
|
document.addEventListener(
|
||||||
|
"visibilitychange",
|
||||||
|
() => {
|
||||||
if (document.visibilityState === "hidden") {
|
if (document.visibilityState === "hidden") {
|
||||||
hiddenCapability.resolve();
|
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([
|
await Promise.race([
|
||||||
this._onePageRenderedCapability.promise,
|
this._onePageRenderedCapability.promise,
|
||||||
hiddenCapability.promise,
|
hiddenCapability.promise,
|
||||||
]);
|
]);
|
||||||
// Ensure that the "visibilitychange" listener is removed immediately.
|
ac.abort(); // Remove the "visibilitychange" listener immediately.
|
||||||
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllText() {
|
async getAllText() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user