lighthouse 10.4.0 → 11.0.0
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/CONTRIBUTING.md +1 -1
- package/cli/cli-flags.d.ts +1 -6
- package/cli/cli-flags.js +0 -5
- package/cli/run.js +3 -10
- package/cli/sentry-prompt.js +4 -2
- package/cli/test/smokehouse/core-tests.js +0 -2
- package/cli/test/smokehouse/frontends/smokehouse-bin.js +24 -14
- package/cli/test/smokehouse/lighthouse-runners/bundle.d.ts +1 -2
- package/cli/test/smokehouse/lighthouse-runners/bundle.js +12 -21
- package/cli/test/smokehouse/lighthouse-runners/cli.d.ts +1 -3
- package/cli/test/smokehouse/lighthouse-runners/cli.js +3 -7
- package/cli/test/smokehouse/lighthouse-runners/devtools.d.ts +1 -5
- package/cli/test/smokehouse/lighthouse-runners/devtools.js +1 -12
- package/cli/test/smokehouse/readme.md +0 -2
- package/cli/test/smokehouse/report-assert.d.ts +1 -3
- package/cli/test/smokehouse/report-assert.js +2 -19
- package/cli/test/smokehouse/smokehouse.js +3 -32
- package/core/audits/accessibility/aria-allowed-role.d.ts +10 -0
- package/core/audits/accessibility/aria-allowed-role.js +46 -0
- package/core/audits/accessibility/image-redundant-alt.d.ts +10 -0
- package/core/audits/accessibility/image-redundant-alt.js +45 -0
- package/core/audits/accessibility/label-content-name-mismatch.d.ts +10 -0
- package/core/audits/accessibility/label-content-name-mismatch.js +44 -0
- package/core/audits/accessibility/skip-link.d.ts +10 -0
- package/core/audits/accessibility/skip-link.js +43 -0
- package/core/audits/accessibility/table-duplicate-name.d.ts +10 -0
- package/core/audits/accessibility/table-duplicate-name.js +44 -0
- package/core/audits/accessibility/target-size.js +1 -1
- package/core/audits/byte-efficiency/duplicated-javascript.js +2 -2
- package/core/audits/byte-efficiency/render-blocking-resources.js +1 -0
- package/core/audits/dobetterweb/uses-http2.d.ts +18 -1
- package/core/audits/dobetterweb/uses-http2.js +62 -16
- package/core/audits/installable-manifest.d.ts +1 -5
- package/core/audits/installable-manifest.js +2 -7
- package/core/audits/largest-contentful-paint-element.d.ts +0 -6
- package/core/audits/largest-contentful-paint-element.js +13 -15
- package/core/audits/metrics/{experimental-interaction-to-next-paint.d.ts → interaction-to-next-paint.d.ts} +3 -3
- package/core/audits/metrics/{experimental-interaction-to-next-paint.js → interaction-to-next-paint.js} +3 -3
- package/core/audits/uses-rel-preconnect.js +23 -8
- package/core/audits/work-during-interaction.js +2 -2
- package/core/computed/processed-navigation.d.ts +1 -1
- package/core/config/config-helpers.d.ts +3 -3
- package/core/config/config-helpers.js +5 -12
- package/core/config/config.js +1 -7
- package/core/config/constants.d.ts +0 -2
- package/core/config/constants.js +2 -18
- package/core/config/default-config.js +59 -53
- package/core/config/filters.js +1 -1
- package/core/config/validation.d.ts +7 -12
- package/core/config/validation.js +16 -26
- package/core/gather/base-artifacts.d.ts +4 -4
- package/core/gather/base-artifacts.js +2 -6
- package/core/gather/base-gatherer.d.ts +12 -37
- package/core/gather/base-gatherer.js +7 -54
- package/core/gather/driver/dom.d.ts +4 -4
- package/core/gather/driver/dom.js +2 -2
- package/core/gather/driver/environment.d.ts +4 -4
- package/core/gather/driver/environment.js +2 -2
- package/core/gather/driver/execution-context.d.ts +12 -3
- package/core/gather/driver/execution-context.js +34 -3
- package/core/gather/driver/navigation.d.ts +2 -2
- package/core/gather/driver/navigation.js +2 -5
- package/core/gather/driver/network-monitor.d.ts +7 -6
- package/core/gather/driver/network-monitor.js +4 -4
- package/core/gather/driver/network.d.ts +2 -2
- package/core/gather/driver/network.js +1 -1
- package/core/gather/driver/prepare.d.ts +10 -10
- package/core/gather/driver/prepare.js +10 -10
- package/core/gather/driver/service-workers.d.ts +4 -4
- package/core/gather/driver/service-workers.js +2 -2
- package/core/gather/driver/storage.d.ts +6 -6
- package/core/gather/driver/storage.js +3 -3
- package/core/gather/driver/target-manager.d.ts +6 -5
- package/core/gather/driver/target-manager.js +3 -3
- package/core/gather/driver/wait-for-condition.d.ts +14 -14
- package/core/gather/driver/wait-for-condition.js +8 -8
- package/core/gather/driver.d.ts +9 -6
- package/core/gather/driver.js +14 -4
- package/core/gather/fetcher.d.ts +3 -3
- package/core/gather/fetcher.js +1 -1
- package/core/gather/gatherers/accessibility.d.ts +4 -4
- package/core/gather/gatherers/accessibility.js +8 -3
- package/core/gather/gatherers/anchor-elements.d.ts +4 -4
- package/core/gather/gatherers/anchor-elements.js +4 -4
- package/core/gather/gatherers/bf-cache-failures.d.ts +8 -14
- package/core/gather/gatherers/bf-cache-failures.js +5 -14
- package/core/gather/gatherers/cache-contents.d.ts +4 -4
- package/core/gather/gatherers/cache-contents.js +3 -3
- package/core/gather/gatherers/console-messages.d.ts +6 -6
- package/core/gather/gatherers/console-messages.js +4 -4
- package/core/gather/gatherers/css-usage.d.ts +14 -14
- package/core/gather/gatherers/css-usage.js +9 -9
- package/core/gather/gatherers/devtools-log-compat.d.ts +5 -5
- package/core/gather/gatherers/devtools-log-compat.js +4 -4
- package/core/gather/gatherers/devtools-log.d.ts +6 -6
- package/core/gather/gatherers/devtools-log.js +4 -4
- package/core/gather/gatherers/dobetterweb/doctype.d.ts +4 -4
- package/core/gather/gatherers/dobetterweb/doctype.js +3 -3
- package/core/gather/gatherers/dobetterweb/domstats.d.ts +4 -4
- package/core/gather/gatherers/dobetterweb/domstats.js +3 -3
- package/core/gather/gatherers/dobetterweb/optimized-images.d.ts +10 -22
- package/core/gather/gatherers/dobetterweb/optimized-images.js +10 -27
- package/core/gather/gatherers/dobetterweb/response-compression.d.ts +6 -12
- package/core/gather/gatherers/dobetterweb/response-compression.js +14 -21
- package/core/gather/gatherers/dobetterweb/tags-blocking-first-paint.d.ts +8 -14
- package/core/gather/gatherers/dobetterweb/tags-blocking-first-paint.js +5 -14
- package/core/gather/gatherers/full-page-screenshot.d.ts +10 -10
- package/core/gather/gatherers/full-page-screenshot.js +7 -10
- package/core/gather/gatherers/global-listeners.d.ts +4 -4
- package/core/gather/gatherers/global-listeners.js +3 -3
- package/core/gather/gatherers/iframe-elements.d.ts +4 -4
- package/core/gather/gatherers/iframe-elements.js +3 -3
- package/core/gather/gatherers/image-elements.d.ts +10 -10
- package/core/gather/gatherers/image-elements.js +6 -6
- package/core/gather/gatherers/inputs.d.ts +4 -4
- package/core/gather/gatherers/inputs.js +3 -3
- package/core/gather/gatherers/inspector-issues.d.ts +8 -19
- package/core/gather/gatherers/inspector-issues.js +9 -26
- package/core/gather/gatherers/installability-errors.d.ts +6 -6
- package/core/gather/gatherers/installability-errors.js +4 -4
- package/core/gather/gatherers/js-usage.d.ts +6 -6
- package/core/gather/gatherers/js-usage.js +4 -4
- package/core/gather/gatherers/link-elements.d.ts +8 -20
- package/core/gather/gatherers/link-elements.js +7 -24
- package/core/gather/gatherers/main-document-content.d.ts +4 -16
- package/core/gather/gatherers/main-document-content.js +5 -23
- package/core/gather/gatherers/meta-elements.d.ts +4 -4
- package/core/gather/gatherers/meta-elements.js +3 -3
- package/core/gather/gatherers/network-user-agent.d.ts +5 -5
- package/core/gather/gatherers/network-user-agent.js +4 -4
- package/core/gather/gatherers/script-elements.d.ts +6 -11
- package/core/gather/gatherers/script-elements.js +4 -13
- package/core/gather/gatherers/scripts.d.ts +7 -6
- package/core/gather/gatherers/scripts.js +7 -9
- package/core/gather/gatherers/seo/embedded-content.d.ts +4 -4
- package/core/gather/gatherers/seo/embedded-content.js +3 -3
- package/core/gather/gatherers/seo/font-size.d.ts +6 -6
- package/core/gather/gatherers/seo/font-size.js +5 -5
- package/core/gather/gatherers/seo/robots-txt.d.ts +4 -4
- package/core/gather/gatherers/seo/robots-txt.js +3 -3
- package/core/gather/gatherers/seo/tap-targets.d.ts +8 -8
- package/core/gather/gatherers/seo/tap-targets.js +5 -5
- package/core/gather/gatherers/service-worker.d.ts +4 -10
- package/core/gather/gatherers/service-worker.js +3 -15
- package/core/gather/gatherers/source-maps.d.ts +11 -23
- package/core/gather/gatherers/source-maps.js +22 -53
- package/core/gather/gatherers/stacks.d.ts +7 -7
- package/core/gather/gatherers/stacks.js +6 -6
- package/core/gather/gatherers/trace-compat.d.ts +5 -5
- package/core/gather/gatherers/trace-compat.js +4 -4
- package/core/gather/gatherers/trace-elements.d.ts +13 -25
- package/core/gather/gatherers/trace-elements.js +19 -32
- package/core/gather/gatherers/trace.d.ts +8 -8
- package/core/gather/gatherers/trace.js +5 -5
- package/core/gather/gatherers/viewport-dimensions.d.ts +4 -4
- package/core/gather/gatherers/viewport-dimensions.js +3 -3
- package/core/gather/gatherers/web-app-manifest.d.ts +8 -8
- package/core/gather/gatherers/web-app-manifest.js +5 -5
- package/core/gather/navigation-runner.d.ts +9 -9
- package/core/gather/navigation-runner.js +14 -8
- package/core/gather/runner-helpers.d.ts +3 -3
- package/core/gather/runner-helpers.js +12 -4
- package/core/gather/session.d.ts +2 -2
- package/core/gather/session.js +1 -1
- package/core/gather/snapshot-runner.d.ts +2 -2
- package/core/gather/snapshot-runner.js +1 -1
- package/core/gather/timespan-runner.d.ts +2 -2
- package/core/gather/timespan-runner.js +1 -1
- package/core/index.cjs +0 -7
- package/core/index.d.ts +0 -15
- package/core/index.js +2 -40
- package/core/lib/asset-saver.js +14 -4
- package/core/lib/axe.js +1 -1
- package/core/lib/dependency-graph/simulator/network-analyzer.d.ts +28 -12
- package/core/lib/dependency-graph/simulator/network-analyzer.js +128 -100
- package/core/lib/emulation.d.ts +14 -14
- package/core/lib/emulation.js +7 -7
- package/core/lib/navigation-error.js +5 -0
- package/core/lib/network-recorder.d.ts +2 -1
- package/core/lib/network-recorder.js +1 -0
- package/core/lib/network-request.js +12 -3
- package/core/lib/page-functions.d.ts +10 -2
- package/core/lib/page-functions.js +85 -8
- package/core/lib/sentry.js +9 -2
- package/core/lib/stack-packs.js +4 -0
- package/core/runner.d.ts +8 -30
- package/core/runner.js +8 -39
- package/core/user-flow.d.ts +4 -4
- package/core/user-flow.js +2 -2
- package/dist/report/bundle.esm.js +2221 -5832
- package/dist/report/flow.js +2631 -235
- package/dist/report/standalone.js +2586 -234
- package/flow-report/src/i18n/i18n.d.ts +2 -2
- package/package.json +17 -24
- package/readme.md +3 -1
- package/report/assets/templates.html +3 -1
- package/report/renderer/category-renderer.d.ts +3 -2
- package/report/renderer/category-renderer.js +8 -4
- package/report/renderer/components.js +11 -5
- package/report/renderer/pwa-category-renderer.js +1 -1
- package/report/renderer/report-ui-features.js +9 -6
- package/report/renderer/report-utils.d.ts +1 -1
- package/report/renderer/report-utils.js +2 -2
- package/report/renderer/topbar-features.js +3 -0
- package/shared/localization/locales/ar-XB.json +185 -44
- package/shared/localization/locales/ar.json +185 -44
- package/shared/localization/locales/bg.json +185 -44
- package/shared/localization/locales/ca.json +190 -49
- package/shared/localization/locales/cs.json +185 -44
- package/shared/localization/locales/da.json +185 -44
- package/shared/localization/locales/de.json +185 -44
- package/shared/localization/locales/el.json +185 -44
- package/shared/localization/locales/en-GB.json +185 -44
- package/shared/localization/locales/en-US.json +99 -45
- package/shared/localization/locales/en-XA.json +185 -44
- package/shared/localization/locales/en-XL.json +99 -45
- package/shared/localization/locales/es-419.json +185 -44
- package/shared/localization/locales/es.json +185 -44
- package/shared/localization/locales/fi.json +185 -44
- package/shared/localization/locales/fil.json +185 -44
- package/shared/localization/locales/fr.json +185 -44
- package/shared/localization/locales/he.json +186 -45
- package/shared/localization/locales/hi.json +185 -44
- package/shared/localization/locales/hr.json +185 -44
- package/shared/localization/locales/hu.json +185 -44
- package/shared/localization/locales/id.json +185 -44
- package/shared/localization/locales/it.json +185 -44
- package/shared/localization/locales/ja.json +185 -44
- package/shared/localization/locales/ko.json +185 -44
- package/shared/localization/locales/lt.json +185 -44
- package/shared/localization/locales/lv.json +185 -44
- package/shared/localization/locales/nl.json +185 -44
- package/shared/localization/locales/no.json +185 -44
- package/shared/localization/locales/pl.json +185 -44
- package/shared/localization/locales/pt-PT.json +185 -44
- package/shared/localization/locales/pt.json +190 -49
- package/shared/localization/locales/ro.json +185 -44
- package/shared/localization/locales/ru.json +185 -44
- package/shared/localization/locales/sk.json +185 -44
- package/shared/localization/locales/sl.json +185 -44
- package/shared/localization/locales/sr-Latn.json +185 -44
- package/shared/localization/locales/sr.json +185 -44
- package/shared/localization/locales/sv.json +185 -44
- package/shared/localization/locales/ta.json +185 -44
- package/shared/localization/locales/te.json +185 -44
- package/shared/localization/locales/th.json +185 -44
- package/shared/localization/locales/tr.json +185 -44
- package/shared/localization/locales/uk.json +185 -44
- package/shared/localization/locales/vi.json +185 -44
- package/shared/localization/locales/zh-HK.json +185 -44
- package/shared/localization/locales/zh-TW.json +185 -44
- package/shared/localization/locales/zh.json +185 -44
- package/third-party/esbuild-plugins-polyfills/LICENSE +3 -0
- package/third-party/esbuild-plugins-polyfills/README.md +7 -0
- package/third-party/esbuild-plugins-polyfills/esbuild-polyfills.d.ts +9 -0
- package/third-party/esbuild-plugins-polyfills/esbuild-polyfills.js +129 -0
- package/tsconfig.json +2 -1
- package/types/artifacts.d.ts +16 -45
- package/types/config.d.ts +10 -52
- package/types/externs.d.ts +0 -2
- package/types/gatherer.d.ts +24 -47
- package/types/internal/rxjs.d.ts +26 -0
- package/types/internal/smokehouse.d.ts +1 -3
- package/types/lh.d.ts +0 -2
- package/types/lhr/settings.d.ts +1 -1
- package/core/audits/metrics/first-contentful-paint-3g.d.ts +0 -15
- package/core/audits/metrics/first-contentful-paint-3g.js +0 -69
- package/core/audits/resource-summary.d.ts +0 -16
- package/core/audits/resource-summary.js +0 -104
- package/core/audits/service-worker.d.ts +0 -46
- package/core/audits/service-worker.js +0 -182
- package/core/gather/gatherers/gatherer.d.ts +0 -46
- package/core/gather/gatherers/gatherer.js +0 -58
- package/core/legacy/config/config.d.ts +0 -107
- package/core/legacy/config/config.js +0 -566
- package/core/legacy/config/legacy-default-config.d.ts +0 -4
- package/core/legacy/config/legacy-default-config.js +0 -87
- package/core/legacy/gather/connections/connection.d.ts +0 -77
- package/core/legacy/gather/connections/connection.js +0 -196
- package/core/legacy/gather/connections/cri.d.ts +0 -27
- package/core/legacy/gather/connections/cri.js +0 -162
- package/core/legacy/gather/connections/raw.d.ts +0 -20
- package/core/legacy/gather/connections/raw.js +0 -57
- package/core/legacy/gather/driver.d.ts +0 -216
- package/core/legacy/gather/driver.js +0 -480
- package/core/legacy/gather/gather-runner.d.ts +0 -166
- package/core/legacy/gather/gather-runner.js +0 -590
- package/types/internal/lighthouse-logger.d.ts +0 -34
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
export type ProtocolEventRecord = {
|
|
2
|
-
'protocolevent': [LH.Protocol.RawEventMessage];
|
|
3
|
-
};
|
|
4
|
-
export type CrdpEventMessageEmitter = LH.Protocol.StrictEventEmitter<ProtocolEventRecord>;
|
|
5
|
-
export type CommandInfo = LH.CrdpCommands[keyof LH.CrdpCommands];
|
|
6
|
-
export type CommandCallback = {
|
|
7
|
-
resolve: (arg0: Promise<CommandInfo['returnType']>) => void;
|
|
8
|
-
method: keyof LH.CrdpCommands;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* @typedef {{'protocolevent': [LH.Protocol.RawEventMessage]}} ProtocolEventRecord
|
|
12
|
-
* @typedef {LH.Protocol.StrictEventEmitter<ProtocolEventRecord>} CrdpEventMessageEmitter
|
|
13
|
-
* @typedef {LH.CrdpCommands[keyof LH.CrdpCommands]} CommandInfo
|
|
14
|
-
* @typedef {{resolve: function(Promise<CommandInfo['returnType']>): void, method: keyof LH.CrdpCommands}} CommandCallback
|
|
15
|
-
*/
|
|
16
|
-
export class Connection {
|
|
17
|
-
_lastCommandId: number;
|
|
18
|
-
/** @type {Map<number, CommandCallback>} */
|
|
19
|
-
_callbacks: Map<number, CommandCallback>;
|
|
20
|
-
/** @type {Map<string, LH.Protocol.TargetType>} */
|
|
21
|
-
_sessionIdToTargetType: Map<string, LH.Protocol.TargetType>;
|
|
22
|
-
_eventEmitter: CrdpEventMessageEmitter | null;
|
|
23
|
-
/**
|
|
24
|
-
* @return {Promise<void>}
|
|
25
|
-
*/
|
|
26
|
-
connect(): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* @return {Promise<void>}
|
|
29
|
-
*/
|
|
30
|
-
disconnect(): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* @return {Promise<string>}
|
|
33
|
-
*/
|
|
34
|
-
wsEndpoint(): Promise<string>;
|
|
35
|
-
/**
|
|
36
|
-
* Call protocol methods
|
|
37
|
-
* @template {keyof LH.CrdpCommands} C
|
|
38
|
-
* @param {C} method
|
|
39
|
-
* @param {string|undefined} sessionId
|
|
40
|
-
* @param {LH.CrdpCommands[C]['paramsType']} paramArgs,
|
|
41
|
-
* @return {Promise<LH.CrdpCommands[C]['returnType']>}
|
|
42
|
-
*/
|
|
43
|
-
sendCommand<C extends keyof LH.CrdpCommands>(method: C, sessionId: string | undefined, ...paramArgs: LH.CrdpCommands[C]["paramsType"]): Promise<LH.CrdpCommands[C]["returnType"]>;
|
|
44
|
-
/**
|
|
45
|
-
* Bind listeners for connection events.
|
|
46
|
-
* @param {'protocolevent'} eventName
|
|
47
|
-
* @param {function(LH.Protocol.RawEventMessage): void} cb
|
|
48
|
-
*/
|
|
49
|
-
on(eventName: 'protocolevent', cb: (arg0: LH.Protocol.RawEventMessage) => void): void;
|
|
50
|
-
/**
|
|
51
|
-
* Unbind listeners for connection events.
|
|
52
|
-
* @param {'protocolevent'} eventName
|
|
53
|
-
* @param {function(LH.Protocol.RawEventMessage): void} cb
|
|
54
|
-
*/
|
|
55
|
-
off(eventName: 'protocolevent', cb: (arg0: LH.Protocol.RawEventMessage) => void): void;
|
|
56
|
-
/**
|
|
57
|
-
* @param {string} message
|
|
58
|
-
* @protected
|
|
59
|
-
*/
|
|
60
|
-
protected sendRawMessage(message: string): void;
|
|
61
|
-
/**
|
|
62
|
-
* @param {string} message
|
|
63
|
-
* @return {void}
|
|
64
|
-
* @protected
|
|
65
|
-
*/
|
|
66
|
-
protected handleRawMessage(message: string): void;
|
|
67
|
-
/**
|
|
68
|
-
* @param {LH.Protocol.RawEventMessage} eventMessage
|
|
69
|
-
*/
|
|
70
|
-
emitProtocolEvent(eventMessage: LH.Protocol.RawEventMessage): void;
|
|
71
|
-
/**
|
|
72
|
-
* @protected
|
|
73
|
-
*/
|
|
74
|
-
protected dispose(): void;
|
|
75
|
-
}
|
|
76
|
-
import * as LH from '../../../../types/lh.js';
|
|
77
|
-
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright 2016 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
|
-
import {EventEmitter} from 'events';
|
|
8
|
-
|
|
9
|
-
import log from 'lighthouse-logger';
|
|
10
|
-
|
|
11
|
-
import * as LH from '../../../../types/lh.js';
|
|
12
|
-
import {LighthouseError} from '../../../lib/lh-error.js';
|
|
13
|
-
|
|
14
|
-
// TODO(bckenny): CommandCallback properties should be tied by command type after
|
|
15
|
-
// https://github.com/Microsoft/TypeScript/pull/22348. See driver.js TODO.
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {{'protocolevent': [LH.Protocol.RawEventMessage]}} ProtocolEventRecord
|
|
18
|
-
* @typedef {LH.Protocol.StrictEventEmitter<ProtocolEventRecord>} CrdpEventMessageEmitter
|
|
19
|
-
* @typedef {LH.CrdpCommands[keyof LH.CrdpCommands]} CommandInfo
|
|
20
|
-
* @typedef {{resolve: function(Promise<CommandInfo['returnType']>): void, method: keyof LH.CrdpCommands}} CommandCallback
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
class Connection {
|
|
24
|
-
constructor() {
|
|
25
|
-
this._lastCommandId = 0;
|
|
26
|
-
/** @type {Map<number, CommandCallback>} */
|
|
27
|
-
this._callbacks = new Map();
|
|
28
|
-
/** @type {Map<string, LH.Protocol.TargetType>} */
|
|
29
|
-
this._sessionIdToTargetType = new Map();
|
|
30
|
-
|
|
31
|
-
this._eventEmitter = /** @type {?CrdpEventMessageEmitter} */ (new EventEmitter());
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @return {Promise<void>}
|
|
36
|
-
*/
|
|
37
|
-
connect() {
|
|
38
|
-
return Promise.reject(new Error('Not implemented'));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @return {Promise<void>}
|
|
43
|
-
*/
|
|
44
|
-
disconnect() {
|
|
45
|
-
return Promise.reject(new Error('Not implemented'));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @return {Promise<string>}
|
|
50
|
-
*/
|
|
51
|
-
wsEndpoint() {
|
|
52
|
-
return Promise.reject(new Error('Not implemented'));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Call protocol methods
|
|
57
|
-
* @template {keyof LH.CrdpCommands} C
|
|
58
|
-
* @param {C} method
|
|
59
|
-
* @param {string|undefined} sessionId
|
|
60
|
-
* @param {LH.CrdpCommands[C]['paramsType']} paramArgs,
|
|
61
|
-
* @return {Promise<LH.CrdpCommands[C]['returnType']>}
|
|
62
|
-
*/
|
|
63
|
-
sendCommand(method, sessionId, ...paramArgs) {
|
|
64
|
-
// Reify params since we need it as a property so can't just spread again.
|
|
65
|
-
const params = paramArgs.length ? paramArgs[0] : undefined;
|
|
66
|
-
|
|
67
|
-
log.formatProtocol('method => browser', {method, params}, 'verbose');
|
|
68
|
-
const id = ++this._lastCommandId;
|
|
69
|
-
const message = JSON.stringify({id, sessionId, method, params});
|
|
70
|
-
this.sendRawMessage(message);
|
|
71
|
-
|
|
72
|
-
return new Promise(resolve => {
|
|
73
|
-
this._callbacks.set(id, {method, resolve});
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Bind listeners for connection events.
|
|
79
|
-
* @param {'protocolevent'} eventName
|
|
80
|
-
* @param {function(LH.Protocol.RawEventMessage): void} cb
|
|
81
|
-
*/
|
|
82
|
-
on(eventName, cb) {
|
|
83
|
-
if (eventName !== 'protocolevent') {
|
|
84
|
-
throw new Error('Only supports "protocolevent" events');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (!this._eventEmitter) {
|
|
88
|
-
throw new Error('Attempted to add event listener after connection disposed.');
|
|
89
|
-
}
|
|
90
|
-
this._eventEmitter.on(eventName, cb);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Unbind listeners for connection events.
|
|
95
|
-
* @param {'protocolevent'} eventName
|
|
96
|
-
* @param {function(LH.Protocol.RawEventMessage): void} cb
|
|
97
|
-
*/
|
|
98
|
-
off(eventName, cb) {
|
|
99
|
-
if (eventName !== 'protocolevent') {
|
|
100
|
-
throw new Error('Only supports "protocolevent" events');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (!this._eventEmitter) {
|
|
104
|
-
throw new Error('Attempted to remove event listener after connection disposed.');
|
|
105
|
-
}
|
|
106
|
-
this._eventEmitter.removeListener(eventName, cb);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/* eslint-disable no-unused-vars */
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* @param {string} message
|
|
113
|
-
* @protected
|
|
114
|
-
*/
|
|
115
|
-
sendRawMessage(message) {
|
|
116
|
-
throw new Error('Not implemented');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/* eslint-enable no-unused-vars */
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @param {string} message
|
|
123
|
-
* @return {void}
|
|
124
|
-
* @protected
|
|
125
|
-
*/
|
|
126
|
-
handleRawMessage(message) {
|
|
127
|
-
/** @type {LH.Protocol.RawMessage} */
|
|
128
|
-
const object = JSON.parse(message);
|
|
129
|
-
|
|
130
|
-
// Responses to commands carry "id" property, while events do not.
|
|
131
|
-
if (!('id' in object)) {
|
|
132
|
-
log.formatProtocol('<= event',
|
|
133
|
-
{method: object.method, params: object.params}, 'verbose');
|
|
134
|
-
if (object.method === 'Target.attachedToTarget') {
|
|
135
|
-
const type = object.params.targetInfo.type;
|
|
136
|
-
if (type === 'page' || type === 'iframe') {
|
|
137
|
-
this._sessionIdToTargetType.set(object.params.sessionId, type);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (object.sessionId) {
|
|
141
|
-
const type = this._sessionIdToTargetType.get(object.sessionId);
|
|
142
|
-
if (type) {
|
|
143
|
-
object.targetType = type;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
this.emitProtocolEvent(object);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const callback = this._callbacks.get(object.id);
|
|
151
|
-
if (callback) {
|
|
152
|
-
this._callbacks.delete(object.id);
|
|
153
|
-
|
|
154
|
-
callback.resolve(Promise.resolve().then(_ => {
|
|
155
|
-
if (object.error) {
|
|
156
|
-
log.formatProtocol('method <= browser ERR', {method: callback.method}, 'error');
|
|
157
|
-
throw LighthouseError.fromProtocolMessage(callback.method, object.error);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
log.formatProtocol('method <= browser OK',
|
|
161
|
-
{method: callback.method, params: object.result}, 'verbose');
|
|
162
|
-
return object.result;
|
|
163
|
-
}));
|
|
164
|
-
} else {
|
|
165
|
-
// In DevTools we receive responses to commands we did not send which we cannot act on, so we
|
|
166
|
-
// just log these occurrences.
|
|
167
|
-
const error = object.error?.message;
|
|
168
|
-
log.formatProtocol(`disowned method <= browser ${error ? 'ERR' : 'OK'}`,
|
|
169
|
-
{method: 'UNKNOWN', params: error || object.result}, 'verbose');
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* @param {LH.Protocol.RawEventMessage} eventMessage
|
|
175
|
-
*/
|
|
176
|
-
emitProtocolEvent(eventMessage) {
|
|
177
|
-
if (!this._eventEmitter) {
|
|
178
|
-
throw new Error('Attempted to emit event after connection disposed.');
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
this._eventEmitter.emit('protocolevent', eventMessage);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* @protected
|
|
186
|
-
*/
|
|
187
|
-
dispose() {
|
|
188
|
-
if (this._eventEmitter) {
|
|
189
|
-
this._eventEmitter.removeAllListeners();
|
|
190
|
-
this._eventEmitter = null;
|
|
191
|
-
}
|
|
192
|
-
this._sessionIdToTargetType.clear();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export {Connection};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export class CriConnection extends Connection {
|
|
2
|
-
/**
|
|
3
|
-
* @param {number=} port Optional port number. Defaults to 9222;
|
|
4
|
-
* @param {string=} hostname Optional hostname. Defaults to localhost.
|
|
5
|
-
* @constructor
|
|
6
|
-
*/
|
|
7
|
-
constructor(port?: number | undefined, hostname?: string | undefined);
|
|
8
|
-
port: number;
|
|
9
|
-
hostname: string;
|
|
10
|
-
_ws: WebSocket | null;
|
|
11
|
-
_pageId: string | null;
|
|
12
|
-
/**
|
|
13
|
-
* @param {LH.DevToolsJsonTarget} response
|
|
14
|
-
* @return {Promise<void>}
|
|
15
|
-
* @private
|
|
16
|
-
*/
|
|
17
|
-
private _connectToSocket;
|
|
18
|
-
/**
|
|
19
|
-
* @param {string} command
|
|
20
|
-
* @return {Promise<LH.DevToolsJsonTarget | Array<LH.DevToolsJsonTarget> | {message: string}>}
|
|
21
|
-
* @private
|
|
22
|
-
*/
|
|
23
|
-
private _runJsonCommand;
|
|
24
|
-
}
|
|
25
|
-
import { Connection } from './connection.js';
|
|
26
|
-
import WebSocket from 'ws';
|
|
27
|
-
//# sourceMappingURL=cri.d.ts.map
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright 2016 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
|
-
import http from 'http';
|
|
8
|
-
|
|
9
|
-
import WebSocket from 'ws';
|
|
10
|
-
import log from 'lighthouse-logger';
|
|
11
|
-
|
|
12
|
-
import {Connection} from './connection.js';
|
|
13
|
-
import {LighthouseError} from '../../../lib/lh-error.js';
|
|
14
|
-
|
|
15
|
-
const DEFAULT_HOSTNAME = '127.0.0.1';
|
|
16
|
-
const CONNECT_TIMEOUT = 10000;
|
|
17
|
-
const DEFAULT_PORT = 9222;
|
|
18
|
-
|
|
19
|
-
class CriConnection extends Connection {
|
|
20
|
-
/**
|
|
21
|
-
* @param {number=} port Optional port number. Defaults to 9222;
|
|
22
|
-
* @param {string=} hostname Optional hostname. Defaults to localhost.
|
|
23
|
-
* @constructor
|
|
24
|
-
*/
|
|
25
|
-
constructor(port = DEFAULT_PORT, hostname = DEFAULT_HOSTNAME) {
|
|
26
|
-
super();
|
|
27
|
-
this.port = port;
|
|
28
|
-
this.hostname = hostname;
|
|
29
|
-
this._ws = null;
|
|
30
|
-
this._pageId = null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @override
|
|
35
|
-
* @return {Promise<void>}
|
|
36
|
-
*/
|
|
37
|
-
async connect() {
|
|
38
|
-
const response = await this._runJsonCommand('new');
|
|
39
|
-
return this._connectToSocket(/** @type {LH.DevToolsJsonTarget} */(response));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @param {LH.DevToolsJsonTarget} response
|
|
44
|
-
* @return {Promise<void>}
|
|
45
|
-
* @private
|
|
46
|
-
*/
|
|
47
|
-
_connectToSocket(response) {
|
|
48
|
-
const url = response.webSocketDebuggerUrl;
|
|
49
|
-
this._pageId = response.id;
|
|
50
|
-
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
const ws = new WebSocket(url, {
|
|
53
|
-
perMessageDeflate: false,
|
|
54
|
-
});
|
|
55
|
-
ws.on('open', () => {
|
|
56
|
-
this._ws = ws;
|
|
57
|
-
resolve();
|
|
58
|
-
});
|
|
59
|
-
ws.on('message', data => this.handleRawMessage(/** @type {string} */ (data)));
|
|
60
|
-
ws.on('close', this.dispose.bind(this));
|
|
61
|
-
ws.on('error', reject);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @param {string} command
|
|
67
|
-
* @return {Promise<LH.DevToolsJsonTarget | Array<LH.DevToolsJsonTarget> | {message: string}>}
|
|
68
|
-
* @private
|
|
69
|
-
*/
|
|
70
|
-
_runJsonCommand(command) {
|
|
71
|
-
return new Promise((resolve, reject) => {
|
|
72
|
-
const request = http.request({
|
|
73
|
-
method: 'PUT', // GET and POST are deprecated: https://crrev.com/c/3595822
|
|
74
|
-
hostname: this.hostname,
|
|
75
|
-
port: this.port,
|
|
76
|
-
path: '/json/' + command,
|
|
77
|
-
}, response => {
|
|
78
|
-
let data = '';
|
|
79
|
-
response.setEncoding('utf8');
|
|
80
|
-
response.on('data', chunk => {
|
|
81
|
-
data += chunk;
|
|
82
|
-
});
|
|
83
|
-
response.on('end', () => {
|
|
84
|
-
if (response.statusCode === 200) {
|
|
85
|
-
try {
|
|
86
|
-
resolve(JSON.parse(data));
|
|
87
|
-
return;
|
|
88
|
-
} catch (e) {
|
|
89
|
-
// In the case of 'close' & 'activate' Chromium returns a string rather than JSON: goo.gl/7v27xD
|
|
90
|
-
if (data === 'Target is closing' || data === 'Target activated') {
|
|
91
|
-
return resolve({message: data});
|
|
92
|
-
}
|
|
93
|
-
return reject(e);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
reject(new Error(`Protocol JSON API error (${command}), status: ${response.statusCode}`));
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
request.end();
|
|
101
|
-
|
|
102
|
-
// This error handler is critical to ensuring Lighthouse exits cleanly even when Chrome crashes.
|
|
103
|
-
// See https://github.com/GoogleChrome/lighthouse/pull/8583.
|
|
104
|
-
request.on('error', reject);
|
|
105
|
-
|
|
106
|
-
request.setTimeout(CONNECT_TIMEOUT, () => {
|
|
107
|
-
// Reject on error with code specifically indicating timeout in connection setup.
|
|
108
|
-
const err = new LighthouseError(LighthouseError.errors.CRI_TIMEOUT);
|
|
109
|
-
log.error('CriConnection', err.friendlyMessage);
|
|
110
|
-
reject(err);
|
|
111
|
-
|
|
112
|
-
request.abort();
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* @override
|
|
119
|
-
* @return {Promise<void>}
|
|
120
|
-
*/
|
|
121
|
-
disconnect() {
|
|
122
|
-
if (!this._ws) {
|
|
123
|
-
log.warn('CriConnection', 'disconnect() was called without an established connection.');
|
|
124
|
-
return Promise.resolve();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return this._runJsonCommand(`close/${this._pageId}`).then(_ => {
|
|
128
|
-
if (this._ws) {
|
|
129
|
-
this._ws.removeAllListeners();
|
|
130
|
-
this._ws.close();
|
|
131
|
-
this._ws = null;
|
|
132
|
-
}
|
|
133
|
-
this._pageId = null;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @override
|
|
139
|
-
* @return {Promise<string>}
|
|
140
|
-
*/
|
|
141
|
-
wsEndpoint() {
|
|
142
|
-
return this._runJsonCommand('version').then(response => {
|
|
143
|
-
return /** @type {LH.DevToolsJsonTarget} */ (response).webSocketDebuggerUrl;
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* @override
|
|
150
|
-
* @param {string} message
|
|
151
|
-
* @protected
|
|
152
|
-
*/
|
|
153
|
-
sendRawMessage(message) {
|
|
154
|
-
if (!this._ws) {
|
|
155
|
-
log.error('CriConnection', 'sendRawMessage() was called without an established connection.');
|
|
156
|
-
throw new Error('sendRawMessage() was called without an established connection.');
|
|
157
|
-
}
|
|
158
|
-
this._ws.send(message);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export {CriConnection};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type Port = {
|
|
2
|
-
on: (eventName: 'message' | 'close', cb: ((arg: string) => void) | (() => void)) => void;
|
|
3
|
-
send: (message: string) => void;
|
|
4
|
-
close: () => void;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {object} Port
|
|
8
|
-
* @property {(eventName: 'message'|'close', cb: ((arg: string) => void) | (() => void)) => void} on
|
|
9
|
-
* @property {(message: string) => void} send
|
|
10
|
-
* @property {() => void} close
|
|
11
|
-
*/
|
|
12
|
-
export class RawConnection extends Connection {
|
|
13
|
-
/**
|
|
14
|
-
* @param {Port} port
|
|
15
|
-
*/
|
|
16
|
-
constructor(port: Port);
|
|
17
|
-
_port: Port;
|
|
18
|
-
}
|
|
19
|
-
import { Connection } from './connection.js';
|
|
20
|
-
//# sourceMappingURL=raw.d.ts.map
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright 2016 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
|
-
import {Connection} from './connection.js';
|
|
8
|
-
|
|
9
|
-
/* eslint-disable no-unused-vars */
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @typedef {object} Port
|
|
13
|
-
* @property {(eventName: 'message'|'close', cb: ((arg: string) => void) | (() => void)) => void} on
|
|
14
|
-
* @property {(message: string) => void} send
|
|
15
|
-
* @property {() => void} close
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/* eslint-enable no-unused-vars */
|
|
19
|
-
|
|
20
|
-
class RawConnection extends Connection {
|
|
21
|
-
/**
|
|
22
|
-
* @param {Port} port
|
|
23
|
-
*/
|
|
24
|
-
constructor(port) {
|
|
25
|
-
super();
|
|
26
|
-
this._port = port;
|
|
27
|
-
this._port.on('message', this.handleRawMessage.bind(this));
|
|
28
|
-
this._port.on('close', this.dispose.bind(this));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @override
|
|
33
|
-
* @return {Promise<void>}
|
|
34
|
-
*/
|
|
35
|
-
connect() {
|
|
36
|
-
return Promise.resolve();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @return {Promise<void>}
|
|
41
|
-
*/
|
|
42
|
-
disconnect() {
|
|
43
|
-
this._port.close();
|
|
44
|
-
return Promise.resolve();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @override
|
|
49
|
-
* @param {string} message
|
|
50
|
-
* @protected
|
|
51
|
-
*/
|
|
52
|
-
sendRawMessage(message) {
|
|
53
|
-
this._port.send(message);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export {RawConnection};
|