chore: remove page.metrics API (#30)
This commit is contained in:
parent
b4b7b6b96c
commit
35e6d10517
33
docs/api.md
33
docs/api.md
|
|
@ -71,7 +71,6 @@
|
||||||
* [event: 'framedetached'](#event-framedetached)
|
* [event: 'framedetached'](#event-framedetached)
|
||||||
* [event: 'framenavigated'](#event-framenavigated)
|
* [event: 'framenavigated'](#event-framenavigated)
|
||||||
* [event: 'load'](#event-load)
|
* [event: 'load'](#event-load)
|
||||||
* [event: 'metrics'](#event-metrics)
|
|
||||||
* [event: 'pageerror'](#event-pageerror)
|
* [event: 'pageerror'](#event-pageerror)
|
||||||
* [event: 'popup'](#event-popup)
|
* [event: 'popup'](#event-popup)
|
||||||
* [event: 'request'](#event-request)
|
* [event: 'request'](#event-request)
|
||||||
|
|
@ -116,7 +115,6 @@
|
||||||
* [page.isClosed()](#pageisclosed)
|
* [page.isClosed()](#pageisclosed)
|
||||||
* [page.keyboard](#pagekeyboard)
|
* [page.keyboard](#pagekeyboard)
|
||||||
* [page.mainFrame()](#pagemainframe)
|
* [page.mainFrame()](#pagemainframe)
|
||||||
* [page.metrics()](#pagemetrics)
|
|
||||||
* [page.mouse](#pagemouse)
|
* [page.mouse](#pagemouse)
|
||||||
* [page.pdf](#pagepdf)
|
* [page.pdf](#pagepdf)
|
||||||
* [page.queryObjects(prototypeHandle)](#pagequeryobjectsprototypehandle)
|
* [page.queryObjects(prototypeHandle)](#pagequeryobjectsprototypehandle)
|
||||||
|
|
@ -1010,15 +1008,6 @@ Emitted when a frame is navigated to a new url.
|
||||||
|
|
||||||
Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.
|
Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.
|
||||||
|
|
||||||
#### event: 'metrics'
|
|
||||||
- <[Object]>
|
|
||||||
- `title` <[string]> The title passed to `console.timeStamp`.
|
|
||||||
- `metrics` <[Object]> Object containing metrics as key/value pairs. The values
|
|
||||||
of metrics are of <[number]> type.
|
|
||||||
|
|
||||||
Emitted when the JavaScript code makes a call to `console.timeStamp`. For the list
|
|
||||||
of metrics see `page.metrics`.
|
|
||||||
|
|
||||||
#### event: 'pageerror'
|
#### event: 'pageerror'
|
||||||
- <[Error]> The exception message
|
- <[Error]> The exception message
|
||||||
|
|
||||||
|
|
@ -1628,24 +1617,6 @@ Indicates that the page has been closed.
|
||||||
|
|
||||||
Page is guaranteed to have a main frame which persists during navigations.
|
Page is guaranteed to have a main frame which persists during navigations.
|
||||||
|
|
||||||
#### page.metrics()
|
|
||||||
- returns: <[Promise]<[Object]>> Object containing metrics as key/value pairs.
|
|
||||||
- `Timestamp` <[number]> The timestamp when the metrics sample was taken.
|
|
||||||
- `Documents` <[number]> Number of documents in the page.
|
|
||||||
- `Frames` <[number]> Number of frames in the page.
|
|
||||||
- `JSEventListeners` <[number]> Number of events in the page.
|
|
||||||
- `Nodes` <[number]> Number of DOM nodes in the page.
|
|
||||||
- `LayoutCount` <[number]> Total number of full or partial page layout.
|
|
||||||
- `RecalcStyleCount` <[number]> Total number of page style recalculations.
|
|
||||||
- `LayoutDuration` <[number]> Combined durations of all page layouts.
|
|
||||||
- `RecalcStyleDuration` <[number]> Combined duration of all page style recalculations.
|
|
||||||
- `ScriptDuration` <[number]> Combined duration of JavaScript execution.
|
|
||||||
- `TaskDuration` <[number]> Combined duration of all tasks performed by the browser.
|
|
||||||
- `JSHeapUsedSize` <[number]> Used JavaScript heap size.
|
|
||||||
- `JSHeapTotalSize` <[number]> Total JavaScript heap size.
|
|
||||||
|
|
||||||
> **NOTE** All timestamps are in monotonic time: monotonically increasing time in seconds since an arbitrary point in the past.
|
|
||||||
|
|
||||||
#### page.mouse
|
#### page.mouse
|
||||||
|
|
||||||
- returns: <[Mouse]>
|
- returns: <[Mouse]>
|
||||||
|
|
@ -2179,8 +2150,8 @@ The Worker class represents a [WebWorker](https://developer.mozilla.org/en-US/do
|
||||||
The events `workercreated` and `workerdestroyed` are emitted on the page object to signal the worker lifecycle.
|
The events `workercreated` and `workerdestroyed` are emitted on the page object to signal the worker lifecycle.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
page.on('workercreated', worker => console.log('Worker created: ' + worker.url()));
|
page.workers.on('workercreated', worker => console.log('Worker created: ' + worker.url()));
|
||||||
page.on('workerdestroyed', worker => console.log('Worker destroyed: ' + worker.url()));
|
page.workers.on('workerdestroyed', worker => console.log('Worker destroyed: ' + worker.url()));
|
||||||
|
|
||||||
console.log('Current workers:');
|
console.log('Current workers:');
|
||||||
for (const worker of page.workers())
|
for (const worker of page.workers())
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ export const Events = {
|
||||||
FrameDetached: 'framedetached',
|
FrameDetached: 'framedetached',
|
||||||
FrameNavigated: 'framenavigated',
|
FrameNavigated: 'framenavigated',
|
||||||
Load: 'load',
|
Load: 'load',
|
||||||
Metrics: 'metrics',
|
|
||||||
Popup: 'popup',
|
Popup: 'popup',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,6 @@ export class Page extends EventEmitter {
|
||||||
client.on('Page.javascriptDialogOpening', event => this._onDialog(event));
|
client.on('Page.javascriptDialogOpening', event => this._onDialog(event));
|
||||||
client.on('Runtime.exceptionThrown', exception => this._handleException(exception.exceptionDetails));
|
client.on('Runtime.exceptionThrown', exception => this._handleException(exception.exceptionDetails));
|
||||||
client.on('Inspector.targetCrashed', event => this._onTargetCrashed());
|
client.on('Inspector.targetCrashed', event => this._onTargetCrashed());
|
||||||
client.on('Performance.metrics', event => this._emitMetrics(event));
|
|
||||||
client.on('Log.entryAdded', event => this._onLogEntryAdded(event));
|
client.on('Log.entryAdded', event => this._onLogEntryAdded(event));
|
||||||
client.on('Page.fileChooserOpened', event => this._onFileChooser(event));
|
client.on('Page.fileChooserOpened', event => this._onFileChooser(event));
|
||||||
this._target._isClosedPromise.then(() => {
|
this._target._isClosedPromise.then(() => {
|
||||||
|
|
@ -356,27 +355,6 @@ export class Page extends EventEmitter {
|
||||||
return this._frameManager.networkManager().setUserAgent(userAgent);
|
return this._frameManager.networkManager().setUserAgent(userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
async metrics(): Promise<Metrics> {
|
|
||||||
const response = await this._client.send('Performance.getMetrics');
|
|
||||||
return this._buildMetricsObject(response.metrics);
|
|
||||||
}
|
|
||||||
|
|
||||||
_emitMetrics(event: Protocol.Performance.metricsPayload) {
|
|
||||||
this.emit(Events.Page.Metrics, {
|
|
||||||
title: event.title,
|
|
||||||
metrics: this._buildMetricsObject(event.metrics)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_buildMetricsObject(metrics: Protocol.Performance.Metric[] | null): Metrics {
|
|
||||||
const result = {};
|
|
||||||
for (const metric of metrics || []) {
|
|
||||||
if (supportedMetrics.has(metric.name))
|
|
||||||
result[metric.name] = metric.value;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
_handleException(exceptionDetails: Protocol.Runtime.ExceptionDetails) {
|
_handleException(exceptionDetails: Protocol.Runtime.ExceptionDetails) {
|
||||||
const message = getExceptionMessage(exceptionDetails);
|
const message = getExceptionMessage(exceptionDetails);
|
||||||
const err = new Error(message);
|
const err = new Error(message);
|
||||||
|
|
@ -792,22 +770,6 @@ export class Page extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Metrics = {
|
|
||||||
Timestamp?: number,
|
|
||||||
Documents?: number,
|
|
||||||
Frames?: number,
|
|
||||||
JSEventListeners?: number,
|
|
||||||
Nodes?: number,
|
|
||||||
LayoutCount?: number,
|
|
||||||
RecalcStyleCount?: number,
|
|
||||||
LayoutDuration?: number,
|
|
||||||
RecalcStyleDuration?: number,
|
|
||||||
ScriptDuration?: number,
|
|
||||||
TaskDuration?: number,
|
|
||||||
JSHeapUsedSize?: number,
|
|
||||||
JSHeapTotalSize?: number,
|
|
||||||
}
|
|
||||||
|
|
||||||
type ScreenshotOptions = {
|
type ScreenshotOptions = {
|
||||||
type?: string,
|
type?: string,
|
||||||
path?: string,
|
path?: string,
|
||||||
|
|
@ -823,22 +785,6 @@ type MediaFeature = {
|
||||||
value: string
|
value: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const supportedMetrics: Set<string> = new Set([
|
|
||||||
'Timestamp',
|
|
||||||
'Documents',
|
|
||||||
'Frames',
|
|
||||||
'JSEventListeners',
|
|
||||||
'Nodes',
|
|
||||||
'LayoutCount',
|
|
||||||
'RecalcStyleCount',
|
|
||||||
'LayoutDuration',
|
|
||||||
'RecalcStyleDuration',
|
|
||||||
'ScriptDuration',
|
|
||||||
'TaskDuration',
|
|
||||||
'JSHeapUsedSize',
|
|
||||||
'JSHeapTotalSize',
|
|
||||||
]);
|
|
||||||
|
|
||||||
type NetworkCookie = {
|
type NetworkCookie = {
|
||||||
name: string,
|
name: string,
|
||||||
value: string,
|
value: string,
|
||||||
|
|
|
||||||
|
|
@ -104,10 +104,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
|
||||||
page.waitForFileChooser(),
|
page.waitForFileChooser(),
|
||||||
page.click('input'),
|
page.click('input'),
|
||||||
]);
|
]);
|
||||||
await Promise.all([
|
await chooser.accept([FILE_TO_UPLOAD]);
|
||||||
chooser.accept([FILE_TO_UPLOAD]),
|
|
||||||
new Promise(x => page.once('metrics', x)),
|
|
||||||
]);
|
|
||||||
expect(await page.$eval('input', input => input.files.length)).toBe(1);
|
expect(await page.$eval('input', input => input.files.length)).toBe(1);
|
||||||
expect(await page.$eval('input', input => input.files[0].name)).toBe('file-to-upload.txt');
|
expect(await page.$eval('input', input => input.files[0].name)).toBe('file-to-upload.txt');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -436,44 +436,6 @@ module.exports.addTests = function({testRunner, expect, headless, playwright, FF
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe.skip(FFOX || WEBKIT)('Page.metrics', function() {
|
|
||||||
it('should get metrics from a page', async({page, server}) => {
|
|
||||||
await page.goto('about:blank');
|
|
||||||
const metrics = await page.metrics();
|
|
||||||
checkMetrics(metrics);
|
|
||||||
});
|
|
||||||
it('metrics event fired on console.timeStamp', async({page, server}) => {
|
|
||||||
const metricsPromise = new Promise(fulfill => page.once('metrics', fulfill));
|
|
||||||
await page.evaluate(() => console.timeStamp('test42'));
|
|
||||||
const metrics = await metricsPromise;
|
|
||||||
expect(metrics.title).toBe('test42');
|
|
||||||
checkMetrics(metrics.metrics);
|
|
||||||
});
|
|
||||||
function checkMetrics(metrics) {
|
|
||||||
const metricsToCheck = new Set([
|
|
||||||
'Timestamp',
|
|
||||||
'Documents',
|
|
||||||
'Frames',
|
|
||||||
'JSEventListeners',
|
|
||||||
'Nodes',
|
|
||||||
'LayoutCount',
|
|
||||||
'RecalcStyleCount',
|
|
||||||
'LayoutDuration',
|
|
||||||
'RecalcStyleDuration',
|
|
||||||
'ScriptDuration',
|
|
||||||
'TaskDuration',
|
|
||||||
'JSHeapUsedSize',
|
|
||||||
'JSHeapTotalSize',
|
|
||||||
]);
|
|
||||||
for (const name in metrics) {
|
|
||||||
expect(metricsToCheck.has(name)).toBeTruthy();
|
|
||||||
expect(metrics[name]).toBeGreaterThanOrEqual(0);
|
|
||||||
metricsToCheck.delete(name);
|
|
||||||
}
|
|
||||||
expect(metricsToCheck.size).toBe(0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Page.waitForRequest', function() {
|
describe('Page.waitForRequest', function() {
|
||||||
it('should work', async({page, server}) => {
|
it('should work', async({page, server}) => {
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue