Skip to content

Commit

Permalink
Revert "core(without-javascript): remove audit (#11711)"
Browse files Browse the repository at this point in the history
This reverts commit 2aa9845.
  • Loading branch information
paulirish committed Dec 11, 2020
1 parent 2aa9845 commit 1f80c94
Show file tree
Hide file tree
Showing 69 changed files with 944 additions and 8 deletions.
11 changes: 11 additions & 0 deletions lighthouse-cli/test/cli/__snapshots__/index-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Object {
Object {
"path": "viewport",
},
Object {
"path": "without-javascript",
},
Object {
"path": "metrics/first-contentful-paint",
},
Expand Down Expand Up @@ -1141,6 +1144,11 @@ Object {
"id": "viewport",
"weight": 2,
},
Object {
"group": "pwa-optimized",
"id": "without-javascript",
"weight": 1,
},
Object {
"group": "pwa-optimized",
"id": "apple-touch-icon",
Expand Down Expand Up @@ -1478,6 +1486,9 @@ Object {
Object {
"path": "http-redirect",
},
Object {
"path": "html-without-javascript",
},
],
"loadFailureMode": "warn",
"networkQuietThresholdMs": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
'service-worker',
'works-offline',
'viewport',
'without-javascript',
'user-timings',
'critical-request-chains',
'render-blocking-resources',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module.exports = [
'viewport': {
score: 1,
},
'without-javascript': {
score: 1,
},
'user-timings': {
scoreDisplayMode: 'notApplicable',
},
Expand Down Expand Up @@ -139,6 +142,9 @@ module.exports = [
'viewport': {
score: 1,
},
'without-javascript': {
score: 1,
},
'user-timings': {
scoreDisplayMode: 'notApplicable',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const expectations = [
'viewport': {
score: 1,
},
'without-javascript': {
score: 1,
},
'installable-manifest': {
score: 1,
details: {items: [pwaDetailsExpectations]},
Expand Down Expand Up @@ -95,6 +98,9 @@ const expectations = [
'viewport': {
score: 1,
},
'without-javascript': {
score: 1,
},
'installable-manifest': {
score: 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ module.exports = [
score: 1,
},
'redirects-http': {
score: 1,
// Note: relies on JS redirect.
// see https://github.com/GoogleChrome/lighthouse/issues/2383
score: 0,
},
'service-worker': {
score: 1,
Expand All @@ -37,6 +39,9 @@ module.exports = [
'viewport': {
score: 1,
},
'without-javascript': {
score: 1,
},
'installable-manifest': {
score: 0,
details: {items: [jakeExpectations]},
Expand Down Expand Up @@ -100,6 +105,9 @@ module.exports = [
'viewport': {
score: 1,
},
'without-javascript': {
score: 1,
},
'installable-manifest': {
score: 1,
details: {items: [{...pwaDetailsExpectations, manifestUrl: 'https://caltrainschedule.io/manifest.json'}]},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ module.exports = [
'viewport': {
score: 1,
},
'without-javascript': {
score: 1,
},
'installable-manifest': {
score: 1,
details: {items: [pwaRocksExpectations]},
Expand Down
62 changes: 62 additions & 0 deletions lighthouse-core/audits/without-javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license Copyright 2016 The Lighthouse Authors. 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 Audit = require('./audit.js');
const i18n = require('../lib/i18n/i18n.js');

const UIStrings = {
/** Title of a Lighthouse audit that provides detail on the web page's ability to return content with Javascript disabled in the browser. This descriptive title is shown to users when at least some content is shown when Javascript is not available. */
title: 'Contains some content when JavaScript is not available',
/** Title of a Lighthouse audit that provides detail on the web page's ability to return content with Javascript disabled in the browser. This descriptive title is shown to users when no content is shown when Javascript is not available. */
failureTitle: 'Does not provide fallback content when JavaScript is not available',
/** Description of a Lighthouse audit that tells the user why they should return content even if Javascript is unavailable in a browser. This is displayed after a user expands the section to see more. No character length limits. 'Learn More' becomes link text to additional documentation. */
description: 'Your app should display some content when JavaScript is disabled, even if ' +
'it\'s just a warning to the user that JavaScript is required to use the app. ' +
'[Learn more](https://web.dev/without-javascript/).',
/** Message explaining that a website's body should render some (any) content even if the page's JavaScript cannot be loaded. */
explanation: 'The page body should render some content if its scripts are not available.',
};

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);

class WithoutJavaScript extends Audit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'without-javascript',
title: str_(UIStrings.title),
failureTitle: str_(UIStrings.failureTitle),
description: str_(UIStrings.description),
requiredArtifacts: ['HTMLWithoutJavaScript'],
};
}

/**
* @param {LH.Artifacts} artifacts
* @return {LH.Audit.Product}
*/
static audit(artifacts) {
const artifact = artifacts.HTMLWithoutJavaScript;

// Fail pages that have empty text and are missing a noscript tag
if (artifact.bodyText.trim() === '' && !artifact.hasNoScript) {
return {
score: 0,
explanation: str_(UIStrings.explanation),
};
}

return {
score: 1,
};
}
}

module.exports = WithoutJavaScript;
module.exports.UIStrings = UIStrings;
3 changes: 3 additions & 0 deletions lighthouse-core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const defaultConfig = {
blockedUrlPatterns: ['*.css', '*.jpg', '*.jpeg', '*.png', '*.gif', '*.svg', '*.ttf', '*.woff', '*.woff2'],
gatherers: [
'http-redirect',
'html-without-javascript',
],
}],
audits: [
Expand All @@ -191,6 +192,7 @@ const defaultConfig = {
'service-worker',
'works-offline',
'viewport',
'without-javascript',
'metrics/first-contentful-paint',
'metrics/largest-contentful-paint',
'metrics/first-meaningful-paint',
Expand Down Expand Up @@ -620,6 +622,7 @@ const defaultConfig = {
{id: 'themed-omnibox', weight: 1, group: 'pwa-optimized'},
{id: 'content-width', weight: 1, group: 'pwa-optimized'},
{id: 'viewport', weight: 2, group: 'pwa-optimized'},
{id: 'without-javascript', weight: 1, group: 'pwa-optimized'},
{id: 'apple-touch-icon', weight: 1, group: 'pwa-optimized'},
{id: 'maskable-icon', weight: 1, group: 'pwa-optimized'},
// Manual audits
Expand Down
2 changes: 2 additions & 0 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ class Driver {
const waitForLoad = options.waitForLoad || false;
/** @type {Partial<LH.Gatherer.PassContext>} */
const passContext = options.passContext || {};
const disableJS = passContext.disableJavaScript || false;

if (waitForNavigated && (waitForFcp || waitForLoad)) {
throw new Error('Cannot use both waitForNavigated and another event, pick just one');
Expand All @@ -700,6 +701,7 @@ class Driver {

await this.sendCommand('Page.enable');
await this.sendCommand('Page.setLifecycleEventsEnabled', {enabled: true});
await this.sendCommand('Emulation.setScriptExecutionDisabled', {value: disableJS});
// No timeout needed for Page.navigate. See https://github.com/GoogleChrome/lighthouse/pull/6413.
const waitforPageNavigateCmd = this._innerSendCommand('Page.navigate', undefined, {url});

Expand Down
56 changes: 56 additions & 0 deletions lighthouse-core/gather/gatherers/html-without-javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license Copyright 2016 The Lighthouse Authors. 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');

/**
* @fileoverview Returns the innerText of the <body> element while JavaScript is
* disabled.
*/

/* global document */

/* istanbul ignore next */
function getBodyText() {
// note: we use innerText, not textContent, because textContent includes the content of <script> elements!
const body = document.querySelector('body');
return Promise.resolve({
bodyText: body ? body.innerText : '',
hasNoScript: !!document.querySelector('noscript'),
});
}

class HTMLWithoutJavaScript extends Gatherer {
/**
* @param {LH.Gatherer.PassContext} passContext
*/
beforePass(passContext) {
passContext.disableJavaScript = true;
}

/**
* @param {LH.Gatherer.PassContext} passContext
* @return {Promise<LH.Artifacts['HTMLWithoutJavaScript']>}
*/
async afterPass(passContext) {
// Reset the JS disable.
passContext.disableJavaScript = false;

const expression = `(${getBodyText.toString()}())`;
const {bodyText, hasNoScript} = await passContext.driver.evaluateAsync(expression);
if (typeof bodyText !== 'string') {
throw new Error('document body innerText returned by protocol was not a string');
}

return {
bodyText,
hasNoScript,
};
}
}

module.exports = HTMLWithoutJavaScript;
12 changes: 12 additions & 0 deletions lighthouse-core/lib/i18n/locales/ar-XB.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lighthouse-core/lib/i18n/locales/ar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lighthouse-core/lib/i18n/locales/bg.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lighthouse-core/lib/i18n/locales/ca.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lighthouse-core/lib/i18n/locales/cs.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lighthouse-core/lib/i18n/locales/da.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1f80c94

Please sign in to comment.