I can't save settings with storage sync.set

43 views
Skip to first unread message

Tiago Dantas

unread,
Nov 28, 2021, 1:52:39 AM11/28/21
to Chromium Extensions
When I click on save the error appears:

Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present.

options.html

https://paste.ofcode.org/MxpjjsrZjNY9wkzGzXB5Zs

saver.js

https://paste.ofcode.org/m4LiLZfpKbkRyCmmNvELHU

manifest.json

{
    "manifest_version": 3,
    "version": "1.1",
    "name": "censored",
    "description": "censored",
    "author": "Tiago Dantas",
    "permissions": [
        "activeTab",
        "scripting",
        "storage"
    ],
    "action": {
        "default_popup": "index.html",
        "default_icon": "icon.png"
    },
    "options_ui": {
      "page": "options.html",
      "open_in_tab": true
    },
    "icons": {
        "16": "icon.png",
        "32": "icon.png",
        "48": "icon.png",
        "128": "icon.png"
      },

      "content_scripts": [
        {
          "matches": ["censored*"],
          "run_at": "document_end",
          "all_frames": true,
          "js": ["alteracoes.js", "options.js", "saver.js"]
        }
      ],
      "background": {
        "service_worker": "background.js"
    }
}

Robbi

unread,
Nov 28, 2021, 12:30:47 PM11/28/21
to Chromium Extensions, tiagod...@gmail.com
Inline event handler ( onclick="save()" ) cannot be used; you have to create it inside the .js file in this way:
document.getElementById("save").addEventListener("click", save).
Make sure to put the above line inside a DOMContentLoaded event handler 'cause your button could be not ready when user click on it
Reply all
Reply to author
Forward
0 new messages