Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
chrome extension using a content script to access the `window` object
"content_scripts": [
"matches": ["http://*/*", "https://*/*"],
"js": ["inject.js"],
"all_frames": true
"web_accessible_resources": [
* injectScript - Inject internal script to available access to the `window`
* @param {type} file_path Local path of the internal script.
* @param {type} tag The tag as string, where the script will be append (default: 'body').
* @see {@link}
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);
injectScript(chrome.extension.getURL('content.js'), 'body');

This comment has been minimized.

Copy link

@bennadel bennadel commented Dec 22, 2020

Thank you! This was exactly what I needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment