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.
This commit is contained in:
Andrey Lushnikov 2017-05-13 11:12:06 -07:00
parent 8a8076c15b
commit 15b36b1cf0
3 changed files with 8 additions and 8 deletions

View File

@ -21,7 +21,7 @@ var browser = new Browser();
browser.newPage().then(async page => { browser.newPage().then(async page => {
var modernizrPath = path.join('..', 'third_party', 'phantomjs', 'examples', 'modernizr.js'); var modernizrPath = path.join('..', 'third_party', 'phantomjs', 'examples', 'modernizr.js');
await page.injectFile(modernizrPath); await page.injectFile(modernizrPath);
page.on('Page.Events.ConsoleMessage', console.log); page.on('ConsoleMessage', console.log);
await page.evaluate(detectFeatures); await page.evaluate(detectFeatures);
browser.close(); browser.close();
}); });

View File

@ -416,11 +416,11 @@ Page.ScreenshotTypes = {
}; };
Page.Events = { Page.Events = {
ConsoleMessage: 'Page.Events.ConsoleMessage', ConsoleMessage: 'ConsoleMessage',
DialogOpened: 'Page.Events.DialogOpened', DialogOpened: 'DialogOpened',
ExceptionThrown: 'Page.Events.ExceptionThrown', ExceptionThrown: 'ExceptionThrown',
ResourceLoadingFailed: 'Page.Events.ResourceLoadingFailed', ResourceLoadingFailed: 'ResourceLoadingFailed',
ResponseReceived: 'Page.Events.ResponseReceived', ResponseReceived: 'ResponseReceived',
}; };
module.exports = Page; module.exports = Page;

View File

@ -33,9 +33,9 @@ describe('Puppeteer', function() {
expect(result).toBe(56); expect(result).toBe(56);
})); }));
it('Page.Events.ConsoleMessage', SX(async function() { it('Page Events: ConsoleMessage', SX(async function() {
var msgs = []; var msgs = [];
page.on('Page.Events.ConsoleMessage', msg => msgs.push(msg)); page.on('ConsoleMessage', msg => msgs.push(msg));
await page.evaluate(() => console.log('Message!')); await page.evaluate(() => console.log('Message!'));
expect(msgs).toEqual(['Message!']); expect(msgs).toEqual(['Message!']);
})); }));