If you're using the most recent version of electron, you might want to give this a shot based on the webview documentation:
Adding CSS
// Injecting CSS into the page
var myWebview = ;// define your webview here
myWebview.insertCSS("body{background:#000}");
Alternatively, you can execute some JavaScript code using executeJavascriptCode
var myWebview = ;// define your webview here
myWebview.executeJavaScript("$('.mySelector').hide();");
In both cases, I recommend reading file contents and passing them as function arguments or appending your files to your webview
using executeJavascriptCode
. See the example below:
// Appending javascript code
var scriptPath = __dirname + '/path/to/script.js';
var myWebview = ;// define your webview here
myWebview.executeJavaScript('document.write(\'<script src="' + scriptPath + '"></script>\');');
// Appending CSS code
var cssPath = __dirname + '/path/to/stylesheet.js';
var myWebview = ;// define your webview here
myWebview.executeJavaScript('document.write(\'<link rel="stylesheet" type="text/css" href="' + cssPath + '">\');');
Hopefully this information proves useful.
Best of luck!