1

The extension doesn't work because it says this:

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

I have tried to remove all inline js but it picks up the body tag as an inline script.

html:

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body onload="load()">
    <h1>
    BACKGROUND OPTIONS
    </h1>

        <input type = "text" id = "text" value = "" />
        <br>
    <button id="save"">
    SAVE
    </button>
    <br>
    <h1> 
    I MAGE:
    </h1>
    <img id="imgid">
</body>
</html>
    <script src="options.js"></script>
</body>
</html>

json:

{
  "manifest_version": 2,
  "name": "My Extension",
  "version": "3",
  "options_page": "options.html",
  "content_security_policy": "script-src 'self' 'unsafe-eval' ; object-src 'self'",
  "permissions": [
        "topSites",
        "chrome://favicon/",
        "unlimitedStorage",
        "topSites",
        "identity",
        "http://*/",
        "https://*/",
        "alarms",
        "tabs",
        "activeTab",
        "management",
        "storage",
        "webNavigation",
        "webRequest",
        "webRequestBlocking",
        "cookies",
        "contextMenus",
        "notifications",
        "background"
    ],
  "chrome_url_overrides" : {
    "newtab": "page.html"
  }
}

js:

document.getElementById("save").onclick = function(){
    var select = document.getElementById("text");
    var text = select.value;
    localStorage["text"] = text;
    var image = document.getElementById("imgid");
    image.src = text;          
}

function load() {
var load = document.getElementById("text");
load.value = localStorage["text"];
document.body.style.background = localStorage["text"];
var image = document.getElementById("imgid");
image.src = localStorage["text"];
}
Polyhex
  • 11
  • 1
  • 1) remove `onload="load()"`, 2) add `load();` at the start of js file, 3) see [this answer](/a/25721457) for more info. – wOxxOm Oct 25 '19 at 05:56

0 Answers0