diff --git a/core/gather/gatherers/devtools-log.js b/core/gather/gatherers/devtools-log.js index 270e55bbce71..3dcec2e789bd 100644 --- a/core/gather/gatherers/devtools-log.js +++ b/core/gather/gatherers/devtools-log.js @@ -49,6 +49,13 @@ class DevtoolsLog extends BaseGatherer { driver.targetManager.off('protocolevent', this._onProtocolMessage); } + /** + * @return {LH.Artifacts['DevtoolsLog']} + */ + getDebugData() { + return this._messageLog.messages; + } + /** * @return {Promise} */ diff --git a/core/gather/gatherers/trace.js b/core/gather/gatherers/trace.js index c3c24508a808..a7d4640dc48d 100644 --- a/core/gather/gatherers/trace.js +++ b/core/gather/gatherers/trace.js @@ -126,6 +126,10 @@ class Trace extends BaseGatherer { this._trace = await Trace.endTraceAndCollectEvents(driver.defaultSession); } + getDebugData() { + return this._trace; + } + getArtifact() { return this._trace; } diff --git a/core/gather/navigation-runner.js b/core/gather/navigation-runner.js index 31c6e7c45d80..6bbf8ec39080 100644 --- a/core/gather/navigation-runner.js +++ b/core/gather/navigation-runner.js @@ -110,32 +110,20 @@ async function _navigate(navigationContext) { * @return {Promise<{devtoolsLog?: LH.DevtoolsLog, records?: Array, trace?: LH.Trace}>} */ async function _collectDebugData(navigationContext, phaseState) { - const devtoolsLogArtifactDefn = phaseState.artifactDefinitions.find( - definition => definition.gatherer.instance.meta.symbol === DevtoolsLog.symbol - ); - const traceArtifactDefn = phaseState.artifactDefinitions.find( - definition => definition.gatherer.instance.meta.symbol === Trace.symbol - ); - - const artifactDefinitions = [devtoolsLogArtifactDefn, traceArtifactDefn].filter( - /** - * @param {LH.Config.AnyArtifactDefn | undefined} defn - * @return {defn is LH.Config.AnyArtifactDefn} - */ - defn => Boolean(defn) - ); - if (!artifactDefinitions.length) return {}; - - await collectPhaseArtifacts({...phaseState, phase: 'getArtifact', artifactDefinitions}); - const getArtifactState = phaseState.artifactState.getArtifact; + let devtoolsLog; + let trace; + + for (const definition of phaseState.artifactDefinitions) { + const {instance} = definition.gatherer; + if (instance instanceof DevtoolsLog) { + devtoolsLog = instance.getDebugData(); + } else if (instance instanceof Trace) { + trace = instance.getDebugData(); + } + } - const devtoolsLogArtifactId = devtoolsLogArtifactDefn?.id; - const devtoolsLog = devtoolsLogArtifactId && (await getArtifactState[devtoolsLogArtifactId]); const records = devtoolsLog && (await NetworkRecords.request(devtoolsLog, navigationContext)); - const traceArtifactId = traceArtifactDefn?.id; - const trace = traceArtifactId && (await getArtifactState[traceArtifactId]); - return {devtoolsLog, records, trace}; } diff --git a/core/test/gather/navigation-runner-test.js b/core/test/gather/navigation-runner-test.js index e518bb77ed93..ceb57f67d9df 100644 --- a/core/test/gather/navigation-runner-test.js +++ b/core/test/gather/navigation-runner-test.js @@ -344,13 +344,27 @@ describe('NavigationRunner', () => { }); it('finds page load errors in network records when available', async () => { - const {resolvedConfig, gatherers} = createMockConfig(); - mocks.navigationMock.gotoURL.mockResolvedValue({mainDocumentUrl: requestedUrl, warnings: []}); + mocks.navigationMock.gotoURL.mockReturnValue({ + requestedUrl, + mainDocumentUrl: requestedUrl, + warnings: [], + }); + + const devtoolsLogInstance = new DevtoolsLogGatherer(); + const traceInstance = new TraceGatherer(); + + // @ts-expect-error mock config + const resolvedConfig = /** @type {LH.Config.ResolvedConfig} */ ({ + settings: JSON.parse(JSON.stringify(defaultSettings)), + artifacts: [ + {id: 'DevtoolsLog', gatherer: {instance: devtoolsLogInstance}}, + {id: 'Trace', gatherer: {instance: traceInstance}}, + ], + }); + const devtoolsLog = networkRecordsToDevtoolsLog([{url: requestedUrl, failed: true}]); - gatherers.timespan.meta.symbol = DevtoolsLogGatherer.symbol; - gatherers.timespan.getArtifact = fnAny().mockResolvedValue(devtoolsLog); - gatherers.navigation.meta.symbol = TraceGatherer.symbol; - gatherers.navigation.getArtifact = fnAny().mockResolvedValue({traceEvents: []}); + devtoolsLogInstance.getDebugData = fnAny().mockReturnValue(devtoolsLog); + traceInstance.getDebugData = fnAny().mockReturnValue({traceEvents: []}); const artifacts = await runner._navigation({ driver,