diff --git a/web/pdf_scripting_manager.js b/web/pdf_scripting_manager.js index 9da66880d..b8f2ed9f9 100644 --- a/web/pdf_scripting_manager.js +++ b/web/pdf_scripting_manager.js @@ -45,6 +45,8 @@ class PDFScriptingManager { #externalServices = null; + #objectIds = null; + #pdfDocument = null; #pdfViewer = null; @@ -104,6 +106,18 @@ class PDFScriptingManager { if (pdfDocument !== this.#pdfDocument) { return; // The document was closed while the data resolved. } + + // Collect the ids of every field annotation, so that any sandbox message + // targeting an unknown id can be ignored. + if (objects) { + this.#objectIds = new Set(); + for (const fields of Object.values(objects)) { + for (const { id } of fields) { + this.#objectIds.add(id); + } + } + } + try { this.#scripting = this.#initScripting(); } catch (error) { @@ -368,6 +382,9 @@ class PDFScriptingManager { const ids = siblings ? [id, ...siblings] : [id]; for (const elementId of ids) { + if (!this.#objectIds?.has(elementId)) { + continue; + } const element = document.querySelector( `[data-element-id="${elementId}"]` ); @@ -456,6 +473,8 @@ class PDFScriptingManager { } async #destroyScripting() { + this.#objectIds = null; + if (!this.#scripting) { this.#pdfDocument = null;