Insert JS into mainWindow via webContents


Is there a way to do something similar to insertCSS via webContents but for JS scripts?


I need to inject some code into remote site loaded to mainWindow. Thanks




As stef_pellegrino said you can use executeJavaScript. You can find the documentation on it here:

this example adds the platform to the class attribute of the HTML-tag of the loaded page.

mainWindow.webContents.on('dom-ready', function(e) {
  mainWindow.webContents.executeJavaScript('document.getElementsByTagName("html")[0].className += " platform-' + process.platform + '" ')