lighthouse 10.4.0-dev.20230719 → 10.4.0-dev.20230720
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/cli/test/smokehouse/lighthouse-runners/bundle.js +1 -1
- package/cli/test/smokehouse/lighthouse-runners/cli.d.ts +0 -1
- package/cli/test/smokehouse/report-assert.d.ts +0 -1
- package/core/config/constants.js +1 -1
- package/core/gather/driver/execution-context.js +12 -5
- package/core/gather/gatherers/trace-elements.js +7 -3
- package/core/lib/page-functions.d.ts +10 -4
- package/core/lib/page-functions.js +78 -10
- package/package.json +3 -3
- package/readme.md +2 -0
- package/types/internal/lighthouse-logger.d.ts +0 -34
|
@@ -17,7 +17,7 @@ import {Worker, isMainThread, parentPort, workerData} from 'worker_threads';
|
|
|
17
17
|
import {once} from 'events';
|
|
18
18
|
|
|
19
19
|
import puppeteer from 'puppeteer-core';
|
|
20
|
-
import ChromeLauncher from 'chrome-launcher';
|
|
20
|
+
import * as ChromeLauncher from 'chrome-launcher';
|
|
21
21
|
|
|
22
22
|
import {LH_ROOT} from '../../../../root.js';
|
|
23
23
|
import {loadArtifacts, saveArtifacts} from '../../../../core/lib/asset-saver.js';
|
package/core/config/constants.js
CHANGED
|
@@ -17,7 +17,7 @@ const throttling = {
|
|
|
17
17
|
DEVTOOLS_RTT_ADJUSTMENT_FACTOR,
|
|
18
18
|
DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
|
|
19
19
|
// These values align with WebPageTest's definition of "Fast 3G"
|
|
20
|
-
// But offer similar
|
|
20
|
+
// But offer similar characteristics to roughly the 75th percentile of 4G connections.
|
|
21
21
|
mobileSlow4G: {
|
|
22
22
|
rttMs: 150,
|
|
23
23
|
throughputKbps: 1.6 * 1024,
|
|
@@ -108,7 +108,7 @@ class ExecutionContext {
|
|
|
108
108
|
${ExecutionContext._cachedNativesPreamble};
|
|
109
109
|
globalThis.__lighthouseExecutionContextUniqueIdentifier =
|
|
110
110
|
${uniqueExecutionContextIdentifier};
|
|
111
|
-
${pageFunctions.
|
|
111
|
+
${pageFunctions.esbuildFunctionWrapperString}
|
|
112
112
|
return new Promise(function (resolve) {
|
|
113
113
|
return Promise.resolve()
|
|
114
114
|
.then(_ => ${expression})
|
|
@@ -277,13 +277,20 @@ class ExecutionContext {
|
|
|
277
277
|
* @return {string}
|
|
278
278
|
*/
|
|
279
279
|
static serializeDeps(deps) {
|
|
280
|
-
deps = [pageFunctions.
|
|
280
|
+
deps = [pageFunctions.esbuildFunctionWrapperString, ...deps || []];
|
|
281
281
|
return deps.map(dep => {
|
|
282
282
|
if (typeof dep === 'function') {
|
|
283
283
|
// esbuild will change the actual function name (ie. function actualName() {})
|
|
284
|
-
// always,
|
|
285
|
-
//
|
|
286
|
-
|
|
284
|
+
// always, and preserve the real name in `actualName.name`.
|
|
285
|
+
// See esbuildFunctionWrapperString.
|
|
286
|
+
const output = dep.toString();
|
|
287
|
+
const runtimeName = pageFunctions.getRuntimeFunctionName(dep);
|
|
288
|
+
if (runtimeName !== dep.name) {
|
|
289
|
+
// In addition to exposing the mangled name, also expose the original as an alias.
|
|
290
|
+
return `${output}; const ${dep.name} = ${runtimeName};`;
|
|
291
|
+
} else {
|
|
292
|
+
return output;
|
|
293
|
+
}
|
|
287
294
|
} else {
|
|
288
295
|
return dep;
|
|
289
296
|
}
|
|
@@ -23,6 +23,7 @@ import {ProcessedNavigation} from '../../computed/processed-navigation.js';
|
|
|
23
23
|
import {LighthouseError} from '../../lib/lh-error.js';
|
|
24
24
|
import {Responsiveness} from '../../computed/metrics/responsiveness.js';
|
|
25
25
|
import {CumulativeLayoutShift} from '../../computed/metrics/cumulative-layout-shift.js';
|
|
26
|
+
import {ExecutionContext} from '../driver/execution-context.js';
|
|
26
27
|
|
|
27
28
|
/** @typedef {{nodeId: number, score?: number, animations?: {name?: string, failureReasonsMask?: number, unsupportedProperties?: string[]}[], type?: string}} TraceElementData */
|
|
28
29
|
|
|
@@ -284,12 +285,15 @@ class TraceElements extends BaseGatherer {
|
|
|
284
285
|
try {
|
|
285
286
|
const objectId = await resolveNodeIdToObjectId(session, backendNodeId);
|
|
286
287
|
if (!objectId) continue;
|
|
288
|
+
|
|
289
|
+
const deps = ExecutionContext.serializeDeps([
|
|
290
|
+
pageFunctions.getNodeDetails,
|
|
291
|
+
getNodeDetailsData,
|
|
292
|
+
]);
|
|
287
293
|
response = await session.sendCommand('Runtime.callFunctionOn', {
|
|
288
294
|
objectId,
|
|
289
295
|
functionDeclaration: `function () {
|
|
290
|
-
${
|
|
291
|
-
${getNodeDetailsData.toString()};
|
|
292
|
-
${pageFunctions.getNodeDetails};
|
|
296
|
+
${deps}
|
|
293
297
|
return getNodeDetailsData.call(this);
|
|
294
298
|
}`,
|
|
295
299
|
returnByValue: true,
|
|
@@ -11,7 +11,8 @@ export namespace pageFunctions {
|
|
|
11
11
|
export { wrapRequestIdleCallback };
|
|
12
12
|
export { getBoundingClientRect };
|
|
13
13
|
export { truncate };
|
|
14
|
-
export {
|
|
14
|
+
export { esbuildFunctionWrapperString };
|
|
15
|
+
export { getRuntimeFunctionName };
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* `typed-query-selector`'s CSS selector parser.
|
|
@@ -50,11 +51,11 @@ declare function wrapRuntimeEvalErrorInBrowser(err?: string | Error | undefined)
|
|
|
50
51
|
};
|
|
51
52
|
/**
|
|
52
53
|
* @template {string} T
|
|
53
|
-
* @param {T} selector Optional simple CSS selector to filter nodes on.
|
|
54
|
+
* @param {T=} selector Optional simple CSS selector to filter nodes on.
|
|
54
55
|
* Combinators are not supported.
|
|
55
56
|
* @return {Array<ParseSelector<T>>}
|
|
56
57
|
*/
|
|
57
|
-
declare function getElementsInDocument<T extends string>(selector
|
|
58
|
+
declare function getElementsInDocument<T extends string>(selector?: T | undefined): import("typed-query-selector/parser").ParseSelector<T, Element>[];
|
|
58
59
|
/**
|
|
59
60
|
* Gets the opening tag text of the given node.
|
|
60
61
|
* @param {Element|ShadowRoot} element
|
|
@@ -158,6 +159,11 @@ declare function truncate(string: string, characterLimit: number): string;
|
|
|
158
159
|
declare namespace truncate {
|
|
159
160
|
function toString(): string;
|
|
160
161
|
}
|
|
161
|
-
declare const
|
|
162
|
+
declare const esbuildFunctionWrapperString: string;
|
|
163
|
+
/**
|
|
164
|
+
* @param {Function} fn
|
|
165
|
+
* @return {string}
|
|
166
|
+
*/
|
|
167
|
+
declare function getRuntimeFunctionName(fn: Function): string;
|
|
162
168
|
export {};
|
|
163
169
|
//# sourceMappingURL=page-functions.d.ts.map
|
|
@@ -4,6 +4,8 @@
|
|
|
4
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
5
|
*/
|
|
6
6
|
|
|
7
|
+
import {createRequire} from 'module';
|
|
8
|
+
|
|
7
9
|
import {Util} from '../../shared/util.js';
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -50,7 +52,7 @@ function wrapRuntimeEvalErrorInBrowser(err) {
|
|
|
50
52
|
|
|
51
53
|
/**
|
|
52
54
|
* @template {string} T
|
|
53
|
-
* @param {T} selector Optional simple CSS selector to filter nodes on.
|
|
55
|
+
* @param {T=} selector Optional simple CSS selector to filter nodes on.
|
|
54
56
|
* Combinators are not supported.
|
|
55
57
|
* @return {Array<ParseSelector<T>>}
|
|
56
58
|
*/
|
|
@@ -513,24 +515,89 @@ function truncate(string, characterLimit) {
|
|
|
513
515
|
return Util.truncate(string, characterLimit);
|
|
514
516
|
}
|
|
515
517
|
|
|
518
|
+
function isBundledEnvironment() {
|
|
519
|
+
// If we're in DevTools or LightRider, we are definitely bundled.
|
|
520
|
+
// TODO: refactor and delete `global.isDevtools`.
|
|
521
|
+
if (global.isDevtools || global.isLightrider) return true;
|
|
522
|
+
|
|
523
|
+
const require = createRequire(import.meta.url);
|
|
524
|
+
|
|
525
|
+
try {
|
|
526
|
+
// Not foolproof, but `lighthouse-logger` is a dependency of lighthouse that should always be resolvable.
|
|
527
|
+
// `require.resolve` will only throw in atypical/bundled environments.
|
|
528
|
+
require.resolve('lighthouse-logger');
|
|
529
|
+
return false;
|
|
530
|
+
} catch (err) {
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
516
535
|
// This is to support bundled lighthouse.
|
|
517
536
|
// esbuild calls every function with a builtin `__name` (since we set keepNames: true),
|
|
518
537
|
// whose purpose is to store the real name of the function so that esbuild can rename it to avoid
|
|
519
538
|
// collisions. Anywhere we inject dynamically generated code at runtime for the browser to process,
|
|
520
539
|
// we must manually include this function (because esbuild only does so once at the top scope of
|
|
521
540
|
// the bundle, which is irrelevant for code executed in the browser).
|
|
522
|
-
|
|
541
|
+
// When minified, esbuild will mangle the name of this wrapper function, so we need to determine what it
|
|
542
|
+
// is at runtime in order to recreate it within the page.
|
|
543
|
+
const esbuildFunctionWrapperString = createEsbuildFunctionWrapper();
|
|
523
544
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
545
|
+
function createEsbuildFunctionWrapper() {
|
|
546
|
+
if (!isBundledEnvironment()) {
|
|
547
|
+
return '';
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const functionAsString = (()=>{
|
|
551
|
+
// eslint-disable-next-line no-unused-vars
|
|
552
|
+
const a = ()=>{};
|
|
553
|
+
}).toString()
|
|
554
|
+
// When not minified, esbuild annotates the call to this function wrapper with PURE.
|
|
555
|
+
// We know further that the name of the wrapper function should be `__name`, but let's not
|
|
556
|
+
// hardcode that. Remove the PURE annotation to simplify the regex.
|
|
557
|
+
.replace('/* @__PURE__ */', '');
|
|
558
|
+
const functionStringMatch = functionAsString.match(/=\s*([\w_]+)\(/);
|
|
559
|
+
if (!functionStringMatch) {
|
|
560
|
+
throw new Error('Could not determine esbuild function wrapper name');
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* @param {Function} fn
|
|
565
|
+
* @param {string} value
|
|
566
|
+
*/
|
|
567
|
+
const esbuildFunctionWrapper = (fn, value) =>
|
|
568
|
+
Object.defineProperty(fn, 'name', {value, configurable: true});
|
|
569
|
+
const wrapperFnName = functionStringMatch[1];
|
|
570
|
+
return `let ${wrapperFnName}=${esbuildFunctionWrapper}`;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* @param {Function} fn
|
|
575
|
+
* @return {string}
|
|
576
|
+
*/
|
|
577
|
+
function getRuntimeFunctionName(fn) {
|
|
578
|
+
const match = fn.toString().match(/function ([\w$]+)/);
|
|
579
|
+
if (!match) throw new Error(`could not find function name for: ${fn}`);
|
|
580
|
+
return match[1];
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// We setup a number of our page functions to automatically include their dependencies.
|
|
584
|
+
// Because of esbuild bundling, we must refer to the actual (mangled) runtime function name.
|
|
585
|
+
/** @type {Record<string, string>} */
|
|
586
|
+
const names = {
|
|
587
|
+
truncate: getRuntimeFunctionName(truncate),
|
|
588
|
+
getNodeLabel: getRuntimeFunctionName(getNodeLabel),
|
|
589
|
+
getOuterHTMLSnippet: getRuntimeFunctionName(getOuterHTMLSnippet),
|
|
590
|
+
getNodeDetails: getRuntimeFunctionName(getNodeDetails),
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
truncate.toString = () => `function ${names.truncate}(string, characterLimit) {
|
|
527
594
|
const Util = { ${Util.truncate} };
|
|
528
|
-
return (
|
|
595
|
+
return Util.truncate(string, characterLimit);
|
|
529
596
|
}`;
|
|
530
597
|
|
|
531
598
|
/** @type {string} */
|
|
532
599
|
const getNodeLabelRawString = getNodeLabel.toString();
|
|
533
|
-
getNodeLabel.toString = () => `function getNodeLabel(element) {
|
|
600
|
+
getNodeLabel.toString = () => `function ${names.getNodeLabel}(element) {
|
|
534
601
|
${truncate};
|
|
535
602
|
return (${getNodeLabelRawString})(element);
|
|
536
603
|
}`;
|
|
@@ -538,14 +605,14 @@ getNodeLabel.toString = () => `function getNodeLabel(element) {
|
|
|
538
605
|
/** @type {string} */
|
|
539
606
|
const getOuterHTMLSnippetRawString = getOuterHTMLSnippet.toString();
|
|
540
607
|
// eslint-disable-next-line max-len
|
|
541
|
-
getOuterHTMLSnippet.toString = () => `function getOuterHTMLSnippet(element, ignoreAttrs = [], snippetCharacterLimit = 500) {
|
|
608
|
+
getOuterHTMLSnippet.toString = () => `function ${names.getOuterHTMLSnippet}(element, ignoreAttrs = [], snippetCharacterLimit = 500) {
|
|
542
609
|
${truncate};
|
|
543
610
|
return (${getOuterHTMLSnippetRawString})(element, ignoreAttrs, snippetCharacterLimit);
|
|
544
611
|
}`;
|
|
545
612
|
|
|
546
613
|
/** @type {string} */
|
|
547
614
|
const getNodeDetailsRawString = getNodeDetails.toString();
|
|
548
|
-
getNodeDetails.toString = () => `function getNodeDetails(element) {
|
|
615
|
+
getNodeDetails.toString = () => `function ${names.getNodeDetails}(element) {
|
|
549
616
|
${truncate};
|
|
550
617
|
${getNodePath};
|
|
551
618
|
${getNodeSelector};
|
|
@@ -568,5 +635,6 @@ export const pageFunctions = {
|
|
|
568
635
|
wrapRequestIdleCallback,
|
|
569
636
|
getBoundingClientRect,
|
|
570
637
|
truncate,
|
|
571
|
-
|
|
638
|
+
esbuildFunctionWrapperString,
|
|
639
|
+
getRuntimeFunctionName,
|
|
572
640
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lighthouse",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "10.4.0-dev.
|
|
4
|
+
"version": "10.4.0-dev.20230720",
|
|
5
5
|
"description": "Automated auditing, performance metrics, and best practices for the web.",
|
|
6
6
|
"main": "./core/index.js",
|
|
7
7
|
"bin": {
|
|
@@ -181,7 +181,7 @@
|
|
|
181
181
|
"dependencies": {
|
|
182
182
|
"@sentry/node": "^6.17.4",
|
|
183
183
|
"axe-core": "4.7.2",
|
|
184
|
-
"chrome-launcher": "^0.
|
|
184
|
+
"chrome-launcher": "^1.0.0",
|
|
185
185
|
"configstore": "^5.0.1",
|
|
186
186
|
"csp_evaluator": "1.1.1",
|
|
187
187
|
"devtools-protocol": "0.0.1155343",
|
|
@@ -190,7 +190,7 @@
|
|
|
190
190
|
"intl-messageformat": "^4.4.0",
|
|
191
191
|
"jpeg-js": "^0.4.4",
|
|
192
192
|
"js-library-detector": "^6.6.0",
|
|
193
|
-
"lighthouse-logger": "^
|
|
193
|
+
"lighthouse-logger": "^2.0.1",
|
|
194
194
|
"lighthouse-stack-packs": "1.11.0",
|
|
195
195
|
"lodash": "^4.17.21",
|
|
196
196
|
"lookup-closest-locale": "6.2.0",
|
package/readme.md
CHANGED
|
@@ -337,6 +337,8 @@ This section details services that have integrated Lighthouse data. If you're wo
|
|
|
337
337
|
|
|
338
338
|
* **[Treo](https://treo.sh)** - Treo is Lighthouse as a Service. It provides regression testing, geographical regions, custom networks, and integrations with GitHub & Slack. Treo is a paid product with plans for solo-developers and teams.
|
|
339
339
|
|
|
340
|
+
* **[PageVitals](https://pagevitals.com)** - PageVitals combines Lighthouse, CrUX and real-user monitoring data to monitor the performance of websites. See how your website performs over time and get alerted if it gets too slow. Drill down and find the real cause of any performance issue. PageVitals is a paid product with a free 14-day trial.
|
|
341
|
+
|
|
340
342
|
* **[Alertdesk](https://www.alertdesk.com/)** - Alertdesk is based on Lighthouse and helps you to keep track of your site’s quality & performance. Run daily quality & performance tests from both Mobile and Desktop and dive into the powerful & intuitive reports. You can also monitor your uptime (every minute - 24/7) & domain health. Alertdesk is a paid product with a free 14-day trial.
|
|
341
343
|
|
|
342
344
|
* **[Screpy](https://screpy.com)** - Screpy is a web analysis tool that can analyze all pages of your websites in one dashboard and monitor them with your team. It's powered by Lighthouse and it also includes some different analysis tools (SERP, W3C, Uptime, etc). Screpy has free and paid plans.
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright 2017 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
|
-
|
|
7
|
-
declare module 'lighthouse-logger' {
|
|
8
|
-
interface Status {
|
|
9
|
-
msg: string;
|
|
10
|
-
id: string;
|
|
11
|
-
args?: any[];
|
|
12
|
-
}
|
|
13
|
-
export function setLevel(level: string): void;
|
|
14
|
-
export function isVerbose(): boolean;
|
|
15
|
-
export function formatProtocol(prefix: string, data: Object, level?: string): void;
|
|
16
|
-
export function log(title: string, ...args: any[]): void;
|
|
17
|
-
export function warn(title: string, ...args: any[]): void;
|
|
18
|
-
export function error(title: string, ...args: any[]): void;
|
|
19
|
-
export function verbose(title: string, ...args: any[]): void;
|
|
20
|
-
export function time(status: Status, level?: string): void;
|
|
21
|
-
export function timeEnd(status: Status, level?: string): void;
|
|
22
|
-
export function reset(): string;
|
|
23
|
-
export const cross: string;
|
|
24
|
-
export const dim: string;
|
|
25
|
-
export const tick: string;
|
|
26
|
-
export const bold: string;
|
|
27
|
-
export const purple: string;
|
|
28
|
-
export function redify(message: any): string;
|
|
29
|
-
export function greenify(message: any): string;
|
|
30
|
-
/** Retrieves and clears all stored time entries */
|
|
31
|
-
export function takeTimeEntries(): PerformanceEntry[];
|
|
32
|
-
export function getTimeEntries(): PerformanceEntry[];
|
|
33
|
-
export const events: import('events').EventEmitter;
|
|
34
|
-
}
|