From 12e083f60d27816442b8da453c7d7f1f1abbc6bb Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 21 Jul 2024 21:55:37 +0200 Subject: [PATCH] Re-factor how the "docBaseUrl" API-option is set in the viewer This option is old enough that it predates e.g. the introduction of AppOptions, so it probably cannot hurt to re-factor this a little bit now. - In development-mode we can just set this directly in AppOptions. - In the extension-builds we still need to set it dynamically, however by moving this code we get the benefit of being able to avoid storing a data-URL in that case; note how [the API ignores those anyway](https://github.com/mozilla/pdf.js/blob/98e772727e70dcad6433b5f02e027d6724b912f4/src/display/api.js#L256-L262). --- web/app.js | 13 ++++++------- web/app_options.js | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/web/app.js b/web/app.js index 02436ff4a..8078c8be8 100644 --- a/web/app.js +++ b/web/app.js @@ -854,7 +854,13 @@ const PDFViewerApplication = { } if (isDataScheme(url)) { this._hideViewBookmark(); + } else if ( + typeof PDFJSDev !== "undefined" && + PDFJSDev.test("MOZCENTRAL || CHROME") + ) { + AppOptions.set("docBaseUrl", this.baseUrl); } + let title = getPdfFilenameFromUrl(url, ""); if (!title) { try { @@ -996,13 +1002,6 @@ const PDFViewerApplication = { /* downloadUrl = */ args.url ); } - // Always set `docBaseUrl` in development mode, and in the (various) - // extension builds. - if (typeof PDFJSDev === "undefined") { - AppOptions.set("docBaseUrl", document.URL.split("#", 1)[0]); - } else if (PDFJSDev.test("MOZCENTRAL || CHROME")) { - AppOptions.set("docBaseUrl", this.baseUrl); - } // Set the necessary API parameters, using all the available options. const apiParams = AppOptions.getAll(OptionKind.API); diff --git a/web/app_options.js b/web/app_options.js index 001fa72dd..66b36361e 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -345,7 +345,7 @@ const defaultOptions = { }, docBaseUrl: { /** @type {string} */ - value: "", + value: typeof PDFJSDev === "undefined" ? document.URL.split("#", 1)[0] : "", kind: OptionKind.API, }, enableHWA: {