2948 explained code solutions for 75 technologies


chrome-extensionInject Javascript into webpage from content script


var script = document.createElement('script');
script.textContent = 'console.log("Hi");';
(document.head||document.documentElement).appendChild(script);ctrl + c
document.createElement

creates script DOM element

script.textContent

script content should be placed here

console.log("Hi");

code we want to inject into page

.appendChild(script)

this is where injection happens