diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index dfacf6a02cf1..823351ebe116 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -117,9 +117,11 @@ let wrapWebContents = function (webContents) { hasUserGesture = false } if (this.getURL() && !this.isLoadingMainFrame()) { - return asyncWebFrameMethods.call(this, requestId, 'executeJavaScript', callback, code, hasUserGesture) + asyncWebFrameMethods.call(this, requestId, 'executeJavaScript', callback, code, hasUserGesture) } 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) + }) } } diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 1110269e5de1..c364b916c3a4 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -870,6 +870,14 @@ describe('browser-window module', function () { }) 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 () {