lighthouse 9.5.0-dev.20220606 → 9.5.0-dev.20220609
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/report/bundle.esm.js +25 -1
- package/dist/report/flow.js +3 -3
- package/esm-utils.mjs +40 -0
- package/flow-report/tsconfig.json +0 -2
- package/lighthouse-core/config/config.js +1 -0
- package/lighthouse-core/fraggle-rock/config/filters.js +1 -0
- package/lighthouse-core/fraggle-rock/gather/driver.js +8 -12
- package/lighthouse-core/fraggle-rock/gather/session.js +31 -56
- package/lighthouse-core/gather/connections/cri.js +4 -1
- package/lighthouse-core/gather/driver/network-monitor.js +28 -10
- package/lighthouse-core/gather/driver/target-manager.js +29 -17
- package/lighthouse-core/gather/driver/wait-for-condition.js +4 -3
- package/lighthouse-core/gather/driver.js +2 -12
- package/lighthouse-core/gather/gather-runner.js +15 -0
- package/lighthouse-core/gather/gatherers/devtools-log.js +56 -2
- package/lighthouse-core/lib/network-recorder.js +2 -2
- package/lighthouse-core/runner.js +1 -0
- package/package.json +4 -4
- package/report/generator/tsconfig.json +0 -2
- package/report/renderer/swap-locale-feature.js +2 -2
- package/report/tsconfig.json +0 -2
- package/shared/tsconfig.json +0 -2
- package/tsconfig-base.json +5 -0
- package/tsconfig.json +2 -3
- package/types/artifacts.d.ts +2 -0
- package/types/gatherer.d.ts +0 -2
- package/types/lhr/lhr.d.ts +2 -0
- package/types/lhr/tsconfig.json +0 -2
- package/types/lighthouse-logger/index.d.ts +1 -0
- package/lighthouse-core/gather/devtools-log.js +0 -61
package/esm-utils.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
4
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
// TODO(esmodules): rename to .js when root is type: module
|
|
8
|
+
|
|
9
|
+
import module from 'module';
|
|
10
|
+
import url from 'url';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Commonjs equivalent of `require.resolve`.
|
|
15
|
+
* @param {string} packageName
|
|
16
|
+
*/
|
|
17
|
+
function resolveModulePath(packageName) {
|
|
18
|
+
const require = module.createRequire(import.meta.url);
|
|
19
|
+
return require.resolve(packageName);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {ImportMeta} importMeta
|
|
24
|
+
*/
|
|
25
|
+
function getModulePath(importMeta) {
|
|
26
|
+
return url.fileURLToPath(importMeta.url);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {ImportMeta} importMeta
|
|
31
|
+
*/
|
|
32
|
+
function getModuleDirectory(importMeta) {
|
|
33
|
+
return path.dirname(getModulePath(importMeta));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
resolveModulePath,
|
|
38
|
+
getModulePath,
|
|
39
|
+
getModuleDirectory,
|
|
40
|
+
};
|
|
@@ -16,7 +16,7 @@ const throwNotConnectedFn = () => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/** @type {LH.Gatherer.FRProtocolSession} */
|
|
19
|
-
const
|
|
19
|
+
const throwingSession = {
|
|
20
20
|
setTargetInfo: throwNotConnectedFn,
|
|
21
21
|
hasNextProtocolTimeout: throwNotConnectedFn,
|
|
22
22
|
getNextProtocolTimeout: throwNotConnectedFn,
|
|
@@ -26,8 +26,6 @@ const defaultSession = {
|
|
|
26
26
|
off: throwNotConnectedFn,
|
|
27
27
|
addProtocolMessageListener: throwNotConnectedFn,
|
|
28
28
|
removeProtocolMessageListener: throwNotConnectedFn,
|
|
29
|
-
addSessionAttachedListener: throwNotConnectedFn,
|
|
30
|
-
removeSessionAttachedListener: throwNotConnectedFn,
|
|
31
29
|
sendCommand: throwNotConnectedFn,
|
|
32
30
|
dispose: throwNotConnectedFn,
|
|
33
31
|
};
|
|
@@ -39,14 +37,12 @@ class Driver {
|
|
|
39
37
|
*/
|
|
40
38
|
constructor(page) {
|
|
41
39
|
this._page = page;
|
|
42
|
-
/** @type {LH.Gatherer.FRProtocolSession|undefined} */
|
|
43
|
-
this._session = undefined;
|
|
44
40
|
/** @type {ExecutionContext|undefined} */
|
|
45
41
|
this._executionContext = undefined;
|
|
46
42
|
/** @type {Fetcher|undefined} */
|
|
47
43
|
this._fetcher = undefined;
|
|
48
44
|
|
|
49
|
-
this.defaultSession =
|
|
45
|
+
this.defaultSession = throwingSession;
|
|
50
46
|
}
|
|
51
47
|
|
|
52
48
|
/** @return {LH.Gatherer.FRTransitionalDriver['executionContext']} */
|
|
@@ -68,20 +64,20 @@ class Driver {
|
|
|
68
64
|
|
|
69
65
|
/** @return {Promise<void>} */
|
|
70
66
|
async connect() {
|
|
71
|
-
if (this.
|
|
67
|
+
if (this.defaultSession !== throwingSession) return;
|
|
72
68
|
const status = {msg: 'Connecting to browser', id: 'lh:driver:connect'};
|
|
73
69
|
log.time(status);
|
|
74
70
|
const session = await this._page.target().createCDPSession();
|
|
75
|
-
this.
|
|
76
|
-
this._executionContext = new ExecutionContext(this.
|
|
77
|
-
this._fetcher = new Fetcher(this.
|
|
71
|
+
this.defaultSession = new ProtocolSession(session);
|
|
72
|
+
this._executionContext = new ExecutionContext(this.defaultSession);
|
|
73
|
+
this._fetcher = new Fetcher(this.defaultSession);
|
|
78
74
|
log.timeEnd(status);
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
/** @return {Promise<void>} */
|
|
82
78
|
async disconnect() {
|
|
83
|
-
if (
|
|
84
|
-
await this.
|
|
79
|
+
if (this.defaultSession === throwingSession) return;
|
|
80
|
+
await this.defaultSession.dispose();
|
|
85
81
|
}
|
|
86
82
|
}
|
|
87
83
|
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
8
|
const LHError = require('../../lib/lh-error.js');
|
|
9
|
-
const SessionEmitMonkeypatch = Symbol('monkeypatch');
|
|
10
9
|
|
|
11
10
|
// Controls how long to wait for a response after sending a DevTools protocol command.
|
|
12
11
|
const DEFAULT_PROTOCOL_TIMEOUT = 30000;
|
|
@@ -14,32 +13,23 @@ const DEFAULT_PROTOCOL_TIMEOUT = 30000;
|
|
|
14
13
|
/** @implements {LH.Gatherer.FRProtocolSession} */
|
|
15
14
|
class ProtocolSession {
|
|
16
15
|
/**
|
|
17
|
-
* @param {LH.Puppeteer.CDPSession}
|
|
16
|
+
* @param {LH.Puppeteer.CDPSession} cdpSession
|
|
18
17
|
*/
|
|
19
|
-
constructor(
|
|
20
|
-
this.
|
|
18
|
+
constructor(cdpSession) {
|
|
19
|
+
this._cdpSession = cdpSession;
|
|
21
20
|
/** @type {LH.Crdp.Target.TargetInfo|undefined} */
|
|
22
21
|
this._targetInfo = undefined;
|
|
23
22
|
/** @type {number|undefined} */
|
|
24
23
|
this._nextProtocolTimeout = undefined;
|
|
25
24
|
/** @type {WeakMap<any, any>} */
|
|
26
25
|
this._callbackMap = new WeakMap();
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
session.emit = (method, ...args) => {
|
|
34
|
-
// OOPIF sessions need to emit their sessionId so downstream processors can recognize
|
|
35
|
-
// the target the event came from.
|
|
36
|
-
const sessionId = this._targetInfo && this._targetInfo.type === 'iframe' ?
|
|
37
|
-
this._targetInfo.targetId : undefined;
|
|
38
|
-
originalEmit.call(session, '*', {method, params: args[0], sessionId});
|
|
39
|
-
return originalEmit.call(session, method, ...args);
|
|
40
|
-
};
|
|
41
|
-
// @ts-expect-error - It's monkeypatching 🤷♂️.
|
|
42
|
-
session.emit[SessionEmitMonkeypatch] = true;
|
|
28
|
+
sessionId() {
|
|
29
|
+
return this._targetInfo && this._targetInfo.type === 'iframe' ?
|
|
30
|
+
// TODO: use this._session.id() for real session id.
|
|
31
|
+
this._targetInfo.targetId :
|
|
32
|
+
undefined;
|
|
43
33
|
}
|
|
44
34
|
|
|
45
35
|
/** @param {LH.Crdp.Target.TargetInfo} targetInfo */
|
|
@@ -75,7 +65,7 @@ class ProtocolSession {
|
|
|
75
65
|
* @param {(...args: LH.CrdpEvents[E]) => void} callback
|
|
76
66
|
*/
|
|
77
67
|
on(eventName, callback) {
|
|
78
|
-
this.
|
|
68
|
+
this._cdpSession.on(eventName, /** @type {*} */ (callback));
|
|
79
69
|
}
|
|
80
70
|
|
|
81
71
|
/**
|
|
@@ -85,44 +75,35 @@ class ProtocolSession {
|
|
|
85
75
|
* @param {(...args: LH.CrdpEvents[E]) => void} callback
|
|
86
76
|
*/
|
|
87
77
|
once(eventName, callback) {
|
|
88
|
-
this.
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Bind to the puppeteer `sessionattached` listener and return an LH ProtocolSession.
|
|
93
|
-
* @param {(session: ProtocolSession) => void} callback
|
|
94
|
-
*/
|
|
95
|
-
addSessionAttachedListener(callback) {
|
|
96
|
-
/** @param {LH.Puppeteer.CDPSession} session */
|
|
97
|
-
const listener = session => callback(new ProtocolSession(session));
|
|
98
|
-
this._callbackMap.set(callback, listener);
|
|
99
|
-
this._getConnection().on('sessionattached', listener);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Unbind to the puppeteer `sessionattached` listener.
|
|
104
|
-
* @param {(session: ProtocolSession) => void} callback
|
|
105
|
-
*/
|
|
106
|
-
removeSessionAttachedListener(callback) {
|
|
107
|
-
const listener = this._callbackMap.get(callback);
|
|
108
|
-
if (!listener) return;
|
|
109
|
-
this._getConnection().off('sessionattached', listener);
|
|
78
|
+
this._cdpSession.once(eventName, /** @type {*} */ (callback));
|
|
110
79
|
}
|
|
111
80
|
|
|
112
81
|
/**
|
|
113
|
-
* Bind to
|
|
82
|
+
* Bind to puppeteer's '*' event that fires for *any* protocol event,
|
|
83
|
+
* and wrap it with data about the protocol message instead of just the event.
|
|
114
84
|
* @param {(payload: LH.Protocol.RawEventMessage) => void} callback
|
|
115
85
|
*/
|
|
116
86
|
addProtocolMessageListener(callback) {
|
|
117
|
-
|
|
87
|
+
/**
|
|
88
|
+
* @param {any} method
|
|
89
|
+
* @param {any} event
|
|
90
|
+
*/
|
|
91
|
+
const listener = (method, event) => callback({
|
|
92
|
+
method,
|
|
93
|
+
params: event,
|
|
94
|
+
sessionId: this.sessionId(),
|
|
95
|
+
});
|
|
96
|
+
this._callbackMap.set(callback, listener);
|
|
97
|
+
this._cdpSession.on('*', /** @type {*} */ (listener));
|
|
118
98
|
}
|
|
119
99
|
|
|
120
100
|
/**
|
|
121
|
-
* Unbind to our custom event that fires for *any* protocol event.
|
|
122
101
|
* @param {(payload: LH.Protocol.RawEventMessage) => void} callback
|
|
123
102
|
*/
|
|
124
103
|
removeProtocolMessageListener(callback) {
|
|
125
|
-
this.
|
|
104
|
+
const listener = this._callbackMap.get(callback);
|
|
105
|
+
if (!listener) return;
|
|
106
|
+
this._cdpSession.off('*', /** @type {*} */ (listener));
|
|
126
107
|
}
|
|
127
108
|
|
|
128
109
|
/**
|
|
@@ -132,7 +113,7 @@ class ProtocolSession {
|
|
|
132
113
|
* @param {(...args: LH.CrdpEvents[E]) => void} callback
|
|
133
114
|
*/
|
|
134
115
|
off(eventName, callback) {
|
|
135
|
-
this.
|
|
116
|
+
this._cdpSession.off(eventName, /** @type {*} */ (callback));
|
|
136
117
|
}
|
|
137
118
|
|
|
138
119
|
/**
|
|
@@ -155,7 +136,7 @@ class ProtocolSession {
|
|
|
155
136
|
}));
|
|
156
137
|
});
|
|
157
138
|
|
|
158
|
-
const resultPromise = this.
|
|
139
|
+
const resultPromise = this._cdpSession.send(method, ...params);
|
|
159
140
|
const resultWithTimeoutPromise = Promise.race([resultPromise, timeoutPromise]);
|
|
160
141
|
|
|
161
142
|
return resultWithTimeoutPromise.finally(() => {
|
|
@@ -168,14 +149,8 @@ class ProtocolSession {
|
|
|
168
149
|
* @return {Promise<void>}
|
|
169
150
|
*/
|
|
170
151
|
async dispose() {
|
|
171
|
-
this.
|
|
172
|
-
await this.
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
_getConnection() {
|
|
176
|
-
const connection = this._session.connection();
|
|
177
|
-
if (!connection) throw new Error('Connection has been closed.');
|
|
178
|
-
return connection;
|
|
152
|
+
this._cdpSession.removeAllListeners();
|
|
153
|
+
await this._cdpSession.detach();
|
|
179
154
|
}
|
|
180
155
|
}
|
|
181
156
|
|
|
@@ -82,7 +82,8 @@ class CriConnection extends Connection {
|
|
|
82
82
|
*/
|
|
83
83
|
_runJsonCommand(command) {
|
|
84
84
|
return new Promise((resolve, reject) => {
|
|
85
|
-
const request = http.
|
|
85
|
+
const request = http.request({
|
|
86
|
+
method: 'PUT', // GET and POST are deprecated: https://crrev.com/c/3595822
|
|
86
87
|
hostname: this.hostname,
|
|
87
88
|
port: this.port,
|
|
88
89
|
path: '/json/' + command,
|
|
@@ -109,6 +110,8 @@ class CriConnection extends Connection {
|
|
|
109
110
|
});
|
|
110
111
|
});
|
|
111
112
|
|
|
113
|
+
request.end();
|
|
114
|
+
|
|
112
115
|
// This error handler is critical to ensuring Lighthouse exits cleanly even when Chrome crashes.
|
|
113
116
|
// See https://github.com/GoogleChrome/lighthouse/pull/8583.
|
|
114
117
|
request.on('error', reject);
|
|
@@ -90,7 +90,10 @@ class NetworkMonitor {
|
|
|
90
90
|
this._frameNavigations = [];
|
|
91
91
|
this._sessions = new Map();
|
|
92
92
|
this._networkRecorder = new NetworkRecorder();
|
|
93
|
-
|
|
93
|
+
/** @type {LH.Puppeteer.CDPSession} */
|
|
94
|
+
// @ts-expect-error - temporarily reach in to get CDPSession
|
|
95
|
+
const rootCdpSession = this._session._cdpSession;
|
|
96
|
+
this._targetManager = new TargetManager(rootCdpSession);
|
|
94
97
|
|
|
95
98
|
/**
|
|
96
99
|
* Reemit the same network recorder events.
|
|
@@ -103,13 +106,20 @@ class NetworkMonitor {
|
|
|
103
106
|
};
|
|
104
107
|
|
|
105
108
|
this._networkRecorder.on('requeststarted', reEmit('requeststarted'));
|
|
106
|
-
this._networkRecorder.on('
|
|
109
|
+
this._networkRecorder.on('requestfinished', reEmit('requestfinished'));
|
|
107
110
|
|
|
108
111
|
this._session.on('Page.frameNavigated', this._onFrameNavigated);
|
|
109
|
-
this._targetManager.addTargetAttachedListener(this._onTargetAttached);
|
|
110
|
-
|
|
111
112
|
await this._session.sendCommand('Page.enable');
|
|
112
|
-
|
|
113
|
+
|
|
114
|
+
// Legacy driver does its own target management.
|
|
115
|
+
// @ts-expect-error
|
|
116
|
+
const isLegacyRunner = Boolean(this._session._domainEnabledCounts);
|
|
117
|
+
if (isLegacyRunner) {
|
|
118
|
+
this._session.addProtocolMessageListener(this._onProtocolMessage);
|
|
119
|
+
} else {
|
|
120
|
+
this._targetManager.addTargetAttachedListener(this._onTargetAttached);
|
|
121
|
+
await this._targetManager.enable();
|
|
122
|
+
}
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
/**
|
|
@@ -119,13 +129,21 @@ class NetworkMonitor {
|
|
|
119
129
|
if (!this._targetManager) return;
|
|
120
130
|
|
|
121
131
|
this._session.off('Page.frameNavigated', this._onFrameNavigated);
|
|
122
|
-
this._targetManager.removeTargetAttachedListener(this._onTargetAttached);
|
|
123
132
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
133
|
+
// Legacy driver does its own target management.
|
|
134
|
+
// @ts-expect-error
|
|
135
|
+
const isLegacyRunner = Boolean(this._session._domainEnabledCounts);
|
|
136
|
+
if (isLegacyRunner) {
|
|
137
|
+
this._session.removeProtocolMessageListener(this._onProtocolMessage);
|
|
138
|
+
} else {
|
|
139
|
+
this._targetManager.removeTargetAttachedListener(this._onTargetAttached);
|
|
127
140
|
|
|
128
|
-
|
|
141
|
+
for (const session of this._sessions.values()) {
|
|
142
|
+
session.removeProtocolMessageListener(this._onProtocolMessage);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
await this._targetManager.disable();
|
|
146
|
+
}
|
|
129
147
|
|
|
130
148
|
this._frameNavigations = [];
|
|
131
149
|
this._networkRecorder = undefined;
|
|
@@ -11,21 +11,23 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
const log = require('lighthouse-logger');
|
|
14
|
+
const ProtocolSession = require('../../fraggle-rock/gather/session.js');
|
|
14
15
|
|
|
15
16
|
/** @typedef {{target: LH.Crdp.Target.TargetInfo, session: LH.Gatherer.FRProtocolSession}} TargetWithSession */
|
|
16
17
|
|
|
17
18
|
class TargetManager {
|
|
18
|
-
/** @param {LH.
|
|
19
|
-
constructor(
|
|
19
|
+
/** @param {LH.Puppeteer.CDPSession} cdpSession */
|
|
20
|
+
constructor(cdpSession) {
|
|
20
21
|
this._enabled = false;
|
|
21
|
-
this.
|
|
22
|
+
this._rootCdpSession = cdpSession;
|
|
23
|
+
|
|
22
24
|
/** @type {Array<(targetWithSession: TargetWithSession) => Promise<void>|void>} */
|
|
23
25
|
this._listeners = [];
|
|
24
26
|
|
|
25
27
|
this._onSessionAttached = this._onSessionAttached.bind(this);
|
|
26
28
|
|
|
27
29
|
/** @type {Map<string, TargetWithSession>} */
|
|
28
|
-
this.
|
|
30
|
+
this._targetIdToTargets = new Map();
|
|
29
31
|
|
|
30
32
|
/** @param {LH.Crdp.Page.FrameNavigatedEvent} event */
|
|
31
33
|
this._onFrameNavigated = async event => {
|
|
@@ -35,7 +37,7 @@ class TargetManager {
|
|
|
35
37
|
// It's not entirely clear when this is necessary, but when the page switches processes on
|
|
36
38
|
// navigating from about:blank to the `requestedUrl`, resetting `setAutoAttach` has been
|
|
37
39
|
// necessary in the past.
|
|
38
|
-
await this.
|
|
40
|
+
await this._rootCdpSession.send('Target.setAutoAttach', {
|
|
39
41
|
autoAttach: true,
|
|
40
42
|
flatten: true,
|
|
41
43
|
waitForDebuggerOnStart: true,
|
|
@@ -44,9 +46,11 @@ class TargetManager {
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
|
-
* @param {LH.
|
|
49
|
+
* @param {LH.Puppeteer.CDPSession} cdpSession
|
|
48
50
|
*/
|
|
49
|
-
async _onSessionAttached(
|
|
51
|
+
async _onSessionAttached(cdpSession) {
|
|
52
|
+
const session = new ProtocolSession(cdpSession);
|
|
53
|
+
|
|
50
54
|
try {
|
|
51
55
|
const target = await session.sendCommand('Target.getTargetInfo').catch(() => null);
|
|
52
56
|
const targetType = target?.targetInfo?.type;
|
|
@@ -55,13 +59,13 @@ class TargetManager {
|
|
|
55
59
|
|
|
56
60
|
const targetId = target.targetInfo.targetId;
|
|
57
61
|
session.setTargetInfo(target.targetInfo);
|
|
58
|
-
if (this.
|
|
62
|
+
if (this._targetIdToTargets.has(targetId)) return;
|
|
59
63
|
|
|
60
64
|
const targetName = target.targetInfo.url || target.targetInfo.targetId;
|
|
61
65
|
log.verbose('target-manager', `target ${targetName} attached`);
|
|
62
66
|
|
|
63
67
|
const targetWithSession = {target: target.targetInfo, session};
|
|
64
|
-
this.
|
|
68
|
+
this._targetIdToTargets.set(targetId, targetWithSession);
|
|
65
69
|
for (const listener of this._listeners) await listener(targetWithSession);
|
|
66
70
|
|
|
67
71
|
await session.sendCommand('Target.setAutoAttach', {
|
|
@@ -87,24 +91,32 @@ class TargetManager {
|
|
|
87
91
|
if (this._enabled) return;
|
|
88
92
|
|
|
89
93
|
this._enabled = true;
|
|
90
|
-
this.
|
|
94
|
+
this._targetIdToTargets = new Map();
|
|
95
|
+
|
|
96
|
+
this._rootCdpSession.on('Page.frameNavigated', this._onFrameNavigated);
|
|
97
|
+
|
|
98
|
+
const rootConnection = this._rootCdpSession.connection();
|
|
99
|
+
if (!rootConnection) {
|
|
100
|
+
throw new Error('Connection has been closed.');
|
|
101
|
+
}
|
|
102
|
+
rootConnection.on('sessionattached', this._onSessionAttached);
|
|
91
103
|
|
|
92
|
-
this.
|
|
93
|
-
this._session.addSessionAttachedListener(this._onSessionAttached);
|
|
104
|
+
await this._rootCdpSession.send('Page.enable');
|
|
94
105
|
|
|
95
|
-
|
|
96
|
-
await this._onSessionAttached(this.
|
|
106
|
+
// Start with the already attached root session.
|
|
107
|
+
await this._onSessionAttached(this._rootCdpSession);
|
|
97
108
|
}
|
|
98
109
|
|
|
99
110
|
/**
|
|
100
111
|
* @return {Promise<void>}
|
|
101
112
|
*/
|
|
102
113
|
async disable() {
|
|
103
|
-
this.
|
|
104
|
-
|
|
114
|
+
this._rootCdpSession.off('Page.frameNavigated', this._onFrameNavigated);
|
|
115
|
+
// No need to remove listener if connection is already closed.
|
|
116
|
+
this._rootCdpSession.connection()?.off('sessionattached', this._onSessionAttached);
|
|
105
117
|
|
|
106
118
|
this._enabled = false;
|
|
107
|
-
this.
|
|
119
|
+
this._targetIdToTargets = new Map();
|
|
108
120
|
}
|
|
109
121
|
|
|
110
122
|
/**
|
|
@@ -164,7 +164,8 @@ function waitForNetworkIdle(session, networkMonitor, networkQuietOptions) {
|
|
|
164
164
|
const inflightRecords = networkMonitor.getInflightRequests();
|
|
165
165
|
// If there are more than 20 inflight requests, load is still in full swing.
|
|
166
166
|
// Wait until it calms down a bit to be a little less spammy.
|
|
167
|
-
if (inflightRecords.length < 20) {
|
|
167
|
+
if (log.isVerbose() && inflightRecords.length < 20 && inflightRecords.length > 0) {
|
|
168
|
+
log.verbose('waitFor', `=== Waiting on ${inflightRecords.length} requests to finish`);
|
|
168
169
|
for (const record of inflightRecords) {
|
|
169
170
|
log.verbose('waitFor', `Waiting on ${record.url.slice(0, 120)} to finish`);
|
|
170
171
|
}
|
|
@@ -172,7 +173,7 @@ function waitForNetworkIdle(session, networkMonitor, networkQuietOptions) {
|
|
|
172
173
|
};
|
|
173
174
|
|
|
174
175
|
networkMonitor.on('requeststarted', logStatus);
|
|
175
|
-
networkMonitor.on('
|
|
176
|
+
networkMonitor.on('requestfinished', logStatus);
|
|
176
177
|
networkMonitor.on(busyEvent, logStatus);
|
|
177
178
|
|
|
178
179
|
if (!networkQuietOptions.pretendDCLAlreadyFired) {
|
|
@@ -192,7 +193,7 @@ function waitForNetworkIdle(session, networkMonitor, networkQuietOptions) {
|
|
|
192
193
|
networkMonitor.removeListener(busyEvent, onBusy);
|
|
193
194
|
networkMonitor.removeListener(idleEvent, onIdle);
|
|
194
195
|
networkMonitor.removeListener('requeststarted', logStatus);
|
|
195
|
-
networkMonitor.removeListener('
|
|
196
|
+
networkMonitor.removeListener('requestfinished', logStatus);
|
|
196
197
|
networkMonitor.removeListener(busyEvent, logStatus);
|
|
197
198
|
};
|
|
198
199
|
});
|
|
@@ -12,7 +12,7 @@ const {fetchResponseBodyFromCache} = require('../gather/driver/network.js');
|
|
|
12
12
|
const EventEmitter = require('events').EventEmitter;
|
|
13
13
|
|
|
14
14
|
const log = require('lighthouse-logger');
|
|
15
|
-
const
|
|
15
|
+
const DevtoolsMessageLog = require('./gatherers/devtools-log.js').DevtoolsMessageLog;
|
|
16
16
|
const TraceGatherer = require('./gatherers/trace.js');
|
|
17
17
|
|
|
18
18
|
// Pulled in for Connection type checking.
|
|
@@ -41,7 +41,7 @@ class Driver {
|
|
|
41
41
|
* @private
|
|
42
42
|
* Used to save network and lifecycle protocol traffic. Just Page and Network are needed.
|
|
43
43
|
*/
|
|
44
|
-
_devtoolsLog = new
|
|
44
|
+
_devtoolsLog = new DevtoolsMessageLog(/^(Page|Network)\./);
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* @private
|
|
@@ -208,16 +208,6 @@ class Driver {
|
|
|
208
208
|
// OOPIF handling in legacy driver is implicit.
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
/** @param {(session: LH.Gatherer.FRProtocolSession) => void} callback */
|
|
212
|
-
addSessionAttachedListener(callback) { // eslint-disable-line no-unused-vars
|
|
213
|
-
// OOPIF handling in legacy driver is implicit.
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/** @param {(session: LH.Gatherer.FRProtocolSession) => void} callback */
|
|
217
|
-
removeSessionAttachedListener(callback) { // eslint-disable-line no-unused-vars
|
|
218
|
-
// OOPIF handling in legacy driver is implicit.
|
|
219
|
-
}
|
|
220
|
-
|
|
221
211
|
/**
|
|
222
212
|
* Debounce enabling or disabling domains to prevent driver users from
|
|
223
213
|
* stomping on each other. Maintains an internal count of the times a domain
|
|
@@ -20,6 +20,7 @@ const WebAppManifest = require('./gatherers/web-app-manifest.js');
|
|
|
20
20
|
const InstallabilityErrors = require('./gatherers/installability-errors.js');
|
|
21
21
|
const NetworkUserAgent = require('./gatherers/network-user-agent.js');
|
|
22
22
|
const Stacks = require('./gatherers/stacks.js');
|
|
23
|
+
const URL = require('../lib/url-shim.js');
|
|
23
24
|
const {finalizeArtifacts} = require('../fraggle-rock/gather/base-artifacts.js');
|
|
24
25
|
|
|
25
26
|
/** @typedef {import('../gather/driver.js')} Driver */
|
|
@@ -491,6 +492,20 @@ class GatherRunner {
|
|
|
491
492
|
const baseArtifacts = await GatherRunner.initializeBaseArtifacts(options);
|
|
492
493
|
baseArtifacts.BenchmarkIndex = await getBenchmarkIndex(driver.executionContext);
|
|
493
494
|
|
|
495
|
+
// Hack for running benchmarkIndex extra times.
|
|
496
|
+
// Add a `bidx=20` query param, eg: https://www.example.com/?bidx=50
|
|
497
|
+
const parsedUrl = URL.isValid(options.requestedUrl) && new URL(options.requestedUrl);
|
|
498
|
+
if (options.settings.channel === 'lr' && parsedUrl && parsedUrl.searchParams.has('bidx')) {
|
|
499
|
+
const bidxRunCount = parsedUrl.searchParams.get('bidx') || 0;
|
|
500
|
+
// Add the first bidx into the new set
|
|
501
|
+
const indexes = [baseArtifacts.BenchmarkIndex];
|
|
502
|
+
for (let i = 0; i < bidxRunCount; i++) {
|
|
503
|
+
const bidx = await getBenchmarkIndex(driver.executionContext);
|
|
504
|
+
indexes.push(bidx);
|
|
505
|
+
}
|
|
506
|
+
baseArtifacts.BenchmarkIndexes = indexes;
|
|
507
|
+
}
|
|
508
|
+
|
|
494
509
|
await GatherRunner.setupDriver(driver, options);
|
|
495
510
|
|
|
496
511
|
let isFirstPass = true;
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
const NetworkMonitor = require('../driver/network-monitor.js');
|
|
15
|
-
const MessageLog = require('../devtools-log.js');
|
|
16
15
|
const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js');
|
|
17
16
|
|
|
18
17
|
class DevtoolsLog extends FRGatherer {
|
|
@@ -30,7 +29,7 @@ class DevtoolsLog extends FRGatherer {
|
|
|
30
29
|
/** @type {NetworkMonitor|undefined} */
|
|
31
30
|
this._networkMonitor = undefined;
|
|
32
31
|
|
|
33
|
-
this._messageLog = new
|
|
32
|
+
this._messageLog = new DevtoolsMessageLog(/^(Page|Network|Target|Runtime)\./);
|
|
34
33
|
|
|
35
34
|
/** @param {LH.Protocol.RawEventMessage} e */
|
|
36
35
|
this._onProtocolMessage = e => this._messageLog.record(e);
|
|
@@ -63,4 +62,59 @@ class DevtoolsLog extends FRGatherer {
|
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* This class saves all protocol messages whose method match a particular
|
|
68
|
+
* regex filter. Used when saving assets for later analysis by another tool such as
|
|
69
|
+
* Webpagetest.
|
|
70
|
+
*/
|
|
71
|
+
class DevtoolsMessageLog {
|
|
72
|
+
/**
|
|
73
|
+
* @param {RegExp=} regexFilter
|
|
74
|
+
*/
|
|
75
|
+
constructor(regexFilter) {
|
|
76
|
+
this._filter = regexFilter;
|
|
77
|
+
|
|
78
|
+
/** @type {LH.DevtoolsLog} */
|
|
79
|
+
this._messages = [];
|
|
80
|
+
this._isRecording = false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @return {LH.DevtoolsLog}
|
|
85
|
+
*/
|
|
86
|
+
get messages() {
|
|
87
|
+
return this._messages;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
reset() {
|
|
91
|
+
this._messages = [];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
beginRecording() {
|
|
95
|
+
this._isRecording = true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
endRecording() {
|
|
99
|
+
this._isRecording = false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Records a message if method matches filter and recording has been started.
|
|
104
|
+
* @param {LH.Protocol.RawEventMessage} message
|
|
105
|
+
*/
|
|
106
|
+
record(message) {
|
|
107
|
+
// We're not recording, skip the rest of the checks.
|
|
108
|
+
if (!this._isRecording) return;
|
|
109
|
+
// The event was likely an internal puppeteer method that uses Symbols.
|
|
110
|
+
if (typeof message.method !== 'string') return;
|
|
111
|
+
// The event didn't pass our filter, do not record it.
|
|
112
|
+
if (this._filter && !this._filter.test(message.method)) return;
|
|
113
|
+
|
|
114
|
+
// We passed all the checks, record the message.
|
|
115
|
+
this._messages.push(message);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
66
119
|
module.exports = DevtoolsLog;
|
|
120
|
+
module.exports.DevtoolsMessageLog = DevtoolsMessageLog;
|
|
@@ -9,7 +9,7 @@ const log = require('lighthouse-logger');
|
|
|
9
9
|
const NetworkRequest = require('./network-request.js');
|
|
10
10
|
const EventEmitter = require('events').EventEmitter;
|
|
11
11
|
|
|
12
|
-
/** @typedef {'requeststarted'|'
|
|
12
|
+
/** @typedef {'requeststarted'|'requestfinished'} NetworkRecorderEvent */
|
|
13
13
|
|
|
14
14
|
class NetworkRecorder extends EventEmitter {
|
|
15
15
|
/**
|
|
@@ -71,7 +71,7 @@ class NetworkRecorder extends EventEmitter {
|
|
|
71
71
|
* @private
|
|
72
72
|
*/
|
|
73
73
|
onRequestFinished(request) {
|
|
74
|
-
this.emit('
|
|
74
|
+
this.emit('requestfinished', request);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
// The below methods proxy network data into the NetworkRequest object which mimics the
|