Skip to content

Instantly share code, notes, and snippets.

@bengfarrell
Created September 19, 2014 05:30
Show Gist options
  • Save bengfarrell/4bd75031e40c5dd7202e to your computer and use it in GitHub Desktop.
Save bengfarrell/4bd75031e40c5dd7202e to your computer and use it in GitHub Desktop.
Injecting a script into a page using Atom-Shell
app.on('ready', function() {
var injectscript = escape(__dirname + '/inject/test.js');
mainWindow = new BrowserWindow( { width: '800px', height: '600px', 'web-preferences': { 'web-security': false } });
mainWindow.loadUrl('http://google.com' );
mainWindow.openDevTools();
mainWindow.getWebContents().on('did-finish-load', function() {
var remotejs = "var js = document.createElement('script'); \
js.src = 'file://' + unescape('" + injectscript + "'); \
console.log(js); \
document.getElementsByTagName('body')[0].appendChild(js);";
this.executeJavaScript(remotejs);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment