From 8630822a6366aedc4a1f380d384eca308e9958d8 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 23 Apr 2025 15:59:50 +0200 Subject: [PATCH] Fix errors when running the integration tests JavaScript error: http://127.0.0.1:42301/build/generic/web/viewer.mjs, line 5822: TypeError: this[#state] is null JavaScript error: http://127.0.0.1:42301/build/generic/web/viewer.mjs, line 6001: TypeError: can't access property "getPage", this._pdfDocument is null --- web/pdf_find_controller.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 6e87c3149..7a34117e9 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -771,6 +771,9 @@ class PDFFindController { } #calculateMatch(pageIndex) { + if (!this.#state) { + return; + } const query = this.#query; if (query.length === 0) { return; // Do nothing: the matches should be wiped out already. @@ -882,12 +885,17 @@ class PDFFindController { let deferred = Promise.resolve(); const textOptions = { disableNormalization: true }; + const pdfDoc = this._pdfDocument; for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) { const { promise, resolve } = Promise.withResolvers(); this._extractTextPromises[i] = promise; - deferred = deferred.then(() => - this._pdfDocument + deferred = deferred.then(async () => { + if (pdfDoc !== this._pdfDocument) { + resolve(); + return; + } + await pdfDoc .getPage(i + 1) .then(pdfPage => pdfPage.getTextContent(textOptions)) .then( @@ -920,8 +928,8 @@ class PDFFindController { this._hasDiacritics[i] = false; resolve(); } - ) - ); + ); + }); } }