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,129 @@
|
|
|
1
|
+
# Running Lighthouse on Authenticated Pages with Puppeteer
|
|
2
|
+
|
|
3
|
+
If you just want to view the code for using Lighthouse with Puppeteer, see [example-lh-auth.js](./example-lh-auth.js).
|
|
4
|
+
|
|
5
|
+
See [the integration test docs](../integration-test) for an example of how to run Lighthouse in your Jest tests on pages in both an authenticated and non-authenticated session.
|
|
6
|
+
|
|
7
|
+
## The Example Site
|
|
8
|
+
|
|
9
|
+
There are two pages on the site:
|
|
10
|
+
|
|
11
|
+
1. `/` - the homepage
|
|
12
|
+
2. `/dashboard`
|
|
13
|
+
|
|
14
|
+
The homepage shows the login form, but only to users that are not signed in.
|
|
15
|
+
|
|
16
|
+
The dashboard shows a secret to users that are logged in, but shows an error to users that are not.
|
|
17
|
+
|
|
18
|
+
The server responds with different HTML for each of these pages and session states.
|
|
19
|
+
|
|
20
|
+
(Optional) To run the server:
|
|
21
|
+
```sh
|
|
22
|
+
# be in root lighthouse directory
|
|
23
|
+
yarn # install global project deps
|
|
24
|
+
cd docs/recipes/auth
|
|
25
|
+
yarn # install deps related to just this recipe
|
|
26
|
+
yarn start # start the server on http://localhost:10632
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Now that the server is started, let's login with Puppeteer and then run Lighthouse:
|
|
30
|
+
```sh
|
|
31
|
+
node example-lh-auth.js
|
|
32
|
+
```
|
|
33
|
+
What does this do? Read on....
|
|
34
|
+
|
|
35
|
+
## Process
|
|
36
|
+
|
|
37
|
+
Puppeteer - a browser automation tool - can be used to programatically setup a session.
|
|
38
|
+
|
|
39
|
+
1. Launch a new browser.
|
|
40
|
+
1. Navigate to the login page.
|
|
41
|
+
1. Fill and submit the login form.
|
|
42
|
+
1. Run Lighthouse using the same browser.
|
|
43
|
+
|
|
44
|
+
First, launch Chrome:
|
|
45
|
+
```js
|
|
46
|
+
// This port will be used by Lighthouse later. The specific port is arbitrary.
|
|
47
|
+
const PORT = 8041;
|
|
48
|
+
const browser = await puppeteer.launch({
|
|
49
|
+
args: [`--remote-debugging-port=${PORT}`],
|
|
50
|
+
// Optional, if you want to see the tests in action.
|
|
51
|
+
headless: false,
|
|
52
|
+
slowMo: 50,
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Navigate to the login form:
|
|
57
|
+
```js
|
|
58
|
+
const page = await browser.newPage();
|
|
59
|
+
await page.goto('http://localhost:10632');
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Given a login form like this:
|
|
63
|
+
```html
|
|
64
|
+
<form action="/login" method="post">
|
|
65
|
+
<label>
|
|
66
|
+
Email:
|
|
67
|
+
<input type="email" name="email">
|
|
68
|
+
</label>
|
|
69
|
+
<label>
|
|
70
|
+
Password:
|
|
71
|
+
<input type="password" name="password">
|
|
72
|
+
</label>
|
|
73
|
+
<input type="submit">
|
|
74
|
+
</form>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Direct Puppeteer to fill and submit it:
|
|
78
|
+
```js
|
|
79
|
+
const emailInput = await page.$('input[type="email"]');
|
|
80
|
+
await emailInput.type('admin@example.com');
|
|
81
|
+
const passwordInput = await page.$('input[type="password"]');
|
|
82
|
+
await passwordInput.type('password');
|
|
83
|
+
await Promise.all([
|
|
84
|
+
page.$eval('.login-form', form => form.submit()),
|
|
85
|
+
page.waitForNavigation(),
|
|
86
|
+
]);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
At this point, the session that Puppeteer is managing is now logged in.
|
|
90
|
+
|
|
91
|
+
Close the page used to log in:
|
|
92
|
+
```js
|
|
93
|
+
await page.close();
|
|
94
|
+
// The page has been closed, but the browser still has the relevant session.
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Now run Lighthouse, using the same port as before:
|
|
98
|
+
```js
|
|
99
|
+
// The local server is running on port 10632.
|
|
100
|
+
const url = 'http://localhost:10632/dashboard';
|
|
101
|
+
// Direct Lighthouse to use the same port.
|
|
102
|
+
const result = await lighthouse(url, {port: PORT, disableStorageReset: true});
|
|
103
|
+
const lhr = result.lhr;
|
|
104
|
+
|
|
105
|
+
// Direct Puppeteer to close the browser - we're done with it.
|
|
106
|
+
await browser.close();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
All of the above is done in the example script. To run:
|
|
110
|
+
```sh
|
|
111
|
+
# make sure server is running (see beginning of recipe) ...
|
|
112
|
+
node example-lh-auth.js # login via puppeteer and run lighthouse
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Alternatives
|
|
116
|
+
|
|
117
|
+
### [`page.setCookie`](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetcookiecookies)
|
|
118
|
+
|
|
119
|
+
**NOTE:** We strongly recommend your tests use the form-based login flow above instead. Only directly set the token like this as a last resort.
|
|
120
|
+
|
|
121
|
+
If you don't have user credentials to login but you do have direct access to a token for authentication, you can instead directly set a cookie.
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
await page.setCookie({
|
|
125
|
+
name: 'myAuthCookie',
|
|
126
|
+
value: '<auth token goes here>',
|
|
127
|
+
url: 'http://localhost:10632/dashboard',
|
|
128
|
+
});
|
|
129
|
+
```
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* @fileoverview Example script for running Lighthouse on an authenticated page.
|
|
10
|
+
* See docs/recipes/auth/README.md for more.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const puppeteer = require('puppeteer');
|
|
14
|
+
const lighthouse = require('lighthouse');
|
|
15
|
+
|
|
16
|
+
// This port will be used by Lighthouse later. The specific port is arbitrary.
|
|
17
|
+
const PORT = 8041;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {import('puppeteer').Browser} browser
|
|
21
|
+
* @param {string} origin
|
|
22
|
+
*/
|
|
23
|
+
async function login(browser, origin) {
|
|
24
|
+
const page = await browser.newPage();
|
|
25
|
+
await page.goto(origin);
|
|
26
|
+
await page.waitForSelector('input[type="email"]', {visible: true});
|
|
27
|
+
|
|
28
|
+
// Fill in and submit login form.
|
|
29
|
+
const emailInput = await page.$('input[type="email"]');
|
|
30
|
+
await emailInput.type('admin@example.com');
|
|
31
|
+
const passwordInput = await page.$('input[type="password"]');
|
|
32
|
+
await passwordInput.type('password');
|
|
33
|
+
await Promise.all([
|
|
34
|
+
page.$eval('.login-form', form => form.submit()),
|
|
35
|
+
page.waitForNavigation(),
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
await page.close();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {puppeteer.Browser} browser
|
|
43
|
+
* @param {string} origin
|
|
44
|
+
*/
|
|
45
|
+
async function logout(browser, origin) {
|
|
46
|
+
const page = await browser.newPage();
|
|
47
|
+
await page.goto(`${origin}/logout`);
|
|
48
|
+
await page.close();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function main() {
|
|
52
|
+
// Direct Puppeteer to open Chrome with a specific debugging port.
|
|
53
|
+
const browser = await puppeteer.launch({
|
|
54
|
+
args: [`--remote-debugging-port=${PORT}`],
|
|
55
|
+
// Optional, if you want to see the tests in action.
|
|
56
|
+
headless: false,
|
|
57
|
+
slowMo: 50,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Setup the browser session to be logged into our site.
|
|
61
|
+
await login(browser, 'http://localhost:10632');
|
|
62
|
+
|
|
63
|
+
// The local server is running on port 10632.
|
|
64
|
+
const url = 'http://localhost:10632/dashboard';
|
|
65
|
+
// Direct Lighthouse to use the same port.
|
|
66
|
+
const result = await lighthouse(url, {port: PORT, disableStorageReset: true});
|
|
67
|
+
// Direct Puppeteer to close the browser as we're done with it.
|
|
68
|
+
await browser.close();
|
|
69
|
+
|
|
70
|
+
// Output the result.
|
|
71
|
+
console.log(JSON.stringify(result.lhr, null, 2));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (require.main === module) {
|
|
75
|
+
main();
|
|
76
|
+
} else {
|
|
77
|
+
module.exports = {
|
|
78
|
+
login,
|
|
79
|
+
logout,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
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
|
+
<!DOCTYPE html>
|
|
7
|
+
<html lang="en">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="UTF-8">
|
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
11
|
+
<title>Dashboard - Unauthenticated</title>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
you need to be logged in.
|
|
15
|
+
<style>
|
|
16
|
+
body {
|
|
17
|
+
background-color: #CD5C5C;
|
|
18
|
+
}
|
|
19
|
+
</style>
|
|
20
|
+
</body>
|
|
21
|
+
</html>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
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
|
+
<!DOCTYPE html>
|
|
7
|
+
<html lang="en">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="UTF-8">
|
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
11
|
+
<title>Dashboard</title>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<h1>Dashboard</h1>
|
|
15
|
+
<div>
|
|
16
|
+
secrets here
|
|
17
|
+
</div>
|
|
18
|
+
<a href="/logout">logout</a>
|
|
19
|
+
<style>
|
|
20
|
+
body {
|
|
21
|
+
background-color: green;
|
|
22
|
+
}
|
|
23
|
+
</style>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
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
|
+
<!DOCTYPE html>
|
|
7
|
+
<html lang="en">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="UTF-8">
|
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
11
|
+
<title>Home - Login</title>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<h1>Plz login</h1>
|
|
15
|
+
<form class="login-form" action="/login" method="post">
|
|
16
|
+
<label>
|
|
17
|
+
Email:
|
|
18
|
+
<input type="email" name="email">
|
|
19
|
+
</label>
|
|
20
|
+
<label>
|
|
21
|
+
Password:
|
|
22
|
+
<input type="password" name="password">
|
|
23
|
+
</label>
|
|
24
|
+
<input type="submit">
|
|
25
|
+
</form>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
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
|
+
<!DOCTYPE html>
|
|
7
|
+
<html lang="en">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="UTF-8">
|
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
11
|
+
<title>Home - Logged In</title>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<h1>Welcome home!</h1>
|
|
15
|
+
<span>You are logged in. Go to <a href="/dashboard">the dashboard</a>.</span>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
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
|
+
<!DOCTYPE html>
|
|
7
|
+
<html lang="en">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="UTF-8">
|
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
11
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
12
|
+
<title>Dashboard</title>
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
you need to be logged in.
|
|
16
|
+
<style>
|
|
17
|
+
body {
|
|
18
|
+
background-color: #CD5C5C;
|
|
19
|
+
}
|
|
20
|
+
</style>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* @fileoverview Example Express server for demonstrating how to run Lighthouse on an authenticated
|
|
10
|
+
* page. See docs/recipes/auth/README.md for more.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const createError = require('http-errors');
|
|
14
|
+
const express = require('express');
|
|
15
|
+
const morgan = require('morgan');
|
|
16
|
+
const session = require('express-session');
|
|
17
|
+
const http = require('http');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const PUBLIC_DIR = path.join(__dirname, 'public');
|
|
20
|
+
|
|
21
|
+
const app = express();
|
|
22
|
+
|
|
23
|
+
app.use(morgan('dev'));
|
|
24
|
+
app.use(express.urlencoded({extended: false}));
|
|
25
|
+
|
|
26
|
+
app.use(session({
|
|
27
|
+
secret: 'notverysecret',
|
|
28
|
+
resave: true,
|
|
29
|
+
saveUninitialized: false,
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
app.get('/dashboard', (req, res) => {
|
|
33
|
+
if (req.session.user) {
|
|
34
|
+
res.sendFile('./dashboard.html', {root: PUBLIC_DIR});
|
|
35
|
+
} else {
|
|
36
|
+
res.status(401).sendFile('./dashboard-unauthenticated.html', {root: PUBLIC_DIR});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
app.get('/', (req, res) => {
|
|
41
|
+
if (req.session.user) {
|
|
42
|
+
res.sendFile('home.html', {root: PUBLIC_DIR});
|
|
43
|
+
} else {
|
|
44
|
+
res.sendFile('home-unauthenticated.html', {root: PUBLIC_DIR});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
app.post('/login', (req, res, next) => {
|
|
49
|
+
const {email, password} = req.body;
|
|
50
|
+
// super secret login and password ;)
|
|
51
|
+
if (email !== 'admin@example.com' || password !== 'password') {
|
|
52
|
+
return next(createError(401));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
req.session.user = {
|
|
56
|
+
email,
|
|
57
|
+
};
|
|
58
|
+
res.redirect('/dashboard');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
app.get('/logout', (req, res, next) => {
|
|
62
|
+
req.session.destroy(() => {
|
|
63
|
+
res.redirect('/');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Error handlers
|
|
68
|
+
app.use(function(req, res, next) {
|
|
69
|
+
next(createError(404));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
app.use(function(err, req, res, next) {
|
|
73
|
+
res.locals.message = err.message;
|
|
74
|
+
res.locals.error = err;
|
|
75
|
+
|
|
76
|
+
res.status(err.status || 500);
|
|
77
|
+
res.json({err});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const server = http.createServer(app);
|
|
81
|
+
if (require.main === module) {
|
|
82
|
+
server.listen(10632);
|
|
83
|
+
} else {
|
|
84
|
+
module.exports = server;
|
|
85
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright 2017 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
|
+
module.exports = {
|
|
9
|
+
// 1. Run your custom tests along with all the default Lighthouse tests.
|
|
10
|
+
extends: 'lighthouse:default',
|
|
11
|
+
|
|
12
|
+
// 2. Add gatherer to the default Lighthouse load ('pass') of the page.
|
|
13
|
+
passes: [{
|
|
14
|
+
passName: 'defaultPass',
|
|
15
|
+
gatherers: [
|
|
16
|
+
'searchable-gatherer',
|
|
17
|
+
],
|
|
18
|
+
}],
|
|
19
|
+
|
|
20
|
+
// 3. Add custom audit to the list of audits 'lighthouse:default' will run.
|
|
21
|
+
audits: [
|
|
22
|
+
'searchable-audit',
|
|
23
|
+
],
|
|
24
|
+
|
|
25
|
+
// 4. Create a new 'My site metrics' section in the default report for our results.
|
|
26
|
+
categories: {
|
|
27
|
+
mysite: {
|
|
28
|
+
title: 'My site metrics',
|
|
29
|
+
description: 'Metrics for our super awesome site',
|
|
30
|
+
auditRefs: [
|
|
31
|
+
// When we add more custom audits, `weight` controls how they're averaged together.
|
|
32
|
+
{id: 'searchable-audit', weight: 1},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Basic Custom Audit Recipe
|
|
2
|
+
|
|
3
|
+
> **Tip**: see [Lighthouse Architecture](../../../docs/architecture.md) for information
|
|
4
|
+
on terminology and architecture.
|
|
5
|
+
|
|
6
|
+
## What this example does
|
|
7
|
+
|
|
8
|
+
This example shows how to write a custom Lighthouse audit for a hypothetical search page. The page is considered fully initialized when the main search box (the page's "hero element") is ready to be used. When this happens, the page uses `performance.now()` to mark the time it took to become ready and saves the value in a global variable called `window.myLoadMetrics.searchableTime`.
|
|
9
|
+
|
|
10
|
+
## The Audit, Gatherer, and Config
|
|
11
|
+
|
|
12
|
+
- [searchable-gatherer.js](searchable-gatherer.js) - a [Gatherer](https://github.com/GoogleChrome/lighthouse/blob/master/docs/architecture.md#components--terminology) that collects `window.myLoadMetrics.searchableTime`
|
|
13
|
+
from the context of the page.
|
|
14
|
+
|
|
15
|
+
- [searchable-audit.js](searchable-audit.js) - an [Audit](https://github.com/GoogleChrome/lighthouse/blob/master/docs/architecture.md#components--terminology) that tests whether or not `window.myLoadMetrics.searchableTime`
|
|
16
|
+
stays below a 4000ms threshold. In other words, Lighthouse will consider the audit "passing"
|
|
17
|
+
in the report if the search box initializes within 4s.
|
|
18
|
+
|
|
19
|
+
- [custom-config.js](custom-config.js) - this file tells Lighthouse where to
|
|
20
|
+
find the gatherer and audit files, when to run them, and how to incorporate their
|
|
21
|
+
output into the Lighthouse report. This example extends [Lighthouse's
|
|
22
|
+
default configuration](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/default-config.js).
|
|
23
|
+
|
|
24
|
+
**Note**: when extending the default configuration file, passes with the same name are merged together, all other arrays will be concatenated, and primitive values will override the defaults.
|
|
25
|
+
|
|
26
|
+
## Run the configuration
|
|
27
|
+
|
|
28
|
+
Run Lighthouse with the custom audit by using the `--config-path` flag with your configuration file:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
lighthouse --config-path=custom-config.js https://example.com
|
|
32
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright 2017 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
|
+
const MAX_SEARCHABLE_TIME = 4000;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @fileoverview Tests that `window.myLoadMetrics.searchableTime` was below the
|
|
14
|
+
* test threshold value.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
class LoadAudit extends Audit {
|
|
18
|
+
static get meta() {
|
|
19
|
+
return {
|
|
20
|
+
id: 'searchable-audit',
|
|
21
|
+
title: 'Search box initialized and ready',
|
|
22
|
+
failureTitle: 'Search box slow to initialize',
|
|
23
|
+
description: 'Used to measure time to when the search' +
|
|
24
|
+
' box is initialized and ready to search.',
|
|
25
|
+
|
|
26
|
+
// The name of the custom gatherer class that provides input to this audit.
|
|
27
|
+
requiredArtifacts: ['TimeToSearchable'],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static audit(artifacts) {
|
|
32
|
+
const loadMetrics = artifacts.TimeToSearchable;
|
|
33
|
+
|
|
34
|
+
// Audit will pass when the search box loaded in less time than our threshold.
|
|
35
|
+
// This score will be binary, so will get a red ✘ or green ✓ in the report.
|
|
36
|
+
const belowThreshold = loadMetrics.searchableTime <= MAX_SEARCHABLE_TIME;
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
numericValue: loadMetrics.searchableTime,
|
|
40
|
+
// Cast true/false to 1/0
|
|
41
|
+
score: Number(belowThreshold),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = LoadAudit;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright 2017 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 Gatherer = require('lighthouse').Gatherer;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @fileoverview Extracts `window.myLoadMetrics` from the test page.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
class TimeToSearchable extends Gatherer {
|
|
15
|
+
afterPass(options) {
|
|
16
|
+
const driver = options.driver;
|
|
17
|
+
|
|
18
|
+
return driver.executionContext.evaluateAsync('window.myLoadMetrics')
|
|
19
|
+
// Ensure returned value is what we expect.
|
|
20
|
+
.then(loadMetrics => {
|
|
21
|
+
if (!loadMetrics || loadMetrics.searchableTime === undefined) {
|
|
22
|
+
// Throw if page didn't provide the metrics we expect. This isn't
|
|
23
|
+
// fatal -- the Lighthouse run will continue, but any audits that
|
|
24
|
+
// depend on this gatherer will show this error string in the report.
|
|
25
|
+
throw new Error('Unable to find load metrics in page');
|
|
26
|
+
}
|
|
27
|
+
return loadMetrics;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = TimeToSearchable;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
const Audit = require('lighthouse').Audit;
|
|
9
|
+
|
|
10
|
+
class CustomAudit extends Audit {
|
|
11
|
+
static get meta() {
|
|
12
|
+
return {
|
|
13
|
+
id: 'custom-audit',
|
|
14
|
+
title: 'First text input field accepts `123` as input',
|
|
15
|
+
failureTitle: 'First text input field doesn\'t accept `123` as input',
|
|
16
|
+
description: 'Example custom audit which relies on a fancy gatherer.',
|
|
17
|
+
|
|
18
|
+
// The name of the custom gatherer class that provides input to this audit.
|
|
19
|
+
requiredArtifacts: ['CustomGatherer'],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static audit(artifacts) {
|
|
24
|
+
const value = artifacts.CustomGatherer.value;
|
|
25
|
+
const success = value === '123';
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
// Cast true/false to 1/0
|
|
29
|
+
score: Number(success),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = CustomAudit;
|
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright
|
|
2
|
+
* @license Copyright 2020 The Lighthouse Authors. All Rights Reserved.
|
|
3
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
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
5
|
*/
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
|
-
module.exports
|
|
8
|
+
module.exports = {
|
|
9
|
+
passes: [{
|
|
10
|
+
passName: 'defaultPass',
|
|
11
|
+
gatherers: [
|
|
12
|
+
'custom-gatherer',
|
|
13
|
+
],
|
|
14
|
+
}],
|
|
15
|
+
|
|
16
|
+
audits: [
|
|
17
|
+
'custom-audit',
|
|
18
|
+
],
|
|
19
|
+
|
|
20
|
+
categories: {
|
|
21
|
+
mysite: {
|
|
22
|
+
title: 'My custom audit',
|
|
23
|
+
description: 'Super awesome, strings included',
|
|
24
|
+
auditRefs: [
|
|
25
|
+
{id: 'custom-audit', weight: 1},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|