From 3f31a0005a905a9634084367a121fa57589e6778 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 5 Jun 2025 13:41:28 +0200 Subject: [PATCH] Fix mimetype for PDF.js files on Windows With windows-2022 and windows-2025 on GitHub Actions, we get: qutescheme:data_for_url:128 url: qute://pdfjs/web/viewer.mjs, path: /web/viewer.mjs, host pdfjs webenginequtescheme:requestStarted:105 Returning text/plain data which causes: JS: [qute://pdfjs/build/pdf.mjs:0] Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec. It's unclear why we get text/plain back there in the first place (can't reproduce on a local Windows 11 install), but it's definitely wrong, so let's just override that problematic case. --- qutebrowser/utils/utils.py | 5 +++++ tests/unit/utils/test_utils.py | 1 + 2 files changed, 6 insertions(+) diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index 9c506471d..08acfa727 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -722,6 +722,11 @@ def guess_mimetype(filename: str, fallback: bool = False) -> str: fallback: Fall back to application/octet-stream if unknown. """ mimetype, _encoding = mimetypes.guess_type(filename) + if os.path.splitext(filename)[1] == '.mjs' and mimetype == "text/plain": + # For unknown reasons, Windows (at least on GitHub Actions) wrongly + # gives us text/plain here. + return "text/javascript" + if mimetype is None: if fallback: return 'application/octet-stream' diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index fc4a3e652..12dd070de 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -858,6 +858,7 @@ def test_chunk_invalid(n): @pytest.mark.parametrize('filename, expected', [ ('test.jpg', 'image/jpeg'), ('test.blabla', 'application/octet-stream'), + ('test.mjs', 'text/javascript'), ]) def test_guess_mimetype(filename, expected): assert utils.guess_mimetype(filename, fallback=True) == expected