Created
January 6, 2020 04:19
-
-
Save asamountain/1ad31699defe60ce67c1ba9f14aa361d to your computer and use it in GitHub Desktop.
get matric time for debugging in puppeteer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer'); | |
(async () => { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
// Emitted when the DOM is parsed and ready (without waiting for resources) | |
page.once('domcontentloaded', () => console.info('β DOM is ready')); | |
// Emitted when the page is fully loaded | |
page.once('load', () => console.info('β Page is loaded')); | |
// Emitted when the page attaches a frame | |
page.on('frameattached', () => console.info('β Frame is attached')); | |
// Emitted when a frame within the page is navigated to a new URL | |
page.on('framenavigated', () => console.info('π Frame is navigated')); | |
// Emitted when a script within the page uses `console.timeStamp` | |
page.on('metrics', data => console.info(`π Timestamp added at ${data.metrics.Timestamp}`)); | |
// Emitted when a script within the page uses `console` | |
page.on('console', message => console[message.type()](`π ${message.text()}`)); | |
// Emitted when the page emits an error event (for example, the page crashes) | |
page.on('error', error => console.error(`β ${error}`)); | |
// Emitted when a script within the page has uncaught exception | |
page.on('pageerror', error => console.error(`β ${error}`)); | |
// Emitted when a script within the page uses `alert`, `prompt`, `confirm` or `beforeunload` | |
page.on('dialog', async dialog => { | |
console.info(`π ${dialog.message()}`); | |
await dialog.dismiss(); | |
}); | |
// Emitted when a new page, that belongs to the browser context, is opened | |
page.on('popup', () => console.info('π New page is opened')); | |
// Emitted when the page produces a request | |
page.on('request', request => console.info(`π Request: ${request.url()}`)); | |
// Emitted when a request, which is produced by the page, fails | |
page.on('requestfailed', request => console.info(`β Failed request: ${request.url()}`)); | |
// Emitted when a request, which is produced by the page, finishes successfully | |
page.on('requestfinished', request => console.info(`π Finished request: ${request.url()}`)); | |
// Emitted when a response is received | |
page.on('response', response => console.info(`π Response: ${response.url()}`)); | |
// Emitted when the page creates a dedicated WebWorker | |
page.on('workercreated', worker => console.info(`π Worker: ${worker.url()}`)); | |
// Emitted when the page destroys a dedicated WebWorker | |
page.on('workerdestroyed', worker => console.info(`π Destroyed worker: ${worker.url()}`)); | |
// Emitted when the page detaches a frame | |
page.on('framedetached', () => console.info('β Frame is detached')); | |
// Emitted after the page is closed | |
page.once('close', () => console.info('β Page is closed')); | |
await page.goto('https://pptr.dev'); | |
await browser.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment