From d8133c905a3fe67331f3eef5ce2b4d543d4d25ec Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 31 Aug 2026 03:32:31 +0200 Subject: [PATCH] fix: serve module scripts and wasm assets with the correct MIME type (#29139) On Windows hosts the built-in code interpreter fails immediately with "Failed to fetch dynamically imported module: .../pyodide/pyodide.asm.mjs", and the browser console shows the server answered with a MIME type of "text/plain". Code execution is unusable for those users. Python's mimetypes module reads the Windows registry after loading its own table, so a stray registry entry silently replaces the correct type for an extension and Starlette then labels the file with it. Browsers enforce strict MIME checking for module scripts and streaming WASM compilation, so the pyodide loader gets refused. The same workaround already existed for .js; this extends it to the two other extensions pyodide ships, and moves it out of the frontend-build branch so the unconditionally mounted /static assets are covered as well. Fixes #29133 --- backend/open_webui/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index c84a394b87..67a14f16b2 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -2980,6 +2980,11 @@ async def check_db_health(): # --- static assets & files --- +# Windows registry entries can override these with text/plain, which breaks module and wasm loading +mimetypes.add_type('text/javascript', '.js') +mimetypes.add_type('text/javascript', '.mjs') +mimetypes.add_type('application/wasm', '.wasm') + # Serve build-time static assets (CSS, JS, images, favicon, etc.) app.mount('/static', StaticFiles(directory=STATIC_DIR), name='static') @@ -3025,7 +3030,6 @@ def swagger_ui_html(*args, **kwargs): applications.get_swagger_ui_html = swagger_ui_html if os.path.exists(FRONTEND_BUILD_DIR): - mimetypes.add_type('text/javascript', '.js') pyodide_dir = FRONTEND_BUILD_DIR / 'pyodide' if os.path.exists(pyodide_dir): app.mount('/pyodide', CORSStaticFiles(directory=pyodide_dir), name='pyodide')