lighthouse 8.0.0-dev.20210709 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/architecture.md +101 -0
- package/docs/authenticated-pages.md +44 -0
- package/docs/bug-labels.md +35 -0
- package/docs/configuration.md +213 -0
- package/docs/emulation.md +32 -0
- package/docs/error-reporting.md +42 -0
- package/docs/hacking-tips.md +55 -0
- package/docs/headless-chrome.md +119 -0
- package/docs/lantern.md +55 -0
- package/docs/new-audits.md +99 -0
- package/docs/performance-budgets.md +187 -0
- package/docs/plugins.md +374 -0
- package/docs/puppeteer.md +95 -0
- package/docs/readme.md +164 -0
- package/docs/recipes/auth/README.md +129 -0
- package/docs/recipes/auth/example-lh-auth.js +81 -0
- package/docs/recipes/auth/package.json +11 -0
- package/docs/recipes/auth/server/public/dashboard-unauthenticated.html +21 -0
- package/docs/recipes/auth/server/public/dashboard.html +25 -0
- package/docs/recipes/auth/server/public/home-unauthenticated.html +27 -0
- package/docs/recipes/auth/server/public/home.html +17 -0
- package/docs/recipes/auth/server/public/unauthenticated.html +22 -0
- package/docs/recipes/auth/server/server.js +85 -0
- package/docs/recipes/custom-audit/custom-config.js +36 -0
- package/docs/recipes/custom-audit/package.json +8 -0
- package/docs/recipes/custom-audit/readme.md +32 -0
- package/docs/recipes/custom-audit/searchable-audit.js +46 -0
- package/docs/recipes/custom-audit/searchable-gatherer.js +32 -0
- package/docs/recipes/custom-gatherer-puppeteer/custom-audit.js +34 -0
- package/{root.js → docs/recipes/custom-gatherer-puppeteer/custom-config.js} +23 -2
- package/docs/recipes/custom-gatherer-puppeteer/custom-gatherer.js +51 -0
- package/docs/recipes/custom-gatherer-puppeteer/package.json +13 -0
- package/docs/recipes/custom-gatherer-puppeteer/readme.md +7 -0
- package/docs/recipes/custom-gatherer-puppeteer/test.sh +9 -0
- package/docs/recipes/gulp/gulpfile.js +79 -0
- package/docs/recipes/gulp/package.json +12 -0
- package/docs/recipes/gulp/public/index.html +22 -0
- package/docs/recipes/gulp/readme.md +6 -0
- package/docs/recipes/integration-test/README.md +14 -0
- package/docs/recipes/integration-test/example-lh-auth.test.js +160 -0
- package/docs/recipes/integration-test/package.json +9 -0
- package/docs/recipes/lighthouse-plugin-example/audits/preload-as.js +46 -0
- package/docs/recipes/lighthouse-plugin-example/package.json +11 -0
- package/docs/recipes/lighthouse-plugin-example/plugin-recipe-screenshot.png +0 -0
- package/docs/recipes/lighthouse-plugin-example/plugin.js +24 -0
- package/docs/recipes/lighthouse-plugin-example/readme.md +53 -0
- package/docs/releasing.md +164 -0
- package/docs/scoring.md +79 -0
- package/docs/throttling.md +150 -0
- package/docs/understanding-results.md +209 -0
- package/docs/v8-perf-faq.md +244 -0
- package/docs/variability.md +150 -0
- package/jest.config.js +0 -3
- package/lighthouse-cli/bin.js +8 -6
- package/lighthouse-core/audits/accessibility/aria-command-name.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-meter-name.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-progressbar-name.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-tooltip-name.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-treeitem-name.js +1 -1
- package/lighthouse-core/audits/apple-touch-icon.js +0 -1
- package/lighthouse-core/audits/audit.js +3 -3
- package/lighthouse-core/audits/autocomplete.js +2 -2
- package/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +14 -29
- package/lighthouse-core/audits/byte-efficiency/duplicated-javascript.js +2 -3
- package/lighthouse-core/audits/byte-efficiency/efficient-animated-content.js +1 -1
- package/lighthouse-core/audits/byte-efficiency/legacy-javascript.js +2 -3
- package/lighthouse-core/audits/byte-efficiency/modern-image-formats.js +15 -55
- package/lighthouse-core/audits/byte-efficiency/offscreen-images.js +4 -8
- package/lighthouse-core/audits/byte-efficiency/render-blocking-resources.js +8 -15
- package/lighthouse-core/audits/byte-efficiency/total-byte-weight.js +9 -10
- package/lighthouse-core/audits/byte-efficiency/unminified-css.js +1 -1
- package/lighthouse-core/audits/byte-efficiency/unminified-javascript.js +1 -1
- package/lighthouse-core/audits/byte-efficiency/unused-css-rules.js +1 -1
- package/lighthouse-core/audits/byte-efficiency/unused-javascript.js +1 -2
- package/lighthouse-core/audits/byte-efficiency/uses-long-cache-ttl.js +2 -2
- package/lighthouse-core/audits/byte-efficiency/uses-optimized-images.js +1 -2
- package/lighthouse-core/audits/byte-efficiency/uses-responsive-images.js +24 -46
- package/lighthouse-core/audits/byte-efficiency/uses-text-compression.js +1 -1
- package/lighthouse-core/audits/critical-request-chains.js +0 -1
- package/lighthouse-core/audits/csp-xss.js +1 -1
- package/lighthouse-core/audits/diagnostics.js +0 -1
- package/lighthouse-core/audits/dobetterweb/geolocation-on-start.js +0 -1
- package/lighthouse-core/audits/dobetterweb/inspector-issues.js +1 -1
- package/lighthouse-core/audits/dobetterweb/notification-on-start.js +0 -1
- package/lighthouse-core/audits/dobetterweb/uses-http2.js +0 -1
- package/lighthouse-core/audits/final-screenshot.js +4 -8
- package/lighthouse-core/audits/font-display.js +0 -1
- package/lighthouse-core/audits/installable-manifest.js +3 -4
- package/lighthouse-core/audits/largest-contentful-paint-element.js +0 -1
- package/lighthouse-core/audits/long-tasks.js +1 -1
- package/lighthouse-core/audits/maskable-icon.js +0 -1
- package/lighthouse-core/audits/metrics/first-contentful-paint-3g.js +2 -4
- package/lighthouse-core/audits/metrics/first-contentful-paint.js +2 -4
- package/lighthouse-core/audits/metrics/first-meaningful-paint.js +2 -4
- package/lighthouse-core/audits/metrics/interactive.js +2 -4
- package/lighthouse-core/audits/metrics/largest-contentful-paint.js +2 -4
- package/lighthouse-core/audits/metrics/max-potential-fid.js +2 -4
- package/lighthouse-core/audits/metrics/speed-index.js +2 -4
- package/lighthouse-core/audits/metrics/total-blocking-time.js +2 -10
- package/lighthouse-core/audits/metrics.js +2 -4
- package/lighthouse-core/audits/performance-budget.js +0 -1
- package/lighthouse-core/audits/predictive-perf.js +6 -9
- package/lighthouse-core/audits/preload-fonts.js +1 -11
- package/lighthouse-core/audits/preload-lcp-image.js +5 -18
- package/lighthouse-core/audits/redirects.js +8 -10
- package/lighthouse-core/audits/screenshot-thumbnails.js +13 -28
- package/lighthouse-core/audits/seo/canonical.js +1 -2
- package/lighthouse-core/audits/seo/font-size.js +4 -4
- package/lighthouse-core/audits/seo/hreflang.js +2 -3
- package/lighthouse-core/audits/seo/http-status-code.js +16 -21
- package/lighthouse-core/audits/seo/is-crawlable.js +3 -4
- package/lighthouse-core/audits/seo/robots-txt.js +2 -2
- package/lighthouse-core/audits/seo/tap-targets.js +5 -5
- package/lighthouse-core/audits/server-response-time.js +2 -20
- package/lighthouse-core/audits/splash-screen.js +0 -1
- package/lighthouse-core/audits/themed-omnibox.js +0 -1
- package/lighthouse-core/audits/third-party-facades.js +0 -1
- package/lighthouse-core/audits/third-party-summary.js +3 -1
- package/lighthouse-core/audits/timing-budget.js +2 -4
- package/lighthouse-core/audits/uses-rel-preconnect.js +9 -14
- package/lighthouse-core/audits/uses-rel-preload.js +2 -13
- package/lighthouse-core/computed/main-thread-tasks.js +2 -2
- package/lighthouse-core/computed/metrics/cumulative-layout-shift.js +3 -3
- package/lighthouse-core/computed/metrics/first-contentful-paint-all-frames.js +6 -6
- package/lighthouse-core/computed/metrics/first-contentful-paint.js +8 -9
- package/lighthouse-core/computed/metrics/first-meaningful-paint.js +9 -10
- package/lighthouse-core/computed/metrics/interactive.js +24 -25
- package/lighthouse-core/computed/metrics/lantern-first-contentful-paint.js +6 -6
- package/lighthouse-core/computed/metrics/lantern-first-meaningful-paint.js +6 -6
- package/lighthouse-core/computed/metrics/lantern-largest-contentful-paint.js +6 -6
- package/lighthouse-core/computed/metrics/lantern-metric.js +8 -16
- package/lighthouse-core/computed/metrics/largest-contentful-paint-all-frames.js +7 -7
- package/lighthouse-core/computed/metrics/largest-contentful-paint.js +9 -10
- package/lighthouse-core/computed/metrics/max-potential-fid.js +11 -8
- package/lighthouse-core/computed/metrics/metric.js +5 -32
- package/lighthouse-core/computed/metrics/speed-index.js +5 -6
- package/lighthouse-core/computed/metrics/timing-summary.js +45 -55
- package/lighthouse-core/computed/metrics/total-blocking-time.js +29 -36
- package/lighthouse-core/computed/page-dependency-graph.js +14 -14
- package/lighthouse-core/computed/resource-summary.js +7 -3
- package/lighthouse-core/computed/speedline.js +3 -3
- package/lighthouse-core/computed/trace-of-tab.js +86 -15
- package/lighthouse-core/computed/user-timings.js +5 -5
- package/lighthouse-core/config/default-config.js +0 -1
- package/lighthouse-core/fraggle-rock/config/config.js +7 -9
- package/lighthouse-core/fraggle-rock/config/default-config.js +2 -40
- package/lighthouse-core/fraggle-rock/config/filters.js +6 -39
- package/lighthouse-core/fraggle-rock/config/validation.js +4 -4
- package/lighthouse-core/fraggle-rock/gather/base-artifacts.js +19 -54
- package/lighthouse-core/fraggle-rock/gather/navigation-runner.js +10 -21
- package/lighthouse-core/fraggle-rock/gather/runner-helpers.js +2 -2
- package/lighthouse-core/fraggle-rock/gather/snapshot-runner.js +2 -2
- package/lighthouse-core/fraggle-rock/gather/timespan-runner.js +2 -2
- package/lighthouse-core/gather/driver/prepare.js +0 -3
- package/lighthouse-core/gather/fetcher.js +2 -0
- package/lighthouse-core/gather/gather-runner.js +14 -2
- package/lighthouse-core/gather/gatherers/image-elements.js +61 -24
- package/lighthouse-core/gather/gatherers/inspector-issues.js +2 -2
- package/lighthouse-core/gather/gatherers/script-elements.js +12 -45
- package/lighthouse-core/gather/gatherers/seo/font-size.js +5 -5
- package/lighthouse-core/gather/gatherers/seo/tap-targets.js +12 -64
- package/lighthouse-core/gather/gatherers/service-worker.js +3 -20
- package/lighthouse-core/gather/gatherers/trace-compat.js +1 -1
- package/lighthouse-core/gather/gatherers/trace-elements.js +3 -15
- package/lighthouse-core/gather/gatherers/trace.js +4 -13
- package/lighthouse-core/gather/gatherers/viewport-dimensions.js +1 -1
- package/lighthouse-core/lib/dependency-graph/simulator/network-analyzer.js +2 -13
- package/lighthouse-core/lib/emulation.js +2 -0
- package/lighthouse-core/lib/i18n/i18n.js +2 -2
- package/lighthouse-core/lib/i18n/locales/ar-XB.json +141 -141
- package/lighthouse-core/lib/i18n/locales/ar.json +143 -143
- package/lighthouse-core/lib/i18n/locales/bg.json +143 -143
- package/lighthouse-core/lib/i18n/locales/ca.json +141 -141
- package/lighthouse-core/lib/i18n/locales/cs.json +141 -141
- package/lighthouse-core/lib/i18n/locales/da.json +141 -141
- package/lighthouse-core/lib/i18n/locales/de.json +142 -142
- package/lighthouse-core/lib/i18n/locales/el.json +141 -141
- package/lighthouse-core/lib/i18n/locales/en-GB.json +141 -141
- package/lighthouse-core/lib/i18n/locales/en-US.ctc.json +6659 -0
- package/lighthouse-core/lib/i18n/locales/en-US.json +144 -150
- package/lighthouse-core/lib/i18n/locales/en-XA.json +141 -141
- package/lighthouse-core/lib/i18n/locales/en-XL.ctc.json +6628 -0
- package/lighthouse-core/lib/i18n/locales/en-XL.json +144 -150
- package/lighthouse-core/lib/i18n/locales/es-419.json +141 -141
- package/lighthouse-core/lib/i18n/locales/es.json +141 -141
- package/lighthouse-core/lib/i18n/locales/fi.json +143 -143
- package/lighthouse-core/lib/i18n/locales/fil.json +142 -142
- package/lighthouse-core/lib/i18n/locales/fr.json +141 -141
- package/lighthouse-core/lib/i18n/locales/he.json +142 -142
- package/lighthouse-core/lib/i18n/locales/hi.json +143 -143
- package/lighthouse-core/lib/i18n/locales/hr.json +141 -141
- package/lighthouse-core/lib/i18n/locales/hu.json +143 -143
- package/lighthouse-core/lib/i18n/locales/id.json +143 -143
- package/lighthouse-core/lib/i18n/locales/it.json +143 -143
- package/lighthouse-core/lib/i18n/locales/ja.json +143 -143
- package/lighthouse-core/lib/i18n/locales/ko.json +143 -143
- package/lighthouse-core/lib/i18n/locales/lt.json +143 -143
- package/lighthouse-core/lib/i18n/locales/lv.json +143 -143
- package/lighthouse-core/lib/i18n/locales/nl.json +141 -141
- package/lighthouse-core/lib/i18n/locales/no.json +141 -141
- package/lighthouse-core/lib/i18n/locales/pl.json +141 -141
- package/lighthouse-core/lib/i18n/locales/pt-PT.json +141 -141
- package/lighthouse-core/lib/i18n/locales/pt.json +141 -141
- package/lighthouse-core/lib/i18n/locales/ro.json +144 -144
- package/lighthouse-core/lib/i18n/locales/ru.json +143 -143
- package/lighthouse-core/lib/i18n/locales/sk.json +142 -142
- package/lighthouse-core/lib/i18n/locales/sl.json +141 -141
- package/lighthouse-core/lib/i18n/locales/sr-Latn.json +143 -143
- package/lighthouse-core/lib/i18n/locales/sr.json +143 -143
- package/lighthouse-core/lib/i18n/locales/sv.json +142 -142
- package/lighthouse-core/lib/i18n/locales/ta.json +141 -141
- package/lighthouse-core/lib/i18n/locales/te.json +143 -143
- package/lighthouse-core/lib/i18n/locales/th.json +143 -143
- package/lighthouse-core/lib/i18n/locales/tr.json +143 -143
- package/lighthouse-core/lib/i18n/locales/uk.json +141 -141
- package/lighthouse-core/lib/i18n/locales/vi.json +143 -143
- package/lighthouse-core/lib/i18n/locales/zh-HK.json +141 -141
- package/lighthouse-core/lib/i18n/locales/zh-TW.json +143 -143
- package/lighthouse-core/lib/i18n/locales/zh.json +143 -143
- package/lighthouse-core/lib/lh-error.js +2 -2
- package/lighthouse-core/lib/minify-trace.js +1 -1
- package/lighthouse-core/lib/network-request.js +1 -17
- package/lighthouse-core/lib/page-functions.js +5 -6
- package/lighthouse-core/lib/rect-helpers.js +3 -3
- package/lighthouse-core/lib/sd-validation/assets/jsonldcontext.json +7137 -0
- package/lighthouse-core/lib/sd-validation/assets/schema-tree.json +9900 -0
- package/{report/report-assets.js → lighthouse-core/lib/sd-validation/helpers/walk-object.js} +20 -12
- package/lighthouse-core/lib/sd-validation/json-expander.js +56 -0
- package/lighthouse-core/lib/sd-validation/json-linter.js +49 -0
- package/lighthouse-core/lib/sd-validation/jsonld-keyword-validator.js +50 -0
- package/lighthouse-core/lib/sd-validation/line-number-from-jsonld-path.js +60 -0
- package/lighthouse-core/lib/sd-validation/schema-validator.js +146 -0
- package/lighthouse-core/lib/sd-validation/scripts/download-jsonldcontext.js +30 -0
- package/lighthouse-core/lib/sd-validation/scripts/generate-schema-tree.js +97 -0
- package/lighthouse-core/lib/sd-validation/sd-validation.js +77 -0
- package/lighthouse-core/lib/tappable-rects.js +1 -1
- package/lighthouse-core/lib/tracehouse/trace-processor.js +42 -116
- package/lighthouse-core/lib/url-shim.js +2 -29
- package/lighthouse-core/report/html/html-report-assets.js +38 -0
- package/{report/README.md → lighthouse-core/report/html/readme.md} +11 -7
- package/{report → lighthouse-core/report/html}/renderer/category-renderer.js +0 -0
- package/{report → lighthouse-core/report/html}/renderer/crc-details-renderer.js +0 -0
- package/{report → lighthouse-core/report/html}/renderer/details-renderer.js +1 -1
- package/{report → lighthouse-core/report/html}/renderer/dom.js +0 -0
- package/{report → lighthouse-core/report/html}/renderer/element-screenshot-renderer.js +0 -0
- package/{report → lighthouse-core/report/html}/renderer/i18n.js +1 -1
- package/{report → lighthouse-core/report/html}/renderer/logger.js +0 -0
- package/{report → lighthouse-core/report/html}/renderer/performance-category-renderer.js +0 -0
- package/{report → lighthouse-core/report/html}/renderer/psi.js +0 -0
- package/{report → lighthouse-core/report/html}/renderer/pwa-category-renderer.js +0 -0
- package/{report → lighthouse-core/report/html}/renderer/report-renderer.js +0 -0
- package/{report → lighthouse-core/report/html}/renderer/report-ui-features.js +3 -3
- package/{report → lighthouse-core/report/html}/renderer/snippet-renderer.js +0 -0
- package/{report → lighthouse-core/report/html}/renderer/text-encoding.js +0 -0
- package/{report → lighthouse-core/report/html}/renderer/util.js +4 -7
- package/{report/assets/styles.css → lighthouse-core/report/html/report-styles.css} +0 -0
- package/{report/assets/standalone-template.html → lighthouse-core/report/html/report-template.html} +41 -1
- package/{report/assets → lighthouse-core/report/html}/templates.html +0 -0
- package/{report → lighthouse-core/report}/report-generator.js +1 -1
- package/lighthouse-core/runner.js +1 -1
- package/package.json +12 -13
- package/readme.md +2 -2
- package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +2 -3
- package/third-party/chromium-synchronization/installability-errors-test.js +2 -2
- package/third-party/download-content-shell/download-content-shell.js +1 -2
- package/third-party/snyk/snapshot.json +1 -1
- package/tsconfig.json +1 -0
- package/types/artifacts.d.ts +21 -41
- package/types/audit.d.ts +0 -2
- package/types/config.d.ts +2 -16
- package/types/externs.d.ts +0 -1
- package/types/gatherer.d.ts +13 -13
- package/types/html-renderer.d.ts +14 -14
- package/types/i18n.d.ts +1 -1
- package/lighthouse-core/audits/byte-efficiency/uses-responsive-images-snapshot.js +0 -94
- package/lighthouse-core/computed/image-records.js +0 -62
- package/lighthouse-core/computed/metrics/navigation-metric.js +0 -46
- package/lighthouse-core/computed/processed-navigation.js +0 -21
- package/lighthouse-core/computed/processed-trace.js +0 -21
- package/lighthouse-core/gather/gatherers/gather-context.js +0 -25
- package/lighthouse-core/gather/gatherers/host-form-factor.js +0 -31
- package/lighthouse-core/gather/gatherers/host-user-agent.js +0 -29
- package/lighthouse-core/lib/lh-trace-processor.js +0 -46
- package/report/clients/standalone.js +0 -52
- package/report/test/renderer/category-renderer-test.js +0 -488
- package/report/test/renderer/crc-details-renderer-test.js +0 -115
- package/report/test/renderer/details-renderer-test.js +0 -843
- package/report/test/renderer/dom-test.js +0 -157
- package/report/test/renderer/element-screenshot-renderer-test.js +0 -189
- package/report/test/renderer/i18n-test.js +0 -146
- package/report/test/renderer/performance-category-renderer-test.js +0 -332
- package/report/test/renderer/psi-test.js +0 -152
- package/report/test/renderer/pwa-category-renderer-test.js +0 -303
- package/report/test/renderer/report-renderer-test.js +0 -325
- package/report/test/renderer/report-ui-features-test.js +0 -572
- package/report/test/renderer/snippet-renderer-test.js +0 -291
- package/report/test/renderer/text-encoding-test.js +0 -41
- package/report/test/renderer/util-test.js +0 -388
- package/report/test/report-generator-test.js +0 -145
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright 2020 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
+
* 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
|
|
4
|
+
* 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.
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/* global document */
|
|
9
|
+
|
|
10
|
+
const Gatherer = require('lighthouse').Gatherer;
|
|
11
|
+
const Puppeteer = require('puppeteer-core');
|
|
12
|
+
|
|
13
|
+
async function connect(driver) {
|
|
14
|
+
const browser = await Puppeteer.connect({
|
|
15
|
+
browserWSEndpoint: await driver.wsEndpoint(),
|
|
16
|
+
defaultViewport: null,
|
|
17
|
+
});
|
|
18
|
+
const {targetInfo} = await driver.sendCommand('Target.getTargetInfo');
|
|
19
|
+
const puppeteerTarget = (await browser.targets())
|
|
20
|
+
.find(target => target._targetId === targetInfo.targetId);
|
|
21
|
+
const page = await puppeteerTarget.page();
|
|
22
|
+
return {browser, page, executionContext: driver.executionContext};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class CustomGatherer extends Gatherer {
|
|
26
|
+
async afterPass(options) {
|
|
27
|
+
const {driver} = options;
|
|
28
|
+
const {page, executionContext} = await connect(driver);
|
|
29
|
+
|
|
30
|
+
// Inject an input field for our debugging pleasure.
|
|
31
|
+
function makeInput() {
|
|
32
|
+
const el = document.createElement('input');
|
|
33
|
+
el.type = 'number';
|
|
34
|
+
document.body.append(el);
|
|
35
|
+
}
|
|
36
|
+
await executionContext.evaluate(makeInput, {args: []});
|
|
37
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
38
|
+
|
|
39
|
+
// Prove that `driver` (Lighthouse) and `page` (Puppeteer) are talking to the same page.
|
|
40
|
+
await executionContext.evaluateAsync(`document.querySelector('input').value = '1'`);
|
|
41
|
+
await page.type('input', '23', {delay: 300});
|
|
42
|
+
const value = await executionContext.evaluateAsync(`document.querySelector('input').value`);
|
|
43
|
+
if (value !== '123') throw new Error('huh?');
|
|
44
|
+
|
|
45
|
+
// No need to close the browser or page. Puppeteer doesn't own either of them.
|
|
46
|
+
|
|
47
|
+
return {value};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = CustomGatherer;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Make sure we're in this `docs/recipes/customer-gatherer-puppeteer` directory
|
|
4
|
+
cd "$(dirname "$0")"
|
|
5
|
+
|
|
6
|
+
yarn
|
|
7
|
+
node node_modules/.bin/lighthouse --config-path=custom-config.js https://www.example.com --output=json |
|
|
8
|
+
jq '.audits["custom-audit"].score' |
|
|
9
|
+
grep -q 1
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @license Copyright 2017 The Lighthouse Authors. All Rights Reserved.
|
|
5
|
+
* 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
|
|
6
|
+
* 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.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const gulp = require('gulp');
|
|
10
|
+
const connect = require('gulp-connect');
|
|
11
|
+
const lighthouse = require('lighthouse');
|
|
12
|
+
const chromeLauncher = require('chrome-launcher');
|
|
13
|
+
const PORT = 8080;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Start server
|
|
17
|
+
*/
|
|
18
|
+
const startServer = function() {
|
|
19
|
+
return connect.server({
|
|
20
|
+
root: './public',
|
|
21
|
+
port: PORT,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Stop server
|
|
27
|
+
*/
|
|
28
|
+
const stopServer = function() {
|
|
29
|
+
connect.serverClose();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Run lighthouse
|
|
34
|
+
*/
|
|
35
|
+
function launchChromeAndRunLighthouse(url, flags, config = null) {
|
|
36
|
+
return chromeLauncher.launch().then(chrome => {
|
|
37
|
+
flags.port = chrome.port;
|
|
38
|
+
return lighthouse(url, flags, config).then(results =>
|
|
39
|
+
chrome.kill().then(() => results)
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Handle ok result
|
|
46
|
+
* @param {Object} results - Lighthouse results
|
|
47
|
+
*/
|
|
48
|
+
const handleOk = function(results) {
|
|
49
|
+
stopServer();
|
|
50
|
+
console.log(results); // eslint-disable-line no-console
|
|
51
|
+
// TODO: use lighthouse results for checking your performance expectations.
|
|
52
|
+
// e.g. process.exit(1) or throw Error if score falls below a certain threshold.
|
|
53
|
+
// if (results.audits['first-meaningful-paint'].numericValue > 3000) {
|
|
54
|
+
// console.log(`Warning: Time to first meaningful paint ${results.audits['first-meaningful-paint'].displayValue}`);
|
|
55
|
+
// process.exit(1);
|
|
56
|
+
// }
|
|
57
|
+
return results;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Handle error
|
|
62
|
+
*/
|
|
63
|
+
const handleError = function(e) {
|
|
64
|
+
stopServer();
|
|
65
|
+
console.error(e); // eslint-disable-line no-console
|
|
66
|
+
throw e; // Throw to exit process with status 1.
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const flags = {}; // available options - https://github.com/GoogleChrome/lighthouse/#cli-options
|
|
70
|
+
|
|
71
|
+
gulp.task('lighthouse', function() {
|
|
72
|
+
startServer();
|
|
73
|
+
const config = {settings: {onlyCategories: ['performance']}};
|
|
74
|
+
return launchChromeAndRunLighthouse(`http://localhost:${PORT}/index.html`, flags, config)
|
|
75
|
+
.then(handleOk)
|
|
76
|
+
.catch(handleError);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
gulp.task('default', ['lighthouse']);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<!--
|
|
3
|
+
* Copyright 2017 The Lighthouse Authors. All Rights Reserved.
|
|
4
|
+
* 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
|
|
5
|
+
* 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.
|
|
6
|
+
-->
|
|
7
|
+
<html>
|
|
8
|
+
<head>
|
|
9
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
|
|
10
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.css">
|
|
11
|
+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
|
|
12
|
+
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
|
|
13
|
+
<script src="https://code.jquery.com/ui/jquery-ui-git.js"></script>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
|
|
17
|
+
<h1>Slow page</h1>
|
|
18
|
+
|
|
19
|
+
<img src="https://cloud.githubusercontent.com/assets/238208/21210165/b3c368c0-c22d-11e6-91fb-aa24959e2637.png">
|
|
20
|
+
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Running Lighthouse on in Your Integration Jest Tests
|
|
2
|
+
|
|
3
|
+
See [example-lh-auth.test.js](./example-lh-auth.test.js) for an example of how to run Lighthouse in your Jest tests on pages in both an authenticated and non-authenticated session. This recipe builds on the [auth docs](../auth).
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
# Be in this folder: docs/recipes/integration-test
|
|
7
|
+
|
|
8
|
+
# Install deps.
|
|
9
|
+
yarn
|
|
10
|
+
yarn --cwd ../auth
|
|
11
|
+
|
|
12
|
+
# Test.
|
|
13
|
+
yarn test
|
|
14
|
+
```
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright 2019 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
+
* 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
|
|
4
|
+
* 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.
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/* eslint-env jest */
|
|
9
|
+
/* eslint-disable new-cap */
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @fileoverview Example Jest tests for demonstrating how to run Lighthouse on an authenticated
|
|
13
|
+
* page as integration tests. See docs/recipes/auth/README.md for more.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** @typedef {import('lighthouse/types/lhr')} LH */
|
|
17
|
+
|
|
18
|
+
const puppeteer = require('puppeteer');
|
|
19
|
+
const lighthouse = require('lighthouse');
|
|
20
|
+
const server = require('../auth/server/server.js');
|
|
21
|
+
const {login, logout} = require('../auth/example-lh-auth.js');
|
|
22
|
+
|
|
23
|
+
const CHROME_DEBUG_PORT = 8042;
|
|
24
|
+
const SERVER_PORT = 10632;
|
|
25
|
+
const ORIGIN = `http://localhost:${SERVER_PORT}`;
|
|
26
|
+
|
|
27
|
+
jest.setTimeout(30000);
|
|
28
|
+
|
|
29
|
+
// Provide a nice way to assert a score for a category.
|
|
30
|
+
// Note, you could just use `expect(lhr.categories.seo.score).toBeGreaterThanOrEqual(0.9)`,
|
|
31
|
+
// but by using a custom matcher a better error report is generated.
|
|
32
|
+
expect.extend({
|
|
33
|
+
toHaveLighthouseScoreGreaterThanOrEqual(lhr, category, threshold) {
|
|
34
|
+
const score = lhr.categories[category].score;
|
|
35
|
+
const auditsRefsByWeight = [...lhr.categories[category].auditRefs]
|
|
36
|
+
.filter((auditRef) => auditRef.weight > 0)
|
|
37
|
+
.sort((a, b) => b.weight - a.weight);
|
|
38
|
+
const report = auditsRefsByWeight.map((auditRef) => {
|
|
39
|
+
const audit = lhr.audits[auditRef.id];
|
|
40
|
+
const status = audit.score === 1 ?
|
|
41
|
+
this.utils.EXPECTED_COLOR('○') :
|
|
42
|
+
this.utils.RECEIVED_COLOR('✕');
|
|
43
|
+
const weight = this.utils.DIM_COLOR(`[weight: ${auditRef.weight}]`);
|
|
44
|
+
return `\t${status} ${weight} ${audit.id}`;
|
|
45
|
+
}).join('\n');
|
|
46
|
+
|
|
47
|
+
if (score >= threshold) {
|
|
48
|
+
return {
|
|
49
|
+
pass: true,
|
|
50
|
+
message: () =>
|
|
51
|
+
`expected category ${category} to be < ${threshold}, but got ${score}\n${report}`,
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
return {
|
|
55
|
+
pass: false,
|
|
56
|
+
message: () =>
|
|
57
|
+
`expected category ${category} to be >= ${threshold}, but got ${score}\n${report}`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} url
|
|
65
|
+
* @return {Promise<LH.Result>}
|
|
66
|
+
*/
|
|
67
|
+
async function runLighthouse(url) {
|
|
68
|
+
const result = await lighthouse(url, {
|
|
69
|
+
port: CHROME_DEBUG_PORT,
|
|
70
|
+
disableStorageReset: true,
|
|
71
|
+
onlyCategories: ['seo'],
|
|
72
|
+
});
|
|
73
|
+
return result.lhr;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
describe('my site', () => {
|
|
77
|
+
/** @type {import('puppeteer').Browser} */
|
|
78
|
+
let browser;
|
|
79
|
+
/** @type {import('puppeteer').Page} */
|
|
80
|
+
let page;
|
|
81
|
+
|
|
82
|
+
beforeAll(async () => {
|
|
83
|
+
await new Promise(resolve => server.listen(SERVER_PORT, resolve));
|
|
84
|
+
browser = await puppeteer.launch({
|
|
85
|
+
args: [`--remote-debugging-port=${CHROME_DEBUG_PORT}`],
|
|
86
|
+
headless: !process.env.DEBUG,
|
|
87
|
+
slowMo: process.env.DEBUG ? 50 : undefined,
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
afterAll(async () => {
|
|
92
|
+
await browser.close();
|
|
93
|
+
await new Promise(resolve => server.close(resolve));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
beforeEach(async () => {
|
|
97
|
+
page = await browser.newPage();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
afterEach(async () => {
|
|
101
|
+
await page.close();
|
|
102
|
+
await logout(browser, ORIGIN);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('/ logged out', () => {
|
|
106
|
+
it('lighthouse', async () => {
|
|
107
|
+
await page.goto(ORIGIN);
|
|
108
|
+
const lhr = await runLighthouse(page.url());
|
|
109
|
+
expect(lhr).toHaveLighthouseScoreGreaterThanOrEqual('seo', 0.9);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('login form should exist', async () => {
|
|
113
|
+
await page.goto(ORIGIN);
|
|
114
|
+
const emailInput = await page.$('input[type="email"]');
|
|
115
|
+
const passwordInput = await page.$('input[type="password"]');
|
|
116
|
+
expect(emailInput).toBeTruthy();
|
|
117
|
+
expect(passwordInput).toBeTruthy();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('/ logged in', () => {
|
|
122
|
+
it('lighthouse', async () => {
|
|
123
|
+
await login(browser, ORIGIN);
|
|
124
|
+
await page.goto(ORIGIN);
|
|
125
|
+
const lhr = await runLighthouse(page.url());
|
|
126
|
+
expect(lhr).toHaveLighthouseScoreGreaterThanOrEqual('seo', 0.9);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('login form should not exist', async () => {
|
|
130
|
+
await login(browser, ORIGIN);
|
|
131
|
+
await page.goto(ORIGIN);
|
|
132
|
+
const emailInput = await page.$('input[type="email"]');
|
|
133
|
+
const passwordInput = await page.$('input[type="password"]');
|
|
134
|
+
expect(emailInput).toBeFalsy();
|
|
135
|
+
expect(passwordInput).toBeFalsy();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('/dashboard logged out', () => {
|
|
140
|
+
it('has no secrets', async () => {
|
|
141
|
+
await page.goto(`${ORIGIN}/dashboard`);
|
|
142
|
+
expect(await page.content()).not.toContain('secrets');
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('/dashboard logged in', () => {
|
|
147
|
+
it('lighthouse', async () => {
|
|
148
|
+
await login(browser, ORIGIN);
|
|
149
|
+
await page.goto(`${ORIGIN}/dashboard`);
|
|
150
|
+
const lhr = await runLighthouse(page.url());
|
|
151
|
+
expect(lhr).toHaveLighthouseScoreGreaterThanOrEqual('seo', 0.9);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('has secrets', async () => {
|
|
155
|
+
await login(browser, ORIGIN);
|
|
156
|
+
await page.goto(`${ORIGIN}/dashboard`);
|
|
157
|
+
expect(await page.content()).toContain('secrets');
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright 2019 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
+
* 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
|
|
4
|
+
* 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.
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const Audit = require('lighthouse').Audit;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @fileoverview A fake additional check of the robots.txt file.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// https://fetch.spec.whatwg.org/#concept-request-destination
|
|
15
|
+
const allowedTypes = new Set(['font', 'image', 'script', 'serviceworker', 'style', 'worker']);
|
|
16
|
+
|
|
17
|
+
class PreloadAsAudit extends Audit {
|
|
18
|
+
static get meta() {
|
|
19
|
+
return {
|
|
20
|
+
id: 'preload-as',
|
|
21
|
+
title: 'Preloaded requests have proper `as` attributes',
|
|
22
|
+
failureTitle: 'Some preloaded requests do not have proper `as` attributes',
|
|
23
|
+
description: '`<link rel=preload>` tags need an `as` attribute to specify the type of ' +
|
|
24
|
+
'content being loaded.',
|
|
25
|
+
|
|
26
|
+
// The name of the artifact provides input to this audit.
|
|
27
|
+
requiredArtifacts: ['LinkElements'],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static audit(artifacts) {
|
|
32
|
+
// Check that all `<link rel=preload>` elements had a defined `as` attribute.
|
|
33
|
+
const preloadLinks = artifacts.LinkElements.filter(el => el.rel === 'preload');
|
|
34
|
+
const noAsLinks = preloadLinks.filter(el => !allowedTypes.has(el.as));
|
|
35
|
+
|
|
36
|
+
// Audit passes if there are no missing attributes.
|
|
37
|
+
const passed = noAsLinks.length === 0;
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
score: passed ? 1 : 0,
|
|
41
|
+
displayValue: `Found ${noAsLinks.length} preload requests with missing \`as\` attributes`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = PreloadAsAudit;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright 2019 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
+
* 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
|
|
4
|
+
* 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.
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/** @type {LH.Config.Plugin} */
|
|
9
|
+
module.exports = {
|
|
10
|
+
// Additional audit to run on information Lighthouse gathered.
|
|
11
|
+
audits: [{
|
|
12
|
+
path: 'lighthouse-plugin-example/audits/preload-as.js',
|
|
13
|
+
}],
|
|
14
|
+
|
|
15
|
+
// A new category in the report for the new audit's output.
|
|
16
|
+
category: {
|
|
17
|
+
title: 'My Plugin Category',
|
|
18
|
+
description: 'Results for our new plugin category.',
|
|
19
|
+
auditRefs: [
|
|
20
|
+
{id: 'preload-as', weight: 1},
|
|
21
|
+
{id: 'meta-description', weight: 1}, // Can also reference default Lighthouse audits.
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Lighthouse plugin recipe
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
- `package.json` - declares the plugin's entry point (`plugin.js`)
|
|
5
|
+
- `plugin.js` - instructs Lighthouse to run the plugin's own `preload-as.js` audit; describes the new category and its details for the report
|
|
6
|
+
- `audits/preload-as.js` - the new audit to run in addition to Lighthouse's default audits
|
|
7
|
+
|
|
8
|
+
## To develop as a plugin developer
|
|
9
|
+
|
|
10
|
+
Run the following to start of with the recipe as a template:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
mkdir lighthouse-plugin-example && cd lighthouse-plugin-example
|
|
14
|
+
curl -L https://github.com/GoogleChrome/lighthouse/archive/master.zip | tar -xzv
|
|
15
|
+
mv lighthouse-master/docs/recipes/lighthouse-plugin-example/* ./
|
|
16
|
+
rm -rf lighthouse-master
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Install and run just your plugin:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
yarn
|
|
23
|
+
NODE_PATH=.. yarn lighthouse https://example.com --plugins=lighthouse-plugin-example --only-categories=lighthouse-plugin-example --view
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
When you rename the plugin, be sure to rename its directory as well.
|
|
27
|
+
|
|
28
|
+
### Iterating
|
|
29
|
+
To speed up development, you can gather once and iterate by auditing repeatedly.
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
# Gather artifacts from the browser
|
|
33
|
+
NODE_PATH=.. yarn lighthouse https://example.com --plugins=lighthouse-plugin-example --only-categories=lighthouse-plugin-example --gather-mode
|
|
34
|
+
|
|
35
|
+
# and then iterate re-running this:
|
|
36
|
+
NODE_PATH=.. yarn lighthouse https://example.com --plugins=lighthouse-plugin-example --only-categories=lighthouse-plugin-example --audit-mode --view
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Finally, publish to NPM.
|
|
40
|
+
|
|
41
|
+
## To run as a plugin user
|
|
42
|
+
|
|
43
|
+
1. Install `lighthouse` (v5+) and the plugin `lighthouse-plugin-example`, likely as `devDependencies`.
|
|
44
|
+
* `npm install -D lighthouse lighthouse-plugin-example`
|
|
45
|
+
1. To run your private lighthouse binary, you have three options
|
|
46
|
+
1. `npx --no-install lighthouse https://example.com --plugins=lighthouse-plugin-example --view`
|
|
47
|
+
1. `yarn lighthouse https://example.com --plugins=lighthouse-plugin-example --view`
|
|
48
|
+
1. Add an npm script calling `lighthouse` and run that.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Result
|
|
52
|
+
|
|
53
|
+

|