Merge pull request #5319 from deepak1556/webcontents_executejavascript_patch

webContents: fix executejavascript when called before page load
This commit is contained in:
Cheng Zhao 2016-04-28 16:43:50 +09:00
commit 68192785e7
2 changed files with 12 additions and 2 deletions

View file

@ -117,9 +117,11 @@ let wrapWebContents = function (webContents) {
hasUserGesture = false hasUserGesture = false
} }
if (this.getURL() && !this.isLoadingMainFrame()) { if (this.getURL() && !this.isLoadingMainFrame()) {
return asyncWebFrameMethods.call(this, requestId, 'executeJavaScript', callback, code, hasUserGesture) asyncWebFrameMethods.call(this, requestId, 'executeJavaScript', callback, code, hasUserGesture)
} else { } else {
return this.once('did-finish-load', asyncWebFrameMethods.bind(this, requestId, 'executeJavaScript', callback, code, hasUserGesture)) this.once('did-finish-load', () => {
asyncWebFrameMethods.call(this, requestId, 'executeJavaScript', callback, code, hasUserGesture)
})
} }
} }

View file

@ -870,6 +870,14 @@ describe('browser-window module', function () {
}) })
w.loadURL(server.url) w.loadURL(server.url)
}) })
it('executes after page load', function (done) {
w.webContents.executeJavaScript(code, function(result) {
assert.equal(result, expected)
done()
})
w.loadURL(server.url)
})
}) })
describe('deprecated options', function () { describe('deprecated options', function () {