Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove page.metrics API #30

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 2 additions & 31 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
* [event: 'framedetached'](#event-framedetached)
* [event: 'framenavigated'](#event-framenavigated)
* [event: 'load'](#event-load)
* [event: 'metrics'](#event-metrics)
* [event: 'pageerror'](#event-pageerror)
* [event: 'popup'](#event-popup)
* [event: 'request'](#event-request)
Expand Down Expand Up @@ -116,7 +115,6 @@
* [page.isClosed()](#pageisclosed)
* [page.keyboard](#pagekeyboard)
* [page.mainFrame()](#pagemainframe)
* [page.metrics()](#pagemetrics)
* [page.mouse](#pagemouse)
* [page.pdf](#pagepdf)
* [page.queryObjects(prototypeHandle)](#pagequeryobjectsprototypehandle)
Expand Down Expand Up @@ -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.

#### 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'
- <[Error]> The exception message

Expand Down Expand Up @@ -1628,24 +1617,6 @@ Indicates that the page has been closed.

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

- returns: <[Mouse]>
Expand Down Expand Up @@ -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.

```js
page.on('workercreated', worker => console.log('Worker created: ' + worker.url()));
page.on('workerdestroyed', worker => console.log('Worker destroyed: ' + worker.url()));
page.workers.on('workercreated', worker => console.log('Worker created: ' + worker.url()));
page.workers.on('workerdestroyed', worker => console.log('Worker destroyed: ' + worker.url()));

console.log('Current workers:');
for (const worker of page.workers())
Expand Down
1 change: 0 additions & 1 deletion src/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const Events = {
FrameDetached: 'framedetached',
FrameNavigated: 'framenavigated',
Load: 'load',
Metrics: 'metrics',
Popup: 'popup',
},

Expand Down
54 changes: 0 additions & 54 deletions src/chromium/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ export class Page extends EventEmitter {
client.on('Page.javascriptDialogOpening', event => this._onDialog(event));
client.on('Runtime.exceptionThrown', exception => this._handleException(exception.exceptionDetails));
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('Page.fileChooserOpened', event => this._onFileChooser(event));
this._target._isClosedPromise.then(() => {
Expand Down Expand Up @@ -356,27 +355,6 @@ export class Page extends EventEmitter {
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) {
const message = getExceptionMessage(exceptionDetails);
const err = new Error(message);
Expand Down Expand Up @@ -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?: string,
path?: string,
Expand All @@ -823,22 +785,6 @@ type MediaFeature = {
value: string
}

const supportedMetrics: Set<string> = new Set([
'Timestamp',
'Documents',
'Frames',
'JSEventListeners',
'Nodes',
'LayoutCount',
'RecalcStyleCount',
'LayoutDuration',
'RecalcStyleDuration',
'ScriptDuration',
'TaskDuration',
'JSHeapUsedSize',
'JSHeapTotalSize',
]);

type NetworkCookie = {
name: string,
value: string,
Expand Down
5 changes: 1 addition & 4 deletions test/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
page.waitForFileChooser(),
page.click('input'),
]);
await Promise.all([
chooser.accept([FILE_TO_UPLOAD]),
new Promise(x => page.once('metrics', x)),
]);
await chooser.accept([FILE_TO_UPLOAD]);
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');
});
Expand Down
38 changes: 0 additions & 38 deletions test/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
it('should work', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
Expand Down