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:
parent
8a8076c15b
commit
15b36b1cf0
@ -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();
|
||||||
});
|
});
|
||||||
|
10
lib/Page.js
10
lib/Page.js
@ -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;
|
||||||
|
@ -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!']);
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user