Ensure that the viewer property, on BaseViewer-instances, is a valid div-element (issue 12320)

This should help prevent future issues, caused by the user omitting the `viewer` option and/or providing an incorrect `container` option, when initializing a `BaseViewer`-instance.
This commit is contained in:
Jonas Jenwald 2020-09-03 14:54:54 +02:00
parent 84da13b487
commit 89f6bb0fc6

View File

@ -143,6 +143,17 @@ class BaseViewer {
this.container = options.container;
this.viewer = options.viewer || options.container.firstElementChild;
if (
(typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
!(
this.container instanceof HTMLDivElement &&
this.viewer instanceof HTMLDivElement
)
) {
throw new Error("Invalid `container` and/or `viewer` option.");
}
this.eventBus = options.eventBus;
this.linkService = options.linkService || new SimpleLinkService();
this.downloadManager = options.downloadManager || null;