diff --git a/docs/api.md b/docs/api.md index dae44bd2672..ccc34dd39ae 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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]> diff --git a/lib/Page.js b/lib/Page.js index cbbfec0d97d..3d639b9056d 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -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 diff --git a/test/test.js b/test/test.js index b185e80a346..948cdba9fe9 100644 --- a/test/test.js +++ b/test/test.js @@ -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');