2017-11-20 6 views
0
The script has an unsupported MIME type ('text/plain'). 
Failed to load resource: net::ERR_INSECURE_RESPONSE 
ServiceWorker registration failed: DOMException: Failed to register a 
ServiceWorker: The script has an unsupported MIME type ('text/plain'). 

오류 로그.ServiceWorker : 스크립트에 지원되지 않는 MIME 유형 (크롬 확장)이 있습니다.

if ('serviceWorker' in navigator) { 
window.addEventListener('load', function() { 
    navigator.serviceWorker.register("/scripts/sw.js").then(function(registration) { 
     // Registration was successful 
     console.log('ServiceWorker registration successful with scope: ', registration.scope); 
    }).catch(function(err) { 
     // registration failed :(
     console.log('ServiceWorker registration failed: ', err); 
    }); 
}); 

크롬 확장에 서비스 작업자를 사용하려고 시도했지만이 오류가 발생했습니다. 솔루션을 찾을 수 없어서 물었습니다. 고맙습니다.

+0

합니다 ([공식 데모 확장]을 참조 https://chromium.googlesource.com/chromium/src/+/6ddb7d6a7dcfa4364aa4c4c6afb82fdb16b00645/chrome/ 테스트/데이터/확장/api_test/service_worker/배경 /). 또한 아마도 귀하의 OS에서 js MIME 유형이 깨졌습니다. https://crbug.com/762483 – wOxxOm

+0

답변 해 주셔서 감사합니다. 이 문제는 해결되었지만 다른 Windows 사용자는 배포 할 수 없습니다. – jgb

답변

0

나는 동일한 문제가있었습니다. 서버 설정에서 mime/content 유형을 지정해야합니다. 예 : nginx

types { 
    text/html        html htm shtml; 
    text/css        css; 
    text/xml        xml rss; 
    image/gif        gif; 
    image/jpeg        jpeg jpg; 
    application/x-javascript    js; 
    application/atom+xml     atom;} 

가 /etc/nginx/mime.types 간다