mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
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
1 changed files with 17 additions and 10 deletions
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue