diff --git a/lib/Page.js b/lib/Page.js index a964c895be8..51b12074993 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -201,7 +201,7 @@ class Page extends EventEmitter { */ async _handleException(exceptionDetails) { let message = await helper.getExceptionMessage(this._client, exceptionDetails); - this.emit(Page.Events.Error, new Error(message)); + this.emit(Page.Events.PageError, new Error(message)); } async _onConsoleAPI(event) { @@ -617,7 +617,9 @@ function convertPrintParameterToInches(parameter) { Page.Events = { ConsoleMessage: 'consolemessage', Dialog: 'dialog', - Error: 'error', + // Can'e use just 'error' due to node.js special treatment of error events. + // @see https://nodejs.org/api/events.html#events_error_events + PageError: 'pageerror', Request: 'request', Response: 'response', RequestFailed: 'requestfailed', diff --git a/phantom_shim/WebPage.js b/phantom_shim/WebPage.js index b9bd3e0b3e8..37d9065b0eb 100644 --- a/phantom_shim/WebPage.js +++ b/phantom_shim/WebPage.js @@ -64,7 +64,7 @@ class WebPage { this._pageEvents.on(PageEvents.Confirm, message => this._onConfirm(message)); this._pageEvents.on(PageEvents.Alert, message => this._onAlert(message)); this._pageEvents.on(PageEvents.Dialog, dialog => this._onDialog(dialog)); - this._pageEvents.on(PageEvents.Error, error => (this._onError || noop).call(null, error.message, error.stack)); + this._pageEvents.on(PageEvents.PageError, error => (this._onError || noop).call(null, error.message, error.stack)); } get onInitialized() { diff --git a/test/test.js b/test/test.js index 4f691cfd535..01b18491710 100644 --- a/test/test.js +++ b/test/test.js @@ -336,9 +336,9 @@ describe('Puppeteer', function() { })); }); - describe('Page.Events.Error', function() { + describe('Page.Events.PageError', function() { it('should fire', function(done) { - page.on('error', error => { + page.on('pageerror', error => { expect(error.message).toContain('Fancy'); done(); });