Estoy haciendo una extensión de Chrome que abrirá todos los enlaces en una página en pestañas nuevas.Content-Security-Policy error en google chrome extension making
Éstos son mis archivos de código:
manifest.json
{
"name": "A browser action which changes its icon when clicked.",
"version": "1.1",
"permissions": [
"tabs", "<all_urls>"
],
"browser_action": {
"default_title": "links", // optional; shown in tooltip
"default_popup": "popup.html" // optional
},
"content_scripts": [
{
"matches": [ "<all_urls>" ],
"js": ["background.js"]
}
],
"manifest_version": 2
}
popup.html
<!doctype html>
<html>
<head>
<title>My Awesome Popup!</title>
<script>
function getPageandSelectedTextIndex()
{
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {greeting: "hello"}, function (response)
{
console.log(response.farewell);
});
});
}
chrome.browserAction.onClicked.addListener(function(tab) {
getPageandSelectedTextIndex();
});
</script>
</head>
<body>
<button onclick="getPageandSelectedTextIndex()">
</button>
</body>
</html>
background.js
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
updateIcon();
});
function updateIcon() {
var allLinks = document.links;
for (var i=0; i<allLinks.length; i++) {
alllinks[i].style.backgroundColor='#ffff00';
}
}
Inicialmente quería resaltar todo los enlaces en t él los pagina o los marca de alguna manera; pero recibo el error "Se negó a ejecutar el script en línea debido a Content-Security-Policy".
Cuando presiono el botón dentro de la ventana emergente, aparece este error: Refused to execute inline event handler because of Content-Security-Policy
.
Por favor, ayúdame a corregir estos errores, así puedo abrir todos los enlaces en pestañas nuevas usando mi extensión de cromo.
Just beat me to it. La respuesta perfecta y es exactamente lo que necesitas hacer. – Alasdair
k gracias ... lo intentaré – Saad
Esto es tan estúpido. ¡¿Quién propuso esta idea?! Ahora tengo que cambiar todos mis onclicks en línea y ponerlos en un archivo js externo. Y tengo un montón de archivos que los incluyen. –