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.
This commit is contained in:
Jonas Jenwald 2026-04-29 22:22:30 +02:00
parent a6e2a42df1
commit aa08b02a5b

View File

@ -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]] =