diff --git a/web/app.js b/web/app.js index 6040dc854f178e..a1807152b79686 100644 --- a/web/app.js +++ b/web/app.js @@ -1013,7 +1013,7 @@ const PDFViewerApplication = { .catch(downloadByUrl); // Error occurred, try downloading with the URL. }, - save({ sourceEventType = "download" } = {}) { + async save({ sourceEventType = "download" } = {}) { if (this._saveInProgress) { return; } @@ -1036,12 +1036,13 @@ const PDFViewerApplication = { this.download({ sourceEventType }); return; } - this._scriptingInstance?.scripting.dispatchEventInSandbox({ + this._saveInProgress = true; + + await this._scriptingInstance?.scripting.dispatchEventInSandbox({ id: "doc", name: "WillSave", }); - this._saveInProgress = true; this.pdfDocument .saveDocument(this.pdfDocument.annotationStorage) .then(data => { @@ -1051,8 +1052,8 @@ const PDFViewerApplication = { .catch(() => { this.download({ sourceEventType }); }) - .finally(() => { - this._scriptingInstance?.scripting.dispatchEventInSandbox({ + .finally(async () => { + await this._scriptingInstance?.scripting.dispatchEventInSandbox({ id: "doc", name: "DidSave", }); @@ -1614,7 +1615,7 @@ const PDFViewerApplication = { return; } - scripting.dispatchEventInSandbox({ + await scripting.dispatchEventInSandbox({ id: "doc", name: "Open", }); @@ -1967,6 +1968,8 @@ const PDFViewerApplication = { }, beforePrint() { + // Given that the "beforeprint" event is synchronous, we unfortunately + // cannot await the scripting event dispatching here. this._scriptingInstance?.scripting.dispatchEventInSandbox({ id: "doc", name: "WillPrint", @@ -2033,6 +2036,8 @@ const PDFViewerApplication = { }, afterPrint() { + // Given that the "afterprint" event is synchronous, we unfortunately + // cannot await the scripting event dispatching here. this._scriptingInstance?.scripting.dispatchEventInSandbox({ id: "doc", name: "DidPrint",