use*_*388 20 html javascript google-chrome google-chrome-extension content-security-policy
我正在尝试制作无线电流镀铬扩展,但存在问题.当我在浏览器中运行我的脚本时,就像普通的JS + HTML + CSS一样,但是当我尝试像Chrome扩展程序一样运行它时,我收到此错误:
拒绝执行内联脚本,因为它违反了以下内容安全策略指令:"script-src'self'chrome-extension-resource:".要么是'unsafe-inline'关键字,哈希('sha256 -...'),要么是nonce('nonce -...')来启用内联执行.
之后我将其添加到我的清单中:
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
Run Code Online (Sandbox Code Playgroud)
但之后我收到错误消息(清单行中的错误与上面的代码)
这是我的表现:
{
"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'"
}
Run Code Online (Sandbox Code Playgroud)
这是主要的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>
Run Code Online (Sandbox Code Playgroud)
Xan*_*Xan 19
你的问题如下:
Chrome CSP 禁止使用内联代码,但这不能覆盖.你'unsafe-eval'不解决这个问题,并且'unsafe-inline'将已经帮助将被忽略由Chrome.
你需要摆脱内联代码:
<script>$(function(){$("#radioplayere").plate({playlist: [{file:"http://RADIO_STATION_STREAM_URL/;"}], phpGetter: "http://hostingshoutcast.com/stream/plate/php/plate.php"});});</script>
Run Code Online (Sandbox Code Playgroud)
这需要在js文件中移动.
你的manifest.json中有一个拼写错误,你忘记了一个逗号:
"version": "1.0",
Run Code Online (Sandbox Code Playgroud)
通常,使用JSON验证程序可以帮助您捕获这些错误.
| 归档时间: |
|
| 查看次数: |
36622 次 |
| 最近记录: |