Rename Page.Events.Error into Page.Events.PageError

The 'error' event has a special treatment in Node:
https://nodejs.org/api/events.html#events_error_events

To avoid this, this patch renames the 'error' event into
the 'pageerror'.
This commit is contained in:
Andrey Lushnikov 2017-07-06 11:22:32 -07:00
parent 19e882f505
commit 64fed38c60
3 changed files with 7 additions and 5 deletions

View File

@ -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',

View File

@ -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() {

View File

@ -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();
});