├── .editorconfig
├── .github
├── linters
│ ├── .eslintrc.yml
│ ├── .markdown-lint.yml
│ └── .yaml-lint.yml
├── pull_request_template.md
└── workflows
│ ├── linter.yml
│ └── wpt-test.yml
├── .gitignore
├── .markdownlintignore
├── LICENSE
├── README.md
├── bin
└── create-fugu-apis.js
├── dist
├── 00_reset.js
├── Colordepth.js
├── Dpi.js
├── Images.js
├── Resolution.js
├── a11y.js
├── ads.js
├── almanac.js
├── aurora.js
├── avg_dom_depth.js
├── cms.js
├── cookies.js
├── crawl_links.js
├── css-variables.js
├── css.js
├── doctype.js
├── document_height.js
├── document_width.js
├── ecommerce.js
├── element_count.js
├── event-names.js
├── fugu-apis.js
├── generated-content.js
├── has_shadow_root.js
├── img-loading-attr.js
├── initiators.js
├── inline_style_bytes.js
├── javascript.js
├── lib-detector-version.js
├── localstorage_size.js
├── markup.js
├── media.js
├── meta_viewport.js
├── num_iframes.js
├── num_scripts.js
├── num_scripts_async.js
├── num_scripts_sync.js
├── observers.js
├── origin-trials.js
├── parsed_css.js
├── performance.js
├── privacy-sandbox.js
├── privacy.js
├── pwa.js
├── quirks_mode.js
├── responsive_images.js
├── robots_meta.js
├── robots_txt.js
├── sass.js
├── security.js
├── sessionstorage_size.js
├── structured-data.js
├── test_result.js
├── third-parties.js
├── usertiming.js
├── valid-head.js
├── well-known.js
└── wpt_bodies.js
├── inject-dist
├── README.md
├── aurora.js
└── observers.js.bak
├── metric-summary.md
├── package-lock.json
├── package.json
└── tests
├── unit-tests.test.js
└── wpt.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | end_of_line = lf
7 | charset = utf-8
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 | [*.{html,md,js,css,sql}]
12 | indent_size = 2
13 |
14 | [*.py]
15 | indent_size = 4
16 |
--------------------------------------------------------------------------------
/.github/linters/.eslintrc.yml:
--------------------------------------------------------------------------------
1 | ---
2 | env:
3 | browser: true
4 | es6: true
5 | jest: true
6 | node: true
7 |
8 | extends:
9 | - "eslint:recommended"
10 |
11 | globals:
12 | $WPT_ACCESSIBILITY_TREE: readonly
13 | $WPT_BODIES: readonly
14 | $WPT_COOKIES: readonly
15 | $WPT_DNS: readonly
16 | $WPT_REQUESTS: readonly
17 | $WPT_TEST_URL: readonly
18 | httparchive_enable_observations: writable
19 | __REACT_DEVTOOLS_GLOBAL_HOOK__: writable
20 | CSSUnparsedValue: readonly
21 | LaunchParams: readonly
22 |
23 | ignorePatterns:
24 | - "!.*"
25 | - "**/node_modules/.*"
26 | - "/dist/third-parties.js"
27 |
28 | plugins:
29 | - n
30 | - prettier
31 |
32 | rules:
33 | no-inner-declarations: off
34 |
35 | overrides:
36 | # JSON files
37 | - files:
38 | - "*.json"
39 | extends:
40 | - plugin:jsonc/recommended-with-json
41 | parser: jsonc-eslint-parser
42 | parserOptions:
43 | jsonSyntax: JSON
44 |
45 | # JSONC files
46 | - files:
47 | - "*.jsonc"
48 | extends:
49 | - plugin:jsonc/recommended-with-jsonc
50 | parser: jsonc-eslint-parser
51 | parserOptions:
52 | jsonSyntax: JSONC
53 |
54 | # JSON5 files
55 | - files:
56 | - "*.json5"
57 | extends:
58 | - plugin:jsonc/recommended-with-json5
59 | parser: jsonc-eslint-parser
60 | parserOptions:
61 | jsonSyntax: JSON5
62 |
63 | # Javascript files
64 | - files:
65 | - "**/*.js"
66 | extends:
67 | - "plugin:react/recommended"
68 | parserOptions:
69 | ecmaVersion: latest
70 |
71 | - files:
72 | - "**/*.mjs"
73 | - "**/*.cjs"
74 | - "**/*.jsx"
75 | extends:
76 | - "plugin:react/recommended"
77 | parserOptions:
78 | sourceType: module
79 | ecmaVersion: latest
80 | ecmaFeatures:
81 | jsx: true
82 | modules: true
83 |
84 | # TypeScript files
85 | - files:
86 | - "**/*.ts"
87 | - "**/*.cts"
88 | - "**/*.mts"
89 | - "**/*.tsx"
90 | extends:
91 | - "plugin:@typescript-eslint/recommended"
92 | - plugin:n/recommended
93 | - plugin:react/recommended
94 | - prettier
95 | parser: "@typescript-eslint/parser"
96 | plugins:
97 | - "@typescript-eslint"
98 | parserOptions:
99 | ecmaVersion: latest
100 | sourceType: module
101 |
--------------------------------------------------------------------------------
/.github/linters/.markdown-lint.yml:
--------------------------------------------------------------------------------
1 | ---
2 | ###########################
3 | ###########################
4 | ## Markdown Linter rules ##
5 | ###########################
6 | ###########################
7 |
8 | # Linter rules doc:
9 | # - https://github.com/DavidAnson/markdownlint
10 | #
11 | # Note:
12 | # To comment out a single error:
13 | #
14 | # any violations you want
15 | #
16 | #
17 |
18 | ignore:
19 | - ".github/pull_request_template.md"
20 |
21 | ###############
22 | # Rules by id #
23 | ###############
24 | MD004: false # Unordered list style
25 | MD007: false # Allow extra spaces for lists - don't cause issues and will just annoy authors
26 | MD009: false # Allow trailing spaces - don't cause issues and will just annoy authors
27 | MD013: false # Don't demand maximum line lengths
28 | MD024:
29 | siblings_only: true # Allows sub-headings to be reused under different headings
30 | MD026:
31 | punctuation: ".,;:。,;:" # List of not allowed
32 | MD029: false # Ordered list item prefix
33 | MD033: false # Allow inline HTML
34 | MD034: false # Allow base URLs
35 | MD036: false # Emphasis used instead of a heading
36 | MD037: false # Checks for no spaces in emphasis but subject to false positives so turn off
37 | MD040: false # Don't demand language for all code blocks
38 | MD049: false # Allow _ or * to be used for emphasis
39 |
40 | #################
41 | # Rules by tags #
42 | #################
43 | blank_lines: false # Error on blank lines
44 |
--------------------------------------------------------------------------------
/.github/linters/.yaml-lint.yml:
--------------------------------------------------------------------------------
1 | ---
2 | ########################################################
3 | # HTTP Archive Overrides for YAML Lint #
4 | # https://yamllint.readthedocs.io/en/stable/rules.html #
5 | ########################################################
6 | rules:
7 | document-start: disable
8 | line-length:
9 | max: 120
10 | indentation:
11 | indent-sequences: whatever
12 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 |
2 | Resolves \#1
3 |
4 | Description of the changes...
5 |
6 | ---
7 |
8 | **Test websites**:
9 |
10 | - https://example.com/
11 |
--------------------------------------------------------------------------------
/.github/workflows/linter.yml:
--------------------------------------------------------------------------------
1 | ---
2 | #################################
3 | #################################
4 | ## Super Linter GitHub Actions ##
5 | #################################
6 | #################################
7 | name: Lint Code Base
8 |
9 | #
10 | # Documentation:
11 | # https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
12 | #
13 |
14 | #############################
15 | # Start the job on all push #
16 | #############################
17 | on:
18 | workflow_dispatch:
19 | pull_request:
20 | push:
21 | branches:
22 | - main
23 |
24 | ###############
25 | # Set the Job #
26 | ###############
27 | jobs:
28 | build:
29 | # Name the Job
30 | name: Lint Code Base
31 | # Set the agent to run on
32 | runs-on: ubuntu-latest
33 |
34 | ##################
35 | # Load all steps #
36 | ##################
37 | steps:
38 | ##########################
39 | # Checkout the code base #
40 | ##########################
41 | - name: Checkout Code
42 | uses: actions/checkout@v4
43 | with:
44 | # Full git history is needed to get a proper list of changed files within `super-linter`
45 | fetch-depth: 0
46 |
47 | ##################################################
48 | # For PRs we only lint changed files for speed. #
49 | # For others we want to lint the whole codebase. #
50 | ##################################################
51 | - name: Set VALIDATE_ALL_CODEBASE variable to false
52 | # Only run the full workflow for manual runs or if upgrading the super linter
53 | if: |
54 | github.event_name != 'workflow_dispatch' &&
55 | startsWith(github.event.pull_request.title,'Bump github/super-linter') != true
56 | run: |
57 | echo "VALIDATE_ALL_CODEBASE=false" >> $GITHUB_ENV
58 |
59 | ################################
60 | # Run Linter against code base #
61 | ################################
62 | - name: Lint Code Base
63 | uses: super-linter/super-linter/slim@v7
64 | env:
65 | DEFAULT_BRANCH: main
66 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67 | VALIDATE_JAVASCRIPT_ES: true
68 | VALIDATE_EDITORCONFIG: true
69 | VALIDATE_MARKDOWN: true
70 | VALIDATE_YAML: true
71 |
--------------------------------------------------------------------------------
/.github/workflows/wpt-test.yml:
--------------------------------------------------------------------------------
1 | name: Tests
2 |
3 | on:
4 | pull_request_target:
5 | branches:
6 | - main
7 | paths-ignore:
8 | - "**/*.md"
9 | workflow_dispatch:
10 |
11 | jobs:
12 | test:
13 | name: WebPageTest Test Cases
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout
17 | uses: actions/checkout@v4
18 | with:
19 | ref: ${{ github.event.pull_request.head.sha }}
20 | fetch-depth: 0
21 |
22 | - name: Install dependencies
23 | run: npm install jest webpagetest
24 |
25 | - name: Run WebPageTest with unit tests
26 | run: npm test
27 | env:
28 | WPT_SERVER: "webpagetest.httparchive.org"
29 | WPT_API_KEY: ${{ secrets.HA_API_KEY }}
30 |
31 | - name: Run WebPageTest for more websites
32 | run: node tests/wpt.js
33 | env:
34 | WPT_SERVER: "webpagetest.httparchive.org"
35 | WPT_API_KEY: ${{ secrets.HA_API_KEY }}
36 | PR_BODY: ${{ github.event.pull_request.body }}
37 |
38 | - name: Add comment to PR
39 | uses: mshick/add-pr-comment@v2
40 | if: always()
41 | with:
42 | refresh-message-position: true
43 | message-path: comment.md
44 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | .DS_Store
3 | **/.DS_Store
4 | .env
5 |
--------------------------------------------------------------------------------
/.markdownlintignore:
--------------------------------------------------------------------------------
1 | # ignore github markdown files (like pull request templates)
2 | .github/*.md
3 | .github/**/*.md
4 |
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Custom metrics
2 |
3 | ## Adding a new custom metric
4 |
5 | HTTP Archive uses WebPageTest (WPT) to collect information about how web pages are built. WPT is able to run arbitrary JavaScript at the end of a test to collect specific data, known as custom metrics. See the [WPT custom metrics documentation](https://docs.webpagetest.org/custom-metrics/) for more info.
6 |
7 | To add a new custom metric to HTTP Archive:
8 |
9 | 0. Select the appropriate `js` file. Some custom metrics are small and single-purpose while others return many metrics for a given topic, like [`media.js`](./dist/media.js) and [`almanac.js`](./dist/almanac.js). Create a new file if you're not sure where your script belongs.
10 |
11 | 1. For scripts that return a JSON object, the key should be named according to what it's measuring, for example `meta-nodes` returns an array of all `` nodes and their attributes:
12 |
13 | ```js
14 | return JSON.stringify({
15 | 'meta-nodes': (() => {
16 | // Returns a JSON array of meta nodes and their key/value attributes.
17 | var nodes = document.querySelectorAll('head meta');
18 | var metaNodes = parseNodes(nodes);
19 |
20 | return metaNodes;
21 | })(),
22 |
23 | // check if there is any picture tag containing an img tag
24 | 'has_picture_img': document.querySelectorAll('picture img').length > 0
25 | });
26 | ```
27 |
28 | 2. Test your changes on WPT using the workflow below.
29 |
30 | 3. Submit a pull request. Include one or more links to test results in your PR description to verify that the script is working.
31 |
32 | ## Custom WPT data objects
33 |
34 | The following objects are available for use in custom metrics:
35 |
36 | - `$WPT_REQUESTS` - All request data except for bodies (significantly smaller)
37 | - `$WPT_BODIES` - All request data including bodies in the "response_body" entry
38 | - `$WPT_ACCESSIBILITY_TREE` - Array of the nodes of the Chromium Accessibility tree (with the DOM node info recorded in node_info for each node in the array)
39 | - `$WPT_COOKIES` - Array of cookies set by the page
40 | - `$WPT_DNS` - Array of DNS records for the page
41 |
42 | More details can be found in the [WPT custom metrics documentation](https://docs.webpagetest.org/custom-metrics/).
43 |
44 | You can explore them by running WPT with the following custom metric:
45 |
46 | ```js
47 | [custom_wpt_objects]
48 | return {
49 | requests: $WPT_REQUESTS,
50 | bodies: $WPT_BODIES,
51 | accessibility: $WPT_ACCESSIBILITY_TREE,
52 | cookies: $WPT_COOKIES,
53 | dns: $WPT_DNS
54 | };
55 | ```
56 |
57 | ## Testing
58 |
59 | ### Manual testing using webpagetest.org website
60 |
61 | To test a custom metric, for example [`doctype.js`](https://github.com/HTTPArchive/legacy.httparchive.org/blob/master/custom_metrics/doctype.js), you can enter the script directly on [webpagetest.org](https://webpagetest.org?debug=1) under the "Custom" tab.
62 |
63 | 
64 |
65 | Note that all WPT custom metrics must have `[metricName]` at the start of the script. This is excluded in the HTTP Archive code and generated automatically based on the file name, so you will need to manually ensure that it's set.
66 |
67 | If you include the `debug=1` parameter on the WPT home page, for example [https://webpagetest.org?debug=1](https://webpagetest.org?debug=1), the test results will include a raw debug log from the agent including the devtools commands to run the custom metrics (and any handled exceptions).
68 | The log ouput can be found in the main results page to the left of the waterfall. For each run there will be a link for the "debug log" (next to the timeline and trace links).
69 |
70 | To see the custom metric results, select a run, first click on "Details", and then on the "Custom Metrics" link in the top right corner:
71 |
72 | 
73 |
74 | 
75 |
76 | For complex metrics like [almanac.js](./dist/almanac.js) you can more easily explore the results by copy/pasting the JSON into your browser console.
77 |
78 | ### Automated WPT test runs
79 |
80 | 1. WPT tests are running using [WPT API wrapper](https://github.com/webpagetest/webpagetest-api).
81 | 2. Test runs are using a private WPT instance, set by the `WPT_HOST` environment variable.
82 | 3. By default, WebAlmanac website is used for testing in every PR.
83 | 4. PR author can define a list of websites to test additionally, by using a markdown list as shown in [PR template](https://github.com/HTTPArchive/custom-metrics/blob/main/.github/PULL_REQUEST_TEMPLATE/custom_metrics_pr_template.md).
84 |
85 | ### Unit tests
86 |
87 | 1. Unit tests are using [Jest Testing Framework](https://jestjs.io/).
88 | 2. Open [`unit-tests.test.js`](./tests/unit-tests.test.js) file and add test cases for the custom metrics.
89 | 3. `wpt_data` variable contains is an object with custom metrics values parsed from WPT response.
90 |
91 | ## Linting
92 |
93 | On opening a Pull Request we will do some basic linting of JavaScript using [ESLint](https://eslint.org/) through the [GitHub Super-Linter](https://github.com/github/super-linter).
94 |
95 | You can run this locally with the following commands:
96 |
97 | ```sh
98 | docker pull github/super-linter:slim-latest
99 | docker run -e RUN_LOCAL=true -e VALIDATE_JAVASCRIPT_ES=true -e VALIDATE_MARKDOWN=true -e USE_FIND_ALGORITHM=true -v $PWD/custom_metrics:/tmp/lint github/super-linter:slim-latest
100 | ```
101 |
--------------------------------------------------------------------------------
/bin/create-fugu-apis.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 |
3 | const patterns = fs.readFileSync('./node_modules/fugu-api-data/patterns.js', {encoding: 'utf-8'});
4 |
5 | const script = `
6 | const responseBodies = $WPT_BODIES;
7 |
8 | // To avoid to match on, e.g., blog posts that contain the patterns,
9 | // ensure that the file names fulfill certain conditions as a heuristic.
10 | // Note that this leaves a slight risk of excluding inline \`