forked from checkinholiday/lighthouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-thread-tasks.js
58 lines (50 loc) · 1.57 KB
/
main-thread-tasks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {Audit} from './audit.js';
import {MainThreadTasks as MainThreadTasksComputed} from '../computed/main-thread-tasks.js';
class MainThreadTasks extends Audit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'main-thread-tasks',
scoreDisplayMode: Audit.SCORING_MODES.INFORMATIVE,
title: 'Tasks',
description: 'Lists the toplevel main thread tasks that executed during page load.',
requiredArtifacts: ['traces'],
};
}
/**
* @param {LH.Artifacts} artifacts
* @param {LH.Audit.Context} context
* @return {Promise<LH.Audit.Product>}
*/
static async audit(artifacts, context) {
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const tasks = await MainThreadTasksComputed.request(trace, context);
const results = tasks
// Filter to just the sizable toplevel tasks; toplevel tasks are tasks without a parent.
.filter(task => task.duration > 5 && !task.parent)
.map(task => {
return {
duration: task.duration,
startTime: task.startTime,
};
});
/** @type {LH.Audit.Details.Table['headings']} */
const headings = [
{key: 'startTime', valueType: 'ms', granularity: 1, label: 'Start Time'},
{key: 'duration', valueType: 'ms', granularity: 1, label: 'End Time'},
];
const tableDetails = Audit.makeTableDetails(headings, results);
return {
score: 1,
details: tableDetails,
};
}
}
export default MainThreadTasks;