我正试图在流开始时进行扩展,只是为了好玩。当我运行脚本并单击“测试”按钮以查看是否收到通知时,出现此错误:
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
我尝试将其粘贴到manifest.json上,但不起作用:
"content_security_policy": "script-src 'self' 'unsafe-eval' ; object-src 'self'",
我的代码:
Manifest.json:
{
"manifest_version": 2,
"name": "Extension Twitch Maghla",
"description": "Vous informe si il y a un live de Maghla",
"version": "1.0",
"content_security_policy": "script-src 'self' 'unsafe-eval' ; object-src 'self'",
"permissions": ["storage", "alarms", "notifications"],
"browser_action": {
"default_popup": "index.html"
},
"icons": {
"64" : "img/twitch.png"
},
"background": {
"scripts": ["background.js"]
}}
Background.js:
var check = 60000
var xhr = new XMLHttpRequest();
function IsStreaming() {
xhr.open("GET", "https://api.twitch.tv/kraken/streams/maghla?
client_id=08922ax6vgljagb8hewjbb8bchbidf", true);
xhr.onreadystatechange = function ()
{
if(xhr.readyState == 4)
{
var data = JSON.parse(xhr.responseText);
if(data["stream"] === null)
{
chrome.browserAction.setIcon({path:"img/twitch_gray.png"});
}
else
{
chrome.browserAction.setIcon({path:"img/twitch.png"});
notify()
}
}
}
}
IsStreaming()
function notify()
{
chrome.notifications.create('Live', {
type: 'basic',
iconUrl: 'img/twitch.png',
title: 'Maghla est en live !!',
message: 'Allez viens ! On va s\'amuser'
},
function(notificationId) {});
}
app.js:
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.twitch.tv/kraken/streams/maghla?
client_id=tvqezg7jf7epr4x54zzbioif8ddvv0", true);
xhr.onreadystatechange = function(channel)
{
if(xhr.readyState == 4)
{
var data = JSON.parse(xhr.responseText);
var elm = document.getElementById("info");
if(data["stream"] == null)
{
elm.style.color = "red";
elm.innerHTML = "PlatiScript n'est pas en live actuellement :(";
}
else
{
elm.style.color = "green";
elm.innerHTML = "Viens voir PlatiScript en live maintenant !";
notify()
}
}
}
function notify()
{
chrome.notifications.create('Live', {
type: 'basic',
iconUrl: 'img/twitch.png',
title: 'Maghla est en live !!',
message: 'Allez viens ! On va s\'amuser'
},
function(notificationId) {});
}
Index.html:
<h1>Twitch Extensions</h1>
<p id="info">Le live est actif</p>
<button onclick="notify()">click</button>
<script src="app.js"></script>
感谢您的帮助:D