diff --git a/core/gather/driver.js b/core/gather/driver.js index 0afef34f8f5f..73a9ba7cf78f 100644 --- a/core/gather/driver.js +++ b/core/gather/driver.js @@ -26,6 +26,7 @@ const throwingSession = { once: throwNotConnectedFn, off: throwNotConnectedFn, sendCommand: throwNotConnectedFn, + sendCommandAndIgnore: throwNotConnectedFn, dispose: throwNotConnectedFn, }; diff --git a/core/gather/driver/target-manager.js b/core/gather/driver/target-manager.js index 146810df67d9..6872df807e80 100644 --- a/core/gather/driver/target-manager.js +++ b/core/gather/driver/target-manager.js @@ -180,7 +180,7 @@ class TargetManager extends ProtocolEventEmitter { throw err; } finally { // Resume the target if it was paused, but if it's unnecessary, we don't care about the error. - await newSession.sendCommand('Runtime.runIfWaitingForDebugger').catch(() => {}); + await newSession.sendCommandAndIgnore('Runtime.runIfWaitingForDebugger'); } } diff --git a/core/gather/driver/wait-for-condition.js b/core/gather/driver/wait-for-condition.js index d3f65fc9f183..b110f686c12a 100644 --- a/core/gather/driver/wait-for-condition.js +++ b/core/gather/driver/wait-for-condition.js @@ -498,9 +498,8 @@ async function waitForFullyLoaded(session, networkMonitor, options) { if (await isPageHung(session)) { log.warn('waitFor', 'Page appears to be hung, killing JavaScript...'); // We don't await these, as we want to exit with PAGE_HUNG - void session.sendCommand('Emulation.setScriptExecutionDisabled', {value: true}) - .catch(_ => {}); - void session.sendCommand('Runtime.terminateExecution').catch(_ => {}); + void session.sendCommandAndIgnore('Emulation.setScriptExecutionDisabled', {value: true}); + void session.sendCommandAndIgnore('Runtime.terminateExecution'); throw new LighthouseError(LighthouseError.errors.PAGE_HUNG); } diff --git a/core/gather/session.js b/core/gather/session.js index 46581ae73a69..b01e1d68bd0a 100644 --- a/core/gather/session.js +++ b/core/gather/session.js @@ -120,6 +120,18 @@ class ProtocolSession extends CrdpEventEmitter { }); } + /** + * Send and if there's an error response, do not reject. + * @template {keyof LH.CrdpCommands} C + * @param {C} method + * @param {LH.CrdpCommands[C]['paramsType']} params + * @return {Promise} + */ + sendCommandAndIgnore(method, ...params) { + return this.sendCommand(method, ...params) + .catch(e => log.verbose('session', method, e.message)).then(_ => void 0); + } + /** * Disposes of a session so that it can no longer talk to Chrome. * @return {Promise} diff --git a/core/test/gather/mock-driver.js b/core/test/gather/mock-driver.js index 4e3618cb2aa6..6ef25211ce99 100644 --- a/core/test/gather/mock-driver.js +++ b/core/test/gather/mock-driver.js @@ -24,9 +24,11 @@ import {NetworkMonitor} from '../../gather/driver/network-monitor.js'; /** @typedef {import('../../gather/driver/execution-context.js')} ExecutionContext */ function createMockSession() { + const mockSendCommand = createMockSendCommandFn(); return { setTargetInfo: fnAny(), - sendCommand: createMockSendCommandFn(), + sendCommand: mockSendCommand, + sendCommandAndIgnore: mockSendCommand, setNextProtocolTimeout: fnAny(), hasNextProtocolTimeout: fnAny(), getNextProtocolTimeout: fnAny(), diff --git a/types/gatherer.d.ts b/types/gatherer.d.ts index 8e6bc67db864..c5e6796a1aad 100644 --- a/types/gatherer.d.ts +++ b/types/gatherer.d.ts @@ -33,6 +33,7 @@ declare module Gatherer { once(event: TEvent, callback: (...args: CrdpEvents[TEvent]) => void): void; off(event: TEvent, callback: (...args: CrdpEvents[TEvent]) => void): void; sendCommand(method: TMethod, ...params: CrdpCommands[TMethod]['paramsType']): Promise; + sendCommandAndIgnore(method: TMethod, ...params: CrdpCommands[TMethod]['paramsType']): Promise; dispose(): Promise; }