From aa08b02a5bf9844a3e34c22e348cbe6093069e42 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 29 Apr 2026 22:22:30 +0200 Subject: [PATCH] Avoid setting page-content for a previous document in the `PDFFindController.prototype.#extractText` method Given that all of the relevant API methods are asynchronous it's possible, although quite unlikely, that the existing "is the document active" check won't catch all situations where the document was closed in the middle of searching. --- web/pdf_find_controller.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 75163f685..481b0aa8d 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -909,6 +909,11 @@ class PDFFindController { try { const pdfPage = await pdfDoc.getPage(i + 1); const textContent = await pdfPage.getTextContent(textOptions); + + if (pdfDoc !== this._pdfDocument) { + resolve(); + return; + } const strBuf = []; for (const textItem of textContent.items) { @@ -921,6 +926,10 @@ class PDFFindController { [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join("")); } catch (ex) { + if (pdfDoc !== this._pdfDocument) { + resolve(); + return; + } console.error(`Unable to get text content for page ${i + 1}`, ex); // Page error -- assuming no text content. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] =