Created
September 19, 2014 05:30
-
-
Save bengfarrell/4bd75031e40c5dd7202e to your computer and use it in GitHub Desktop.
Injecting a script into a page using Atom-Shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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