Running a script before URL is loaded?


I have a script that I would like to be require() on every page loaded into my app regardless of whether the file is local or not (i.e. if I load I want to be able to use that in the DOM) I know of the webContent.on(‘did-start-loading’). But this doesn’t seem to run early enough for scripts in the header area to use the functions in my script.

Basically, I have a function sRequire on a .js file. If I use the ‘did-start-loading’ even in my main.js file to executeJavaScript in the DOM, any <\script><\script> tags don’t seem to be able to use sRequire. However, when I run the app and use the console, sRequire does exist.

Is there any way I can load a script into the page without having to have it specifically required in the local html files?


If you use <webview> you can use the preload attribute.


Not exactly what I was looking for but it pointed me in the right direction. Using the browser window “preload” attribute I was able to accomplish what I was trying to do. Thanks!