Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the same version of PDF.js is used in both the API and the Viewer (PR 8959 follow-up) #12540

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions web/base_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

import { createPromiseCapability, version } from "pdfjs-lib";
import {
CSS_UNITS,
DEFAULT_SCALE,
Expand All @@ -38,7 +39,6 @@ import {
} from "./ui_utils.js";
import { PDFRenderingQueue, RenderingStates } from "./pdf_rendering_queue.js";
import { AnnotationLayerBuilder } from "./annotation_layer_builder.js";
import { createPromiseCapability } from "pdfjs-lib";
import { PDFPageView } from "./pdf_page_view.js";
import { SimpleLinkService } from "./pdf_link_service.js";
import { TextLayerBuilder } from "./text_layer_builder.js";
Expand Down Expand Up @@ -139,6 +139,13 @@ class BaseViewer {
if (this.constructor === BaseViewer) {
throw new Error("Cannot initialize BaseViewer.");
}
const viewerVersion =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : null;
if (version !== viewerVersion) {
throw new Error(
`The API version "${version}" does not match the Viewer version "${viewerVersion}".`
);
}
this._name = this.constructor.name;

this.container = options.container;
Expand All @@ -150,10 +157,8 @@ class BaseViewer {
) {
if (
!(
this.container &&
this.container.tagName.toUpperCase() === "DIV" &&
this.viewer &&
this.viewer.tagName.toUpperCase() === "DIV"
this.container?.tagName.toUpperCase() === "DIV" &&
this.viewer?.tagName.toUpperCase() === "DIV"
)
) {
throw new Error("Invalid `container` and/or `viewer` option.");
Expand Down