diff --git a/core/config/default-config.js b/core/config/default-config.js index cba121151af3..f54a64730846 100644 --- a/core/config/default-config.js +++ b/core/config/default-config.js @@ -118,7 +118,6 @@ const defaultConfig = { {id: 'ConsoleMessages', gatherer: 'console-messages'}, {id: 'CSSUsage', gatherer: 'css-usage'}, {id: 'Doctype', gatherer: 'dobetterweb/doctype'}, - {id: 'DOMStats', gatherer: 'dobetterweb/domstats'}, {id: 'Inputs', gatherer: 'inputs'}, {id: 'IFrameElements', gatherer: 'iframe-elements'}, {id: 'ImageElements', gatherer: 'image-elements'}, diff --git a/core/gather/gatherers/dobetterweb/domstats.js b/core/gather/gatherers/dobetterweb/domstats.js deleted file mode 100644 index 17f44297106d..000000000000 --- a/core/gather/gatherers/dobetterweb/domstats.js +++ /dev/null @@ -1,102 +0,0 @@ -/** - * @license - * Copyright 2017 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @fileoverview Gathers stats about the max height and width of the DOM tree - * and total number of elements used on the page. - */ - -/* global getNodeDetails */ - - -import BaseGatherer from '../../base-gatherer.js'; -import {pageFunctions} from '../../../lib/page-functions.js'; - -/** - * Calculates the maximum tree depth of the DOM. - * @param {HTMLElement} element Root of the tree to look in. - * @param {boolean=} deep True to include shadow roots. Defaults to true. - * @return {LH.Artifacts.DOMStats} - */ -/* c8 ignore start */ -function getDOMStats(element = document.body, deep = true) { - let deepestElement = null; - let maxDepth = -1; - let maxWidth = -1; - let numElements = 0; - let parentWithMostChildren = null; - - /** - * @param {Element|ShadowRoot} element - * @param {number} depth - */ - const _calcDOMWidthAndHeight = function(element, depth = 1) { - if (depth > maxDepth) { - deepestElement = element; - maxDepth = depth; - } - if (element.children.length > maxWidth) { - parentWithMostChildren = element; - maxWidth = element.children.length; - } - - let child = element.firstElementChild; - while (child) { - _calcDOMWidthAndHeight(child, depth + 1); - // If element has shadow dom, traverse into that tree. - if (deep && child.shadowRoot) { - _calcDOMWidthAndHeight(child.shadowRoot, depth + 1); - } - child = child.nextElementSibling; - numElements++; - } - - return {maxDepth, maxWidth, numElements}; - }; - - const result = _calcDOMWidthAndHeight(element); - - return { - depth: { - max: result.maxDepth, - // @ts-expect-error - getNodeDetails put into scope via stringification - ...getNodeDetails(deepestElement), - }, - width: { - max: result.maxWidth, - // @ts-expect-error - getNodeDetails put into scope via stringification - ...getNodeDetails(parentWithMostChildren), - }, - totalBodyElements: result.numElements, - }; -} -/* c8 ignore stop */ - -class DOMStats extends BaseGatherer { - /** @type {LH.Gatherer.GathererMeta} */ - meta = { - supportedModes: ['snapshot', 'navigation'], - }; - - /** - * @param {LH.Gatherer.Context} passContext - * @return {Promise} - */ - async getArtifact(passContext) { - const driver = passContext.driver; - - await driver.defaultSession.sendCommand('DOM.enable'); - const results = await driver.executionContext.evaluate(getDOMStats, { - args: [], - useIsolation: true, - deps: [pageFunctions.getNodeDetails], - }); - await driver.defaultSession.sendCommand('DOM.disable'); - return results; - } -} - -export default DOMStats; diff --git a/types/artifacts.d.ts b/types/artifacts.d.ts index b2b89bc0e333..116ead84c187 100644 --- a/types/artifacts.d.ts +++ b/types/artifacts.d.ts @@ -116,8 +116,6 @@ export interface GathererArtifacts extends PublicGathererArtifacts { /** Information on the document's doctype(or null if not present), specifically the name, publicId, and systemId. All properties default to an empty string if not present */ Doctype: Artifacts.Doctype | null; - /** Information on the size of all DOM nodes in the page and the most extreme members. */ - DOMStats: Artifacts.DOMStats; /** All the iframe elements in the page. */ IFrameElements: Artifacts.IFrameElement[]; /** All the input elements, including associated form and label elements. */ @@ -224,13 +222,6 @@ declare module Artifacts { documentCompatMode: string; } - interface DOMStats { - /** The total number of elements found within the page's body. */ - totalBodyElements: number; - width: NodeDetails & {max: number;}; - depth: NodeDetails & {max: number;}; - } - interface IFrameElement { /** The `id` attribute of the iframe. */ id: string,