In an extension for google chrome, I specified a script that will run on the site I need.
This script should attach another script file to the page using the following option in the manifest
"web_accessible_resources": ["somescript.js"]
in the script this is the class. As a result, the script is connected like this
var functions = document.createElement('script'); functions.onload = function(){ let someObject = new SomeClass(document); someObject.doAnything(); }; functions.src = chrome.extension.getURL('somescript.js'); functions.type = 'text\/javascript'; document.head.appendChild(functions); But it does not work. When functions.onload triggered, nothing happens and the console displays
Uncaught ReferenceError: SomeClass is not defined at HTMLScriptElement.functions.onload
That is, at the moment when functions.onload is executed, the context still does not know anything about SomeClass . And after that I can write in the console
let someObject = new SomeClass(document); someObject.doAnything(); and everything works out fine. Maybe I need not an onload event, but some other one?