feat: add Page.Events.DOMContentLoaded (#1730)

Fixes #1580
This commit is contained in:
Ian Hunter 2018-01-17 00:22:44 -07:00 committed by Andrey Lushnikov
parent 25b35c5789
commit 59f6d42610
3 changed files with 14 additions and 0 deletions

View File

@ -30,6 +30,7 @@
- [class: Page](#class-page)
* [event: 'console'](#event-console)
* [event: 'dialog'](#event-dialog)
* [event: 'domcontentloaded'](#event-domcontentloaded)
* [event: 'error'](#event-error)
* [event: 'frameattached'](#event-frameattached)
* [event: 'framedetached'](#event-framedetached)
@ -434,6 +435,10 @@ page.evaluate(() => console.log('hello', 5, {foo: 'bar'}));
Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Puppeteer can respond to the dialog via [Dialog]'s [accept](#dialogacceptprompttext) or [dismiss](#dialogdismiss) methods.
#### event: 'domcontentloaded'
Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched.
#### event: 'error'
- <[Error]>

View File

@ -95,6 +95,7 @@ class Page extends EventEmitter {
this._networkManager.on(NetworkManager.Events.RequestFailed, event => this.emit(Page.Events.RequestFailed, event));
this._networkManager.on(NetworkManager.Events.RequestFinished, event => this.emit(Page.Events.RequestFinished, event));
client.on('Page.domContentEventFired', event => this.emit(Page.Events.DOMContentLoaded));
client.on('Page.loadEventFired', event => this.emit(Page.Events.Load));
client.on('Runtime.consoleAPICalled', event => this._onConsoleAPI(event));
client.on('Page.javascriptDialogOpening', event => this._onDialog(event));
@ -965,6 +966,7 @@ function convertPrintParameterToInches(parameter) {
Page.Events = {
Console: 'console',
Dialog: 'dialog',
DOMContentLoaded: 'domcontentloaded',
Error: 'error',
// Can't use just 'error' due to node.js special treatment of error events.
// @see https://nodejs.org/api/events.html#events_error_events

View File

@ -969,6 +969,13 @@ describe('Page', function() {
});
});
describe('Page.Events.DOMContentLoaded', function() {
it('should fire when expected', async({page, server}) => {
page.goto('about:blank');
await waitForEvents(page, 'domcontentloaded', 1);
});
});
describe('Page.metrics', function() {
it('should get metrics from a page', async({page, server}) => {
await page.goto('about:blank');