0

I'm trying to make an extension when a stream started, just for the fun. When I run my script and I ckick on an "test" button to see if I have a notification, I have this error :

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.

I tried to past this on my manifest.json but not working :

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

My Code :

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>

Thx for your help :D

Arthur
  • 1
  • Simply add the onclick listener in your app.js, don't use `onclick="notify()"` in HTML. – wOxxOm Apr 09 '19 at 13:41
  • 1
    Possible duplicate of [onClick within Chrome Extension not working](https://stackoverflow.com/questions/13591983/onclick-within-chrome-extension-not-working) – wOxxOm Apr 09 '19 at 13:42

0 Answers0