From 89f6bb0fc6b76009bff922ac5d5c3c4ddbc21ae2 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 3 Sep 2020 14:54:54 +0200 Subject: [PATCH] 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. --- web/base_viewer.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/base_viewer.js b/web/base_viewer.js index 1cd2e0830..4ed2ba4b0 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -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;