DEV Community

Discussion on: Building a Simple Chrome Extension

Collapse
 
icaropnbr profile image
icaropnbr

Hi! Nice work you have done.

Can you help me?
I'm trying to make a Chrome extension just to remove non-numerical stuff from a prompt command input (from user).

My js file is

function ajustaCpf() {
var cpf = prompt("Cole aqui o CPF: ");
cpf.trim();
var cpfNormal = new RegExp(/\D/g);
var txt = cpf.replace(cpfNormal,'');

if(txt.length == 11) {
alert("CPF: " + txt);
} else {
alert("CPF inválido!");
}
}

And the manifest.json is:

{
"name": "PJe - CPF - CNPJ - N. Processo",
"version": "1.0",
"description": "Extensao do PJe",

"browser_action": {
  "default_popup": "popup.html",
  "default_icon": {
    "128": "images/id-card128.png"
  }
},
"content_scripts": [
    {
        "matches": ["http://*/*, http:s//*/*"],
        "js" : ["jquery-3.4.1.min.js", "magica.js"]
    }
],
"icons": {
  "128": "images/id-card128.png"
},
"manifest_version": 2
Enter fullscreen mode Exit fullscreen mode

}

I'm getting the error msg: "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."

I really don't get it.

=(

Collapse
 
michaeldscherr profile image
Michael Scherr

How are you calling the function ajustaCpf()?

If you are calling it inline from popup.html, then it's not allowed in a chrome plugin.

You would need to move the handler to your magica.js file.

Issue I am referring to: stackoverflow.com/questions/363243...

If that doesn't help try and post your code on github so I can take another look.

Collapse
 
icaropnbr profile image
icaropnbr

Thanks a lot!!

Yes, I was doing it inline:

<button onClick="ajustaCpf()" class="button" >CPF</button>

I'll try what you referred. Sooner or later we'll talk again.

;)

Thread Thread
 
icaropnbr profile image
icaropnbr

It worked!
Thanks a lot for your help!!

Keep the good work!

;)