I would like to make a Chrome extension that provides a new object inside window
. When a web page is viewed in a browser with the extension loaded, I would like window.mything
to be available via Javascript. The window.mything
object will have some functions that I will define in the extension, and these functions should be callable from console.log
or any Javascript file when the page is viewed in a browser with the extension enabled.
I was able to successfully inject a Javascript file into the page by using a Content Script:
var s = document.createElement("script");
s.src = chrome.extension.getURL("mything.js");
document.getElementsByTagName("head")[0].appendChild(s);
mything.js looks like this:
window.mything = {thing: true};
console.log(window);
Whenever a page loads, I see the entire window
object as I expect it to be in the console. However, I can't interact with the window.mything
object from the console. It seems at if the injected script hasn't really modified the global window
object.
How can I modify the global window
object from a Chrome extension?
mything
must be existent. – Ass