E
E
Enerdgazer2017-04-18 15:53:55
JavaScript
Enerdgazer, 2017-04-18 15:53:55

How to fix security policy error in google extension?

The problem is this: I am writing an extension that, when the button is clicked, adds the text entered by the user.
and in a regular html document, if you run it, everything works as it should, but when loaded as an extension, it stops working. Chrome throws popul.html:9 Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
manifest.json code

{
    "manifest_version": 2,

    "name": "organizer",
    "version": "1.0",

  

   "browser_action": {
        "default_title": "Organizer",
        "default_icon": "log.png",
        "default_popup": "popul.html"
    }
 }

popup.html code
<html>
<head>
<script type="text/javascript" src="dobavka.js"> </script>
</head>
<body>
<td><input type="text" id="sd" onfocus="this.value = ''" value="Ввести задачу " class="input_task" /></td>
<button onclick="addLi()">+</button>
<ol id="spisokst";">		
  </ol>
</body>
</html>

dobavka.js
function addLi() {
  var stroka = document.getElementById('sd').value;//дл¤ ввода названи¤ новой строки
  if (stroka){
    var ol = document.getElementById ("spisokst");//находим наш список
    var li = document.createElement("LI");//создаем новый элемент списка
      ol.appendChild(li);//присваиваем нашему спску новый элемент
    var text = document.createTextNode(stroka);//создаем новый узел текст
      li.appendChild(text);//присваиваем этот текст нашему новому пункту списка
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2017-04-18
@artemky

Try to put all the javascript code in the dobavka.js file, that is, in your case, handle the events in the js file (remove onclick="addLi()" and onfocus="this.value = ''")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question