16

라디오 스트림 크롬 확장을하려고하는데 문제가 있습니다. 나는 일반 JS 같은 브라우저에서 내 스크립트를 실행하면 + HTML + CSS 작동,하지만 난 크롬 확장 프로그램처럼들이받은하려고 할 때이 오류가 얻을 :크롬 확장 콘텐츠 보안 정책 지시문 오류

: 내 매니페스트이 추가 그 후

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

:

그러나 그 후 나는 (위의 코드와 매니페스트 라인 오류)


오류 메시지가 표시되었다이 내 매니페스트입니다

{ 
    "background": { 
     "scripts": [ "jquery.js", "jquery-ui.js", "plate.js" ] 
     }, 

    "browser_action": { 
     "default_icon": "Images/action-normal.png", 
     "default_popup": "player.html", 
     "default_title": "" 
    }, 
    "description": "Chrome Player", 
    "manifest_version": 2, 
    "name": "Radio Chrome Player", 
    "permissions": [ "http://www.radio-station.com/" ], 
    "version": "1.0" 

    "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'" 

} 

이 주 HTML 파일은 다음과 같습니다

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<script src="jquery.js"></script> 
<script src="jquery-ui.js"></script> 
<script src="main.js"></script> 
<script>$(function(){$("#radioplayere").plate({playlist: [{file:"http://RADIO_STATION_STREAM_URL/;"}], phpGetter: "http://hostingshoutcast.com/stream/plate/php/plate.php"});});</script> 
</head> 
<body> 
<div id="radioplayer">If you are seeing this then an error has occurred!</div> 
</body> 
</html> 

답변

17

귀하의 문제는 다음과 같습니다 :

  1. 크롬 CSP forbids inline code을, 이것은 무시 될 수 없습니다. 'unsafe-eval'은 문제를 해결하지 않으며 will be ignored님께 도움을 주신 'unsafe-inline'입니다.

    당신은 인라인 코드를 제거해야합니다

    <script>$(function(){$("#radioplayere").plate({playlist: [{file:"http://RADIO_STATION_STREAM_URL/;"}], phpGetter: "http://hostingshoutcast.com/stream/plate/php/plate.php"});});</script> 
    

    이것은 JS 파일을 이동해야합니다. 당신이 그 오류를 잡을 데 도움이되는 JSON validator를 사용하여, 일반적으로

    "version": "1.0", 
    

    : 당신의 manifest.json에 오타가있다

  2. , 당신은 쉼표를 잊어 버렸습니다.

+0

안녕, TNX 내 문제의 해결 반, 지금은 확장처럼 실행할 수 있지만,이 오류 받고 있어요 : 은 '스크립트'http://ws.audioscrobbler.com/2.0/를로드 거부? "script-src 'self'chrome-extension-resource :"을 (를) 위반했기 때문에 callback = jQuery17105420794193632901_13982 ... rtist = David + Craig + ft + Sting & track = Rise + and + Fall & format = json & _ = 1398287917991 '' 그 때문에 나는 노래 이름을 얻을 수 없다. – user3397388

+0

@ user3397388 콘텐츠 보안 정책에 대해 자세히 읽어보십시오. 어떻게 수정해야하는지 설명합니다. – Xan

1

는 내가 늦게까지 조금이야 알지만, Xan의 대답에 영업 이익의 의견에 따라이 문제를 해결하는 또 다른 요소는 암시 AJAX 호출을 조정하는 것입니다.

저도 같은 오류가 발생했다 나의 API 호출을 조정은 할 수 :

dataType: 'json' 

대신 :

dataType: 'jsonp' 

(해결 문제, 부여, 하나는 여전히 모든 인라인을 제거해야합니다 스크립팅.)

1

내게있어서, 그 이유는 내가 이전 버전 (예 : v1.7)의 jQuery에 CSP의 문제점이 있습니다. 새 버전 (v2.1.3).

관련 문제