Skip to content

Instantly share code, notes, and snippets.

@uxter
Created April 5, 2017 13:15
Show Gist options
  • Save uxter/50fb1c7011471442862bd921ec589a64 to your computer and use it in GitHub Desktop.
Save uxter/50fb1c7011471442862bd921ec589a64 to your computer and use it in GitHub Desktop.
How to inject custom JavaScript in web page? (simple google chrome plugin)
// Your code
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.src = chrome.extension.getURL('injected.js');
setTimeout(function() {
document.head.appendChild(script);
});
{
"manifest_version": 2,
"name": "Inject custom script",
"short_name": "InjectCustomScript",
"version": "1.0.0",
"content_scripts": [{
"matches": [
"*://*/*"
],
"js": [ "injector.js" ],
"run_at": "document_start",
"persistent": false
}],
"web_accessible_resources": [
"injected.js"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment