Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script loading failure from djdt 3.0 #1336

Closed
tari opened this issue Sep 24, 2020 · 13 comments
Closed

Script loading failure from djdt 3.0 #1336

tari opened this issue Sep 24, 2020 · 13 comments

Comments

@tari
Copy link

tari commented Sep 24, 2020

Using Django 3.1, I've fount that django-debug-toolbar>=3.0 fails to load scripts and the toolbar doesn't show up at all when running a local development server (manage.py runserver).

Firefox (81.0) has this error message in the console, and Chrome 87 seems to have the same issue:

Loading module from “http://localhost:8000/static/debug_toolbar/js/toolbar.js” was blocked because of a disallowed MIME type (“text/plain”).

I can work around it by setting the MIME type for .js files manually, but it seems like this should either be documented or automatically worked around.

@matthiask
Copy link
Member

Hi @tari

Thanks for the report. This sounds like an issue with Django or even with your development environment, and is probably not specific to django-debug-toolbar? I just checked and the runserver in my current project delivers JS with the correct application/javascript content type...

@tari
Copy link
Author

tari commented Sep 24, 2020

Seems like it's Windows-specific, since I can't reproduce this on Linux (Python 3.8 for both).

I guess it's related to where mimetypes gets its data from by default, but if Django doesn't (currently?) do the right thing it seems worth at least pointing in the right direction.

@tari
Copy link
Author

tari commented Sep 24, 2020

So Python loads MIME types from the registry (HKEY_CLASSES_ROOT) on Windows, and .js is defined as text/plain there. Based on the programs registered to open js files, this may have been set up by VS Code or Visual Studio.

It looks like there's no MIME type configured in Windows by default, since there isn't a Content Type key for .js when I load up a Windows sandbox.


I'm not sure what (if anything) could be done about this, since it's a deep platform issue. I also found an old Go bug around the same problem. I can fix it on this machine by setting HKEY_CLASSES_ROOT\.js\Content Type to text/javascript.

@matthiask
Copy link
Member

I think that the Django maintainers may be sympathetic towards adding some code to work around limitations when developing on Windows. I think you should open a ticket at https://code.djangoproject.com/ticket/ (I checked and didn't find an existing ticket) and propose a code change in Django itself.

My current thinking is that we shouldn't add code to django-debug-toolbar to fix this. It should be fixed, but not in django-debug-toolbar.

@tari
Copy link
Author

tari commented Sep 24, 2020

Sounds reasonable. I've filed Django ticket #32041 about this so I'll close this issue and reopen if I think it warrants further discussion here later.

@tari tari closed this as completed Sep 24, 2020
@matthiask
Copy link
Member

I've seen that the Django ticket has been closed as well.

I understand the argument raised by Mariusz, it's the same argument for not fixing it in django-debug-toolbar after all.

JavaScript not working by default on Windows when served by the Django development server is really unfriendly to beginners though, so – if you want to – you could raise the issue on the django-developers mailing list or in the forum if you prefer that, arguing that runserver should serve correct mimetypes by default on Windows too. At the very least it would be worth it adding a note to the documentation on installing Django on Windows (https://docs.djangoproject.com/en/3.1/howto/windows/).

(By the way, I'm working on Windows right now too, but inside WSL/2, so I'm sympathetic but not affected directly.)

@tari
Copy link
Author

tari commented Sep 25, 2020

That's rather frustrating. I've solicited opinions on working around the problem (it's Windows at fault here!) on the mailing list. Seems like it may have been held for moderation since I don't see it on the web yet.

I appreciate the moral support. 😃

@matthiask
Copy link
Member

Yes that may happen. Hopefully moderators will clear your message soon :)

@matthiask
Copy link
Member

The documentation patch has landed in Django, yay :) django/django@f87b0ec

@AlekseiKhatkevich
Copy link

Using Django 3.1, I've fount that django-debug-toolbar>=3.0 fails to load scripts and the toolbar doesn't show up at all when running a local development server (manage.py runserver).

Firefox (81.0) has this error message in the console, and Chrome 87 seems to have the same issue:

Loading module from “http://localhost:8000/static/debug_toolbar/js/toolbar.js” was blocked because of a disallowed MIME type (“text/plain”).

I can work around it by setting the MIME type for .js files manually, but it seems like this should either be documented or automatically worked around.

Using Django 3.1, I've fount that django-debug-toolbar>=3.0 fails to load scripts and the toolbar doesn't show up at all when running a local development server (manage.py runserver).

Firefox (81.0) has this error message in the console, and Chrome 87 seems to have the same issue:

Loading module from “http://localhost:8000/static/debug_toolbar/js/toolbar.js” was blocked because of a disallowed MIME type (“text/plain”).

I can work around it by setting the MIME type for .js files manually, but it seems like this should either be documented or automatically worked around.

Hi.Sorry for asking. How exactly you fixed this with that stackowerflowanswer. Could you please provide a code snippet?

@tari
Copy link
Author

tari commented Oct 8, 2020

I edited the registry as described in my own answer: set HKEY_CLASSES_ROOT\.js\Content Type to text/javascript.

@ghost
Copy link

ghost commented Nov 7, 2020

I edited the registry as described in my own answer: set HKEY_CLASSES_ROOT\.js\Content Type to text/javascript.

Thanks, works for me

@name-andy46
Copy link

name-andy46 commented Nov 26, 2020

I edited the registry as described in my own answer: set HKEY_CLASSES_ROOT\.js\Content Type to text/javascript.

Hi, apologies for not complying with the Q&A guidelines here.
I'm just starting to learn Django and I really would like to see which queries are being executed through the toolbar.
I've already asked the question here.

Also edited the registry key as in the image below, but still cannot get the toolbar to show up.

MimeType2

Any possibility of solving this?

Edit: Ignore the content type in the meta tag in the image background. Was trying somthing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants