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

service worker not working for localhost #915

Closed
sp1rs opened this issue Jun 16, 2016 · 7 comments
Closed

service worker not working for localhost #915

sp1rs opened this issue Jun 16, 2016 · 7 comments

Comments

@sp1rs
Copy link

sp1rs commented Jun 16, 2016

When i used http://localhost , and put sw.js file in root directory it works fine. But if i put sw.js file in http://localhost/app_name/ then it says net::ERR_INSECURE_RESPONSE in console and undefined:1 Uncaught (in promise) DOMException: Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html').

@wanderview
Copy link
Member

You have to serve your service worker script with a mimetype of text/javascript or similar. Things like python -mSimpleHTTPServer should do this automatically for files ending in .js.

@sp1rs
Copy link
Author

sp1rs commented Jun 16, 2016

@wanderview the file at root directory, its mime type is text/plain, and the file in app/ is also of same mime type text/plain.

@delapuente
Copy link

What's the scope for your service worker? You can not register a sw in /app_name with scope /. The max scope for a worker is the worker location.

@delapuente
Copy link

(Well, actually you can but you need to set Service-Worker-Allowed header).

@sp1rs
Copy link
Author

sp1rs commented Jun 16, 2016

@delapuente
This is the structure of the code:
-- main_app
--- app1
---app2
----static/js/main.js ( where i am registring my sw.js) ( register('/app2/sw.js',{ scope: '/app2/' })
--- sw.js
but if i put sw.js in main dir, then it works fine.

@mfalken
Copy link
Member

mfalken commented Jun 17, 2016

The error message says sw.js is served with the MIME type text/html. It must be served with text/javascript or similar. It looks like your server is changing the MIME type based on the path.

(Also this GitHub repository is not a good place for this issue, since it's not a spec issue.)

@sp1rs
Copy link
Author

sp1rs commented Jun 17, 2016

Closing the issue, the problem was my route was not correctly configured in django app. ** Thanks for the help **

@sp1rs sp1rs closed this as completed Jun 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants