Fix the initialization/resetting of scripting-related events in the BaseViewer

The "pageopen"/"pageclose"-events are only necessary if, and only if, there's actually a sandbox to dispatch the events in. Hence we shouldn't dispatch those events unconditionally, as soon as `enableScripting` is set, but rather initialize that functionality only when needed.

Furthermore, in `web/app.js`, there's currently a bug since we're attempting to *manually* simulate a "pageopen"-event for a page that may not actually have been rendered at the time. With the modified `BaseViewer.initializeScriptingEvents` method, we'll now dispatch a correct "pageopen"-event here.
This commit is contained in:
Jonas Jenwald 2021-01-12 13:38:49 +01:00
parent 1de1ae0be6
commit a882a85446
2 changed files with 47 additions and 25 deletions

View file

@ -1588,7 +1588,7 @@ const PDFViewerApplication = {
}
}
this._scriptingInstance?.scripting.dispatchEventInSandbox({
await this._scriptingInstance?.scripting.dispatchEventInSandbox({
id: "page",
name: "PageOpen",
pageNumber,
@ -1612,7 +1612,7 @@ const PDFViewerApplication = {
return; // The document was closed while the actions resolved.
}
this._scriptingInstance?.scripting.dispatchEventInSandbox({
await this._scriptingInstance?.scripting.dispatchEventInSandbox({
id: "page",
name: "PageClose",
pageNumber,
@ -1678,8 +1678,7 @@ const PDFViewerApplication = {
id: "doc",
name: "Open",
});
await pageOpen({ pageNumber: this.pdfViewer.currentPageNumber });
await this.pdfViewer.initializeScriptingEvents();
// Used together with the integration-tests, see the `scriptingReady`
// getter, to enable awaiting full initialization of the scripting/sandbox.