diff --git a/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap b/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap index 3f92a647b8ba..f58b5096c6ee 100644 --- a/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap +++ b/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap @@ -1147,6 +1147,9 @@ Object { Object { "path": "iframe-elements", }, + Object { + "path": "main-document-content", + }, Object { "path": "dobetterweb/appcache", }, diff --git a/lighthouse-cli/test/smokehouse/dbw-config.js b/lighthouse-cli/test/smokehouse/dbw-config.js index 468dfe34494a..319aa5280923 100644 --- a/lighthouse-cli/test/smokehouse/dbw-config.js +++ b/lighthouse-cli/test/smokehouse/dbw-config.js @@ -10,18 +10,6 @@ */ module.exports = { extends: 'lighthouse:default', - settings: { - onlyCategories: [ - 'best-practices', - ], - onlyAudits: [ - 'dom-size', - 'render-blocking-resources', - 'errors-in-console', - 'efficient-animated-content', - 'apple-touch-icon', // pull in apple touch icon to test `LinkElements` - ], - }, audits: [ // Test the `ignoredPatterns` audit option. {path: 'errors-in-console', options: {ignoredPatterns: ['An ignored error']}}, diff --git a/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js b/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js index d9544efdec8d..d3de80f8d691 100644 --- a/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js +++ b/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js @@ -20,6 +20,7 @@ const expectations = [ }, { id: 'wordpress', }], + MainDocumentContent: /^.*DoBetterWeb Mega Tester.*aggressive-promise-polyfill.*<\/html>\n$/s, LinkElements: [ { rel: 'stylesheet', diff --git a/lighthouse-core/config/default-config.js b/lighthouse-core/config/default-config.js index ce9800a5f9f9..1d5258ed38c6 100644 --- a/lighthouse-core/config/default-config.js +++ b/lighthouse-core/config/default-config.js @@ -136,6 +136,7 @@ const defaultConfig = { 'meta-elements', 'script-elements', 'iframe-elements', + 'main-document-content', 'dobetterweb/appcache', 'dobetterweb/doctype', 'dobetterweb/domstats', diff --git a/lighthouse-core/gather/gatherers/main-document-content.js b/lighthouse-core/gather/gatherers/main-document-content.js new file mode 100644 index 000000000000..bb28df0a401f --- /dev/null +++ b/lighthouse-core/gather/gatherers/main-document-content.js @@ -0,0 +1,28 @@ +/** + * @license Copyright 2019 Google Inc. All Rights Reserved. + * 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 + * 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. + */ +'use strict'; + +const Gatherer = require('./gatherer.js'); +const NetworkAnalyzer = require('../../lib/dependency-graph/simulator/network-analyzer.js'); + +/** + * Collects the content of the main html document. + */ +class MainDocumentContent extends Gatherer { + /** + * @param {LH.Gatherer.PassContext} passContext + * @param {LH.Gatherer.LoadData} loadData + * @return {Promise} + */ + async afterPass(passContext, loadData) { + const mainResource = NetworkAnalyzer.findMainDocument(loadData.networkRecords, passContext.url); + + const driver = passContext.driver; + return driver.getRequestContent(mainResource.requestId); + } +} + +module.exports = MainDocumentContent; diff --git a/lighthouse-core/test/results/artifacts/artifacts.json b/lighthouse-core/test/results/artifacts/artifacts.json index 28acd6c8f81c..f4c834b689cb 100644 --- a/lighthouse-core/test/results/artifacts/artifacts.json +++ b/lighthouse-core/test/results/artifacts/artifacts.json @@ -2113,5 +2113,6 @@ "name": "html", "systemId": "", "publicId": "" - } -} \ No newline at end of file + }, + "MainDocumentContent": "\n\n\n\n\n\nDoBetterWeb Mega Tester... Of Death\n\n\n\n\n\n\n\n\n\n\n\n \n \n \n \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n\n\n\n\n
\n

Do better web tester page

\n Hi there!\n\n \n \n Facebook\n \n \n \n
\n\n
touchmove section
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +} diff --git a/types/artifacts.d.ts b/types/artifacts.d.ts index a3ff14433bff..4ad5f03b0dd3 100644 --- a/types/artifacts.d.ts +++ b/types/artifacts.d.ts @@ -63,6 +63,8 @@ declare global { ConsoleMessages: Crdp.Log.EntryAddedEvent[]; /** All the iframe elements in the page.*/ IFrameElements: Artifacts.IFrameElement[]; + /** The contents of the main HTML document network resource. */ + MainDocumentContent: string; /** Information on size and loading for all the images in the page. Natural size information for `picture` and CSS images is only available if the image was one of the largest 50 images. */ ImageElements: Artifacts.ImageElement[]; /** All the link elements on the page or equivalently declared in `Link` headers. @see https://html.spec.whatwg.org/multipage/links.html */