summaryrefslogtreecommitdiff
path: root/qutebrowser/browser/pdfjs.py
diff options
context:
space:
mode:
Diffstat (limited to 'qutebrowser/browser/pdfjs.py')
-rw-r--r--qutebrowser/browser/pdfjs.py47
1 files changed, 24 insertions, 23 deletions
diff --git a/qutebrowser/browser/pdfjs.py b/qutebrowser/browser/pdfjs.py
index fdece9a9e..841285deb 100644
--- a/qutebrowser/browser/pdfjs.py
+++ b/qutebrowser/browser/pdfjs.py
@@ -1,20 +1,7 @@
-# Copyright 2016-2021 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
-# Copyright 2015 Daniel Schadt
+# SPDX-FileCopyrightText: Daniel Schadt
+# SPDX-FileCopyrightText: Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
-# This file is part of qutebrowser.
-#
-# qutebrowser is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# qutebrowser is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with qutebrowser. If not, see <https://www.gnu.org/licenses/>.
+# SPDX-License-Identifier: GPL-3.0-or-later
"""pdf.js integration for qutebrowser."""
@@ -74,11 +61,11 @@ def generate_pdfjs_page(filename, url):
html = html.replace('</body>',
'</body><script>{}</script>'.format(script))
# WORKAROUND for the fact that PDF.js tries to use the Fetch API even with
- # qute:// URLs.
- pdfjs_script = '<script src="../build/pdf.js"></script>'
- html = html.replace(pdfjs_script,
- '<script>window.Response = undefined;</script>\n' +
- pdfjs_script)
+ # qute:// URLs, this is probably no longer needed in PDFjs 4+. See #4235
+ html = html.replace(
+ '<head>',
+ '<head>\n<script>window.Response = undefined;</script>\n'
+ )
return html
@@ -215,10 +202,24 @@ def _read_from_system(system_path, names):
return (None, None)
+def get_pdfjs_js_path():
+ """Checks for pdf.js main module availability and returns the path if available."""
+ paths = ['build/pdf.js', 'build/pdf.mjs']
+ for path in paths:
+ try:
+ get_pdfjs_res(path)
+ except PDFJSNotFound:
+ pass
+ else:
+ return path
+
+ raise PDFJSNotFound(" or ".join(paths))
+
+
def is_available():
- """Return true if a pdfjs installation is available."""
+ """Return true if certain parts of a pdfjs installation are available."""
try:
- get_pdfjs_res('build/pdf.js')
+ get_pdfjs_js_path()
get_pdfjs_res('web/viewer.html')
except PDFJSNotFound:
return False