From 15b36b1cf0f9022ee2235bfa8722afe9382ba37a Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Sat, 13 May 2017 11:12:06 -0700 Subject: [PATCH] Drop unneeded Page Event's prefixes. This patch drops 'Page.Event.' prefix in every puppeteer's page event. This makes it convenient to subscribe to events by their string value. --- examples/features.js | 2 +- lib/Page.js | 10 +++++----- test/test.js | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/features.js b/examples/features.js index bfc3fd5b1fed4..6838e8ed150b0 100644 --- a/examples/features.js +++ b/examples/features.js @@ -21,7 +21,7 @@ var browser = new Browser(); browser.newPage().then(async page => { var modernizrPath = path.join('..', 'third_party', 'phantomjs', 'examples', 'modernizr.js'); await page.injectFile(modernizrPath); - page.on('Page.Events.ConsoleMessage', console.log); + page.on('ConsoleMessage', console.log); await page.evaluate(detectFeatures); browser.close(); }); diff --git a/lib/Page.js b/lib/Page.js index 4a0f4f19d8b5a..581338b44d4a3 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -416,11 +416,11 @@ Page.ScreenshotTypes = { }; Page.Events = { - ConsoleMessage: 'Page.Events.ConsoleMessage', - DialogOpened: 'Page.Events.DialogOpened', - ExceptionThrown: 'Page.Events.ExceptionThrown', - ResourceLoadingFailed: 'Page.Events.ResourceLoadingFailed', - ResponseReceived: 'Page.Events.ResponseReceived', + ConsoleMessage: 'ConsoleMessage', + DialogOpened: 'DialogOpened', + ExceptionThrown: 'ExceptionThrown', + ResourceLoadingFailed: 'ResourceLoadingFailed', + ResponseReceived: 'ResponseReceived', }; module.exports = Page; diff --git a/test/test.js b/test/test.js index 201ad6d4529c5..7031c738d48ef 100644 --- a/test/test.js +++ b/test/test.js @@ -33,9 +33,9 @@ describe('Puppeteer', function() { expect(result).toBe(56); })); - it('Page.Events.ConsoleMessage', SX(async function() { + it('Page Events: ConsoleMessage', SX(async function() { var msgs = []; - page.on('Page.Events.ConsoleMessage', msg => msgs.push(msg)); + page.on('ConsoleMessage', msg => msgs.push(msg)); await page.evaluate(() => console.log('Message!')); expect(msgs).toEqual(['Message!']); }));