Estoy creando una extensión de Chrome y quiero inyectar un archivo Javascript en DOM desde el archivo content.js, pero después de inyectar el archivo JS, Cross-Origin Read Blocking (CORB) blocked cross-origin response https://raw.githubusercontent.com/avinashiitb/bookmark-preview/main/injectScript.js
La idea detrás de inyectar injectScript.js
es escribir un evento personalizado en DOM y pasar ese evento al script content.js
Manifiesto.Json
{ "manifest_version": 2, "name": "Preview & Bookmark", "author": "Aviansh", "version": "0.001", "content_scripts": [ { "matches": ["*://*/*"], "js": [ "content.js" ], "css": [ "style.css" ] } ], "background": { "scripts": [ "background.js" ] }, "web_accessible_resources": [ "inject-script.js" ], "browser_action": {}, "permissions": [ "storage", "*://*/*" ] }
Contenido.js
function injectScript(file_path, tag) { var node = document.getElementsByTagName(tag)[0]; var script = document.createElement('script'); script.setAttribute('type', 'text/javascript'); script.setAttribute('src', file_path); node.appendChild(script); } injectScript("https://raw.githubusercontent.com/avinashiitb/bookmark-preview/main/injectScript.js", 'body');
inyectarScript.js
alert("Hi");
inject-script.js
var s = document.createElement('script'); s.src = chrome.runtime.getURL('inject-script.js'); s.onload = function() { this.remove(); }; (document.head || document.documentElement).appendChild(s);