summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoofar <toofar@spalge.com>2023-11-27 08:16:34 +1300
committertoofar <toofar@spalge.com>2023-11-27 08:16:34 +1300
commita39dd64c5ebece50b0ae3574a5bb44885b99cefd (patch)
treec5108ab37075df1baae56e7fc41feb6fec8f0ff6
parent0144ae3576aaecde295d40e22d636f04240d6761 (diff)
downloadqutebrowser-a39dd64c5ebece50b0ae3574a5bb44885b99cefd.tar.gz
qutebrowser-a39dd64c5ebece50b0ae3574a5bb44885b99cefd.zip
Move pdf.js fetch() disabler earlier in the file.
We are setting window.Response to undefined to cause certain versions of pdf.js to detect that fetch() isn't available and to fall back to XHRs. In more recent versions of pdf.js the HTML string we were matching against has changed, it has a 'type="module"' attribute now, so we need to change the pattern we match against. I don't think it matters where we put this mocking though, so I've just put it after '<head>', which should hopefully be less fragile than matching against a '<script>' element. Note that this workaround isn't even relevant for the latest versions of pdf.js (4+). It doesn't seem to use a check on `window.Response` as part of fetch feature detection anymore (instead it uses fetch() for https? urls and XHR otherwise). But I figured it was better to have the workaround applying consistently, and not having an effect, vs having the workaround silently fail to apply. Don't have a strong opinion on it though. The other way to fix this would have been something like: attrs = "" if pdfjs_name.endswith(".mjs"): attrs = ' type="module"' pdfjs_script = f'<script src="../build/{html.escape(pdfjs_name)}"{attrs}></script>'
-rw-r--r--qutebrowser/browser/pdfjs.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/qutebrowser/browser/pdfjs.py b/qutebrowser/browser/pdfjs.py
index 427ef4537..1a13f5bda 100644
--- a/qutebrowser/browser/pdfjs.py
+++ b/qutebrowser/browser/pdfjs.py
@@ -63,11 +63,11 @@ def generate_pdfjs_page(filename, url):
viewhtml = viewhtml.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 = f'<script src="../build/{html.escape(pdfjs_name)}"></script>'
- viewhtml = viewhtml.replace(pdfjs_script,
- '<script>window.Response = undefined;</script>\n' +
- pdfjs_script)
+ # qute:// URLs, this is probably no longer needed in PDFjs 4+. See #4235
+ viewhtml = viewhtml.replace(
+ '<head>',
+ '<head>\n<script>window.Response = undefined;</script>\n'
+ )
return viewhtml