diff --git a/atom/renderer/lib/web-view/web-view.js b/atom/renderer/lib/web-view/web-view.js index 5257f0c12f98..4e34d2e55923 100644 --- a/atom/renderer/lib/web-view/web-view.js +++ b/atom/renderer/lib/web-view/web-view.js @@ -404,10 +404,13 @@ var registerWebViewElement = function() { // Forward proto.foo* method calls to WebViewImpl.foo*. createBlockHandler = function(m) { return function() { - var args, internal, ref1; - args = 1 <= arguments.length ? slice.call(arguments, 0) : []; - internal = v8Util.getHiddenValue(this, 'internal'); - return (ref1 = internal.webContents)[m].apply(ref1, args); + var args = 1 <= arguments.length ? slice.call(arguments, 0) : []; + var internal = v8Util.getHiddenValue(this, 'internal'); + if (internal.webContents) { + return internal.webContents[m].apply(internal.webContents, args); + } else { + throw new Error('Cannot call ' + m + ' before the dom-ready event is emitted') + } }; }; for (i = 0, len = methods.length; i < len; i++) { diff --git a/spec/webview-spec.js b/spec/webview-spec.js index faafec73db3b..072a51f36a5a 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -570,7 +570,7 @@ describe(' tag', function() { readyError = error; } - assert.equal(readyError.message, 'stop can only be called after the dom-ready event is emitted'); + assert.equal(readyError.message, 'Cannot call stop before the dom-ready event is emitted'); }); });