diff --git a/core/gather/gatherers/css-usage.js b/core/gather/gatherers/css-usage.js index 0aea2c6f7d02..f89069280dc2 100644 --- a/core/gather/gatherers/css-usage.js +++ b/core/gather/gatherers/css-usage.js @@ -36,7 +36,7 @@ class CSSUsage extends BaseGatherer { /** * @param {LH.Crdp.CSS.StyleSheetAddedEvent} event */ - async _onStylesheetAdded(event) { + _onStylesheetAdded(event) { if (!this._session) throw new Error('Session not initialized'); const styleSheetId = event.header.styleSheetId; const sheetPromise = this._session.sendCommand('CSS.getStyleSheetText', {styleSheetId}) @@ -98,6 +98,9 @@ class CSSUsage extends BaseGatherer { this._ruleUsage = coverageResponse.ruleUsage; session.off('CSS.styleSheetAdded', this._onStylesheetAdded); + // Ensure we finish fetching all stylesheet contents before disabling the CSS domain + await Promise.all(this._sheetPromises.values()); + await session.sendCommand('CSS.disable'); await session.sendCommand('DOM.disable'); }