I’m making a Chrome extension with an options page (declared in my manifest).
I have an object defined like this in a separate file :
function MyObject() {
…
}
I “export” it using:
window.MyExtension = {};
window.MyExtension.MyObject = MyObject;
and then I can construct others objects in my extension main file using:
new MyExtension.MyObject();
It works fine.
But I would like to use this object in my options page. I saw that the script was not loaded so I tried to create a script tag and appending it to the body. The script is executed since I could saw a console.log() output, but I can not construct an object using “new MyObject” in my options page.
I suspect this is because of sandboxing or some stuff like that, the window object in the script defining MyObject should not be the same as in my options page.
But how could I get a reference to MyObject ? However, I can copy-paste the code I need and it will work, but what about DRY… and I can not believe that there is no good way to do it.
Hope I explained it well. Thanks,
cGuille.
Don’t include it using
chrome.extension.getURL(), since your option page is in your extension. Do it like this:This should works. 😉