lighthouse 9.5.0-dev.20220604 → 9.5.0-dev.20220607
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.
|
@@ -5757,6 +5757,30 @@ function renderReport(lhr, opts = {}) {
|
|
|
5757
5757
|
return rootEl;
|
|
5758
5758
|
}
|
|
5759
5759
|
|
|
5760
|
-
|
|
5760
|
+
/**
|
|
5761
|
+
* Returns a new LHR with all strings changed to the new requestedLocale.
|
|
5762
|
+
* @param {LH.Result} lhr
|
|
5763
|
+
* @param {LH.Locale} requestedLocale
|
|
5764
|
+
* @return {{lhr: LH.Result, missingIcuMessageIds: string[]}}
|
|
5765
|
+
*/
|
|
5766
|
+
function swapLocale(lhr, requestedLocale) {
|
|
5767
|
+
// Stub function only included for types
|
|
5768
|
+
return {
|
|
5769
|
+
lhr,
|
|
5770
|
+
missingIcuMessageIds: [],
|
|
5771
|
+
};
|
|
5772
|
+
}
|
|
5773
|
+
|
|
5774
|
+
/**
|
|
5775
|
+
* Populate the i18n string lookup dict with locale data
|
|
5776
|
+
* Used when the host environment selects the locale and serves lighthouse the intended locale file
|
|
5777
|
+
* @see https://docs.google.com/document/d/1jnt3BqKB-4q3AE94UWFA0Gqspx8Sd_jivlB7gQMlmfk/edit
|
|
5778
|
+
* @param {LH.Locale} locale
|
|
5779
|
+
* @param {Record<string, {message: string}>} lhlMessages
|
|
5780
|
+
*/
|
|
5781
|
+
function registerLocaleData(locale, lhlMessages) {
|
|
5782
|
+
// Stub function only included for types
|
|
5783
|
+
}
|
|
5784
|
+
const format = {registerLocaleData};
|
|
5761
5785
|
|
|
5762
5786
|
export { DOM, ReportRenderer, ReportUIFeatures, format, renderReport, swapLocale };
|
|
@@ -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;
|
|
@@ -24,22 +23,12 @@ class ProtocolSession {
|
|
|
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
|
-
if (originalEmit[SessionEmitMonkeypatch]) return;
|
|
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
|
+
this._targetInfo.targetId :
|
|
31
|
+
undefined;
|
|
43
32
|
}
|
|
44
33
|
|
|
45
34
|
/** @param {LH.Crdp.Target.TargetInfo} targetInfo */
|
|
@@ -110,19 +99,31 @@ class ProtocolSession {
|
|
|
110
99
|
}
|
|
111
100
|
|
|
112
101
|
/**
|
|
113
|
-
* Bind to
|
|
102
|
+
* Bind to puppeteer's '*' event that fires for *any* protocol event,
|
|
103
|
+
* and wrap it with data about the protocol message instead of just the event.
|
|
114
104
|
* @param {(payload: LH.Protocol.RawEventMessage) => void} callback
|
|
115
105
|
*/
|
|
116
106
|
addProtocolMessageListener(callback) {
|
|
117
|
-
|
|
107
|
+
/**
|
|
108
|
+
* @param {any} method
|
|
109
|
+
* @param {any} event
|
|
110
|
+
*/
|
|
111
|
+
const listener = (method, event) => callback({
|
|
112
|
+
method,
|
|
113
|
+
params: event,
|
|
114
|
+
sessionId: this.sessionId(),
|
|
115
|
+
});
|
|
116
|
+
this._callbackMap.set(callback, listener);
|
|
117
|
+
this._session.on('*', /** @type {*} */ (listener));
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
* Unbind to our custom event that fires for *any* protocol event.
|
|
122
121
|
* @param {(payload: LH.Protocol.RawEventMessage) => void} callback
|
|
123
122
|
*/
|
|
124
123
|
removeProtocolMessageListener(callback) {
|
|
125
|
-
this.
|
|
124
|
+
const listener = this._callbackMap.get(callback);
|
|
125
|
+
if (!listener) return;
|
|
126
|
+
this._session.off('*', /** @type {*} */ (listener));
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
/**
|
|
@@ -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);
|
package/package.json
CHANGED