@capagents/forgeqe 3.1.1 → 3.1.2
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/HOW_TO_USE.md +435 -78
- package/README.md +21 -6
- package/THIRD_PARTY_NOTICES.md +210 -1
- package/dist/docs-site/CREDITS.md +6 -0
- package/dist/docs-site/architecture-map/index.html +1 -1
- package/dist/docs-site/docs/app-theme.css +100 -8
- package/dist/docs-site/docs/architecture/index.html +210 -214
- package/dist/docs-site/docs/area-api/index.html +350 -0
- package/dist/docs-site/docs/area-automated-tests/index.html +967 -0
- package/dist/docs-site/docs/area-browser/index.html +430 -0
- package/dist/docs-site/docs/area-data/index.html +605 -0
- package/dist/docs-site/docs/area-desktop/index.html +755 -0
- package/dist/docs-site/docs/area-mobile/index.html +631 -0
- package/dist/docs-site/docs/area-operations/index.html +1069 -0
- package/dist/docs-site/docs/area-pull-requests/index.html +208 -0
- package/dist/docs-site/docs/area-quality/index.html +365 -0
- package/dist/docs-site/docs/area-release/index.html +320 -0
- package/dist/docs-site/docs/area-setup/index.html +1192 -0
- package/dist/docs-site/docs/area-systems/index.html +207 -0
- package/dist/docs-site/docs/area-test-cases/index.html +694 -0
- package/dist/docs-site/docs/containers/index.html +97 -104
- package/dist/docs-site/docs/cost-architecture/index.html +108 -112
- package/dist/docs-site/docs/custom-agents-first-run/index.html +19 -23
- package/dist/docs-site/docs/desktop/index.html +172 -162
- package/dist/docs-site/docs/desktop-ci/index.html +26 -33
- package/dist/docs-site/docs/evidence/index.html +253 -257
- package/dist/docs-site/docs/feature-test-prompts/index.html +66 -70
- package/dist/docs-site/docs/get-started/index.html +495 -0
- package/dist/docs-site/docs/graphify/index.html +42 -46
- package/dist/docs-site/docs/guardrails/index.html +17 -21
- package/dist/docs-site/docs/index.html +17 -6729
- package/dist/docs-site/docs/mobile/index.html +155 -162
- package/dist/docs-site/docs/model-routing/index.html +44 -51
- package/dist/docs-site/docs/overview/index.html +176 -0
- package/dist/docs-site/docs/product-graph/index.html +52 -55
- package/dist/docs-site/docs/product-knowledge/index.html +11 -15
- package/dist/docs-site/docs/product-views/index.html +53 -57
- package/dist/docs-site/docs/reference/index.html +379 -0
- package/dist/docs-site/docs/search.js +1 -1
- package/dist/docs-site/docs/using/index.html +480 -0
- package/dist/docs-site/docs/web-app/index.html +147 -93
- package/dist/docs-site/security/index.html +930 -0
- package/dist/docs-site/security/security-theme.css +161 -0
- package/dist/docs-site/security/security.js +1465 -0
- package/dist/docs-site/vendor/react-18.3.1.production.min.js +31 -0
- package/dist/docs-site/vendor/react-dom-18.3.1.production.min.js +267 -0
- package/dist/docs-site/vendor/reactflow-11.11.4.umd.js +10 -0
- package/dist/forgeqe.js +1902 -1895
- package/dist/web/THIRD_PARTY_NOTICES.md +0 -136
- package/dist/web/assets/Agent-CPhmZdFX.js +8 -0
- package/dist/web/assets/AgentWork-BXdN9xgi.js +2 -0
- package/dist/web/assets/ApiTests-Do3xLjfB.js +10 -0
- package/dist/web/assets/Browse-WVkJT6Bs.js +2 -0
- package/dist/web/assets/Chat-CDc9UcQX.js +3 -0
- package/dist/web/assets/CommandPalette-BAZm62lV.js +1 -0
- package/dist/web/assets/Compare-Br6n9T9L.js +1 -0
- package/dist/web/assets/Cost-BBUyBu3Y.js +1 -0
- package/dist/web/assets/Data-Ch2DPEWp.js +6 -0
- package/dist/web/assets/Desktop-Qzoq-cQv.js +1 -0
- package/dist/web/assets/DesktopReview-CF_jQYAM.js +1 -0
- package/dist/web/assets/Evidence-C72Lj5_Q.js +1 -0
- package/dist/web/assets/Explore-ObkEpUyS.js +2 -0
- package/dist/web/assets/Features-CQzNo_WP.js +1 -0
- package/dist/web/assets/Flags-0-RniPJm.js +2 -0
- package/dist/web/assets/Flaky-BPJvNLCA.js +1 -0
- package/dist/web/assets/Impact-CfccsL_k.js +3 -0
- package/dist/web/assets/Jobs-T6m4zhDy.js +5 -0
- package/dist/web/assets/KindPage-BDUvWe2p.js +6 -0
- package/dist/web/assets/Migration-Dqeh4x5u.js +2 -0
- package/dist/web/assets/PageAgent-DNjzIgeY.js +1 -0
- package/dist/web/assets/Product-nYV_scOV.js +7 -0
- package/dist/web/assets/Production-CGSbEWVa.js +1 -0
- package/dist/web/assets/Quality-BIypojZm.js +1 -0
- package/dist/web/assets/Readiness-BlRjwJRg.js +1 -0
- package/dist/web/assets/Record-v2KLI-_Z.js +1 -0
- package/dist/web/assets/Regression-B-jSt4Jz.js +5 -0
- package/dist/web/assets/RelationGraph-8J98lOVG.js +1 -0
- package/dist/web/assets/Reports-GI4u6SyW.js +2 -0
- package/dist/web/assets/Response-mhBThq2b.js +9 -0
- package/dist/web/assets/Responsive-DXu7Ra7K.js +3 -0
- package/dist/web/assets/RunDiff-D0SHDNp0.js +1 -0
- package/dist/web/assets/Runs-C1Gjdi9M.js +2 -0
- package/dist/web/assets/Settings-BGGeuvyF.js +21 -0
- package/dist/web/assets/Steps-D-YG0eJy.js +2 -0
- package/dist/web/assets/TestCases-DC4w77eQ.js +1 -0
- package/dist/web/assets/TestData-CvKWRVVV.js +2 -0
- package/dist/web/assets/TestDebt-D8YzN29_.js +1 -0
- package/dist/web/assets/TestManagement-C5cDCqrD.js +1 -0
- package/dist/web/assets/Tosca-BGUv3RiJ.js +3 -0
- package/dist/web/assets/WhatsNew-B_Gyuv8O.js +1 -0
- package/dist/web/assets/agents-C0Jg2pN8.js +1 -0
- package/dist/web/assets/coverage-BMP6ELFJ.js +5 -0
- package/dist/web/assets/dataParts-DbeCj9ga.js +3 -0
- package/dist/web/assets/diff-BStuTmsN.js +2 -0
- package/dist/web/assets/families-BBFFrUlo.js +1 -0
- package/dist/web/assets/filters-CnAMr286.js +1 -0
- package/dist/web/assets/fold-D_O_VZui.js +1 -0
- package/dist/web/assets/head-CRo48rPt.js +1 -0
- package/dist/web/assets/highlight-BcFZIf59.js +4 -0
- package/dist/web/assets/index-B3JsM7tv.js +64 -0
- package/dist/web/assets/index-CafApcbZ.css +2 -0
- package/dist/web/assets/input-CtzK50ZF.js +1 -0
- package/dist/web/assets/jsx-runtime-LKYXHABd.js +1 -0
- package/dist/web/assets/line-icons-rdF8DYDJ.js +1 -0
- package/dist/web/assets/logos-D4oVWzqa.js +1 -0
- package/dist/web/assets/palette-DAaGSao7.js +1 -0
- package/dist/web/assets/paletteCommands-Co-RlQ8q.js +1 -0
- package/dist/web/assets/parts-D357Wolo.js +1 -0
- package/dist/web/assets/productParts-B8oHRCJF.js +1 -0
- package/dist/web/assets/qualityParts-BLkmIfDY.js +1 -0
- package/dist/web/assets/recordTest-Cez2sDJO.js +1 -0
- package/dist/web/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/web/assets/route-BloYJWgw.js +1 -0
- package/dist/web/index.html +12 -6
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/BASAL.md +1 -1
- package/docs/DESKTOP.md +20 -1
- package/docs/EVIDENCE.md +1 -1
- package/docs/MOBILE.md +4 -4
- package/docs/PRODUCT_KNOWLEDGE.md +2 -0
- package/docs/WEB_APP.md +114 -51
- package/docs/user-guide.html +404 -81
- package/forgeqe.example.yaml +3 -3
- package/package.json +1 -1
- package/prompts/page-differs.md +1 -1
- package/prompts/requests-rule.md +1 -1
- package/prompts/test-reviewer.md +1 -1
- package/prompts/test-rules.md +3 -4
- package/skills/web-guidance/LICENSE +202 -0
- package/skills/web-guidance/SKILL.md +76 -0
- package/skills/web-guidance/UPSTREAM +67 -0
- package/skills/web-guidance/references/accessibility/accessibility.md +585 -0
- package/skills/web-guidance/references/accessibility/accessible-error-announcement.md +302 -0
- package/skills/web-guidance/references/accessibility/accessible-generated-content.md +41 -0
- package/skills/web-guidance/references/accessibility/respect-os-text-scale.md +127 -0
- package/skills/web-guidance/references/css/responsive-design.md +16 -0
- package/skills/web-guidance/references/forms/autofill-address-form.md +86 -0
- package/skills/web-guidance/references/forms/autofill-payment-form.md +142 -0
- package/skills/web-guidance/references/forms/autofill-sign-in-form.md +145 -0
- package/skills/web-guidance/references/forms/autofill-sign-up-form.md +155 -0
- package/skills/web-guidance/references/forms/forms.md +415 -0
- package/skills/web-guidance/references/forms/ime-safe-enter-submit.md +115 -0
- package/skills/web-guidance/references/forms/required-field-feedback.md +317 -0
- package/skills/web-guidance/references/forms/select-menu-interaction.md +310 -0
- package/skills/web-guidance/references/forms/slider.md +184 -0
- package/skills/web-guidance/references/forms/sms-otp-form.md +208 -0
- package/skills/web-guidance/references/forms/switch.md +60 -0
- package/skills/web-guidance/references/forms/validate-input-after-interaction.md +406 -0
- package/skills/web-guidance/references/performance/break-up-long-tasks.md +64 -0
- package/skills/web-guidance/references/performance/identify-heavy-scripts.md +69 -0
- package/skills/web-guidance/references/performance/identify-inp-causes.md +105 -0
- package/skills/web-guidance/references/performance/interaction-paint-timing.md +200 -0
- package/skills/web-guidance/references/performance/optimize-image-priority.md +73 -0
- package/skills/web-guidance/references/performance/performance.md +384 -0
- package/skills/web-guidance/references/privacy/privacy.md +247 -0
- package/skills/web-guidance/references/security/passkey-authentication.md +218 -0
- package/skills/web-guidance/references/security/passkey-management.md +310 -0
- package/skills/web-guidance/references/security/passkey-reauthentication.md +142 -0
- package/skills/web-guidance/references/security/passkey-registration.md +186 -0
- package/skills/web-guidance/references/security/passkeys.md +39 -0
- package/skills/web-guidance/references/security/sanitize-untrusted-html.md +105 -0
- package/skills/web-guidance/references/security/secure-external-subresources.md +202 -0
- package/skills/web-guidance/references/security/security.md +390 -0
- package/skills/web-guidance/references/security/trusted-types.md +141 -0
- package/skills/web-guidance/references/security/validate-origins.md +197 -0
- package/skills/web-guidance/references/security/verify-email-ownership.md +235 -0
- package/skills/web-guidance/references/ui-atoms/position-aware-tooltips.md +173 -0
- package/skills/web-guidance/references/ui-atoms/responsive-table.md +122 -0
- package/skills/web-guidance/references/ui-atoms/viewport-aware-dropdowns.md +178 -0
- package/skills/web-guidance/references/ui-behaviors/drag-and-drop.md +108 -0
- package/skills/web-guidance/references/ui-behaviors/light-dismiss-a-dialog.md +89 -0
- package/skills/web-guidance/references/ui-behaviors/motion.md +97 -0
- package/skills/web-guidance/references/ui-behaviors/platform-controls-dismiss-dialog.md +40 -0
- package/skills/web-guidance/references/ui-behaviors/prevent-page-scroll-under-modal-dialog.md +59 -0
- package/skills/web-guidance/references/ui-behaviors/search-hidden-content.md +141 -0
- package/skills/web-guidance/references/ui-behaviors/sortable-table.md +140 -0
- package/skills/web-guidance/references/ui-components/accordion.md +343 -0
- package/skills/web-guidance/references/ui-components/breadcrumbs.md +168 -0
- package/skills/web-guidance/references/ui-components/carousel.md +206 -0
- package/skills/web-guidance/references/ui-components/checkbox.md +144 -0
- package/skills/web-guidance/references/ui-components/dialog.md +218 -0
- package/skills/web-guidance/references/ui-components/hovercard.md +391 -0
- package/skills/web-guidance/references/ui-components/menu.md +415 -0
- package/skills/web-guidance/references/ui-components/navbar.md +281 -0
- package/skills/web-guidance/references/ui-components/navigation-drawer.md +429 -0
- package/skills/web-guidance/references/ui-components/persistent-toast-notifications.md +185 -0
- package/skills/web-guidance/references/ui-components/progress.md +181 -0
- package/skills/web-guidance/references/ui-components/spinner.md +179 -0
- package/skills/web-guidance/references/ui-components/tabs.md +371 -0
- package/skills/web-guidance/references/ui-components/toolbar.md +277 -0
- package/skills/web-guidance/references/user-experience/form-factor-adaptation.md +120 -0
- package/skills/web-guidance/references/user-experience/natural-interactions.md +155 -0
- package/skills/web-guidance/references/visual-design/color.md +43 -0
- package/skills/web-guidance/references/visual-design/dark-mode.md +350 -0
- package/dist/web/assets/AgentWork-DwAI0_Of.js +0 -2
- package/dist/web/assets/ApiTests-C0vFSHmM.js +0 -10
- package/dist/web/assets/Browse-5jfdtRc5.js +0 -2
- package/dist/web/assets/Chat-B3uhI94O.js +0 -3
- package/dist/web/assets/CommandPalette-D2J4nf5y.js +0 -1
- package/dist/web/assets/Compare-CN75w1p9.js +0 -1
- package/dist/web/assets/Cost-QoxyjR95.js +0 -1
- package/dist/web/assets/Data-BAvkcBVt.js +0 -6
- package/dist/web/assets/Desktop-BXdOIalN.js +0 -1
- package/dist/web/assets/DesktopReview-Bl2SrPP0.js +0 -1
- package/dist/web/assets/Evidence-BJ_I52CD.js +0 -1
- package/dist/web/assets/Explore-D9AuyTip.js +0 -2
- package/dist/web/assets/Features-CusGMDR9.js +0 -1
- package/dist/web/assets/Flags-CycGFuUP.js +0 -2
- package/dist/web/assets/Flaky-BcSzJogN.js +0 -1
- package/dist/web/assets/Impact-CJHnyZ21.js +0 -3
- package/dist/web/assets/Jobs-4xcFzEFo.js +0 -5
- package/dist/web/assets/KindPage-BielEIej.js +0 -6
- package/dist/web/assets/Migration-NwanKpJg.js +0 -2
- package/dist/web/assets/PageAgent-CNw4NXva.js +0 -1
- package/dist/web/assets/Product-DS3LJZ4P.js +0 -7
- package/dist/web/assets/Production-D3zsyNIS.js +0 -1
- package/dist/web/assets/Quality-Ctj2YpC4.js +0 -1
- package/dist/web/assets/Readiness-DGcRr_co.js +0 -1
- package/dist/web/assets/Record-Cc-wGe_Y.js +0 -1
- package/dist/web/assets/Regression-DcsbrRa1.js +0 -5
- package/dist/web/assets/Reports-BkCn0-Sf.js +0 -2
- package/dist/web/assets/Response-BP0UwQcW.js +0 -9
- package/dist/web/assets/Responsive-C8U7dumd.js +0 -3
- package/dist/web/assets/RunDiff-BhABuhF_.js +0 -1
- package/dist/web/assets/Runs-OwdWEYBv.js +0 -2
- package/dist/web/assets/Steps-BvzbQyoD.js +0 -2
- package/dist/web/assets/TestCases-CLq_6JA5.js +0 -1
- package/dist/web/assets/TestData-B0oKAhp6.js +0 -2
- package/dist/web/assets/TestDebt-8NLQ5YV_.js +0 -1
- package/dist/web/assets/TestManagement-2LYQ7vsN.js +0 -1
- package/dist/web/assets/Tosca-DfvMpPTG.js +0 -3
- package/dist/web/assets/WhatsNew-BGFNGwqN.js +0 -1
- package/dist/web/assets/families-DYlN5v0i.js +0 -1
- package/dist/web/assets/filters-faaSnoIq.js +0 -1
- package/dist/web/assets/fold-CUjwWAK3.js +0 -1
- package/dist/web/assets/frame-BLPdAXUq.js +0 -13
- package/dist/web/assets/head-CsTxBsO0.js +0 -1
- package/dist/web/assets/index-CxiCvGZq.js +0 -78
- package/dist/web/assets/index-dOIsrzhD.css +0 -2
- package/dist/web/assets/line-icons-CwZWt93L.js +0 -1
- package/dist/web/assets/logos-dGuc1jIM.js +0 -1
- package/dist/web/assets/markdown-BI3F-SJ1.js +0 -10
- package/dist/web/assets/paletteCommands-QJiCuUEr.js +0 -1
- package/dist/web/assets/parts-CdF1f7yS.js +0 -1
- package/dist/web/assets/productParts-hNLD9fN0.js +0 -1
- package/dist/web/assets/qualityParts-CT25lBWU.js +0 -1
- package/dist/web/assets/recordTest-P792aBUt.js +0 -1
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
# Validate Input After Interaction
|
|
2
|
+
|
|
3
|
+
## The Problem
|
|
4
|
+
|
|
5
|
+
Displaying validation errors the moment a user focuses on a field and starts typing is premature and distracting. For example, as a user types an email address (e.g., "user@gm") or a password with complex requirements, the field is technically invalid until completion. Standard `:invalid` styling results in an error state appearing immediately, frustrating the user.
|
|
6
|
+
|
|
7
|
+
## The Solution
|
|
8
|
+
|
|
9
|
+
The `:user-invalid` pseudo-class allows you to defer the error state until the user has "committed" to a value (by modifying and blurring the field) or attempted to submit the form. This ensures validation feedback is provided only after the user has finished interacting with the field.
|
|
10
|
+
|
|
11
|
+
### Implementation Strategy
|
|
12
|
+
|
|
13
|
+
1. **HTML Constraint**: DO use standard HTML5 attributes like `type="email"`, `pattern`, and `required` to trigger the browser's built-in validation logic.
|
|
14
|
+
2. **Visual Feedback**: DO use `:user-invalid` to apply error styling only after interaction.
|
|
15
|
+
3. **Positive Reinforcement**: DO optionally use `:user-valid` to give a green "success" indicator once the requirements are met.
|
|
16
|
+
4. **Graceful Recovery**: As soon as the user corrects the input to a valid format, `:user-invalid` stops matching, removing the error state immediately.
|
|
17
|
+
5. **Error Text**: DO show visible error text with the error styling, so the error isn't shown by color alone. DO start each message with an error icon that has a text alternative such as "Error" (the safest choice), or word every message as an error, for example "Please enter a valid email address.", and use the same approach for every error in the form. DO say how to fix the error when you know how, for example "Enter an email address in the format you@example.com."
|
|
18
|
+
6. **Error Link**: DO list the error message in the field's `aria-describedby`, after any hint, only while the field is invalid, so screen readers read it with the field. A reference in the markup would read the hidden message from page load. The script in "Consistent ARIA Experience" does this for each field whose `data-error` attribute is set to its error message's `id`.
|
|
19
|
+
|
|
20
|
+
## Implementation Guide
|
|
21
|
+
|
|
22
|
+
### Use Case 1: Email Validation
|
|
23
|
+
|
|
24
|
+
MANDATORY: Rely on standard HTML5 attributes for email fields. The error message is hidden by default and only revealed when the browser determines the user has left the field in an invalid state.
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<form>
|
|
28
|
+
<div class="field">
|
|
29
|
+
<label for="email">Email Address</label>
|
|
30
|
+
<!-- MANDATORY: Place format hints above the input so autocomplete popovers don't cover them during editing -->
|
|
31
|
+
<span id="email-hint" class="hint">Format: you@example.com</span>
|
|
32
|
+
<!-- DO: Use standard HTML validation attributes like type="email" and required -->
|
|
33
|
+
<!-- Set data-error to the error message's id. The aria-invalid script lists that id in aria-describedby while the field is invalid. -->
|
|
34
|
+
<input
|
|
35
|
+
type="email"
|
|
36
|
+
id="email"
|
|
37
|
+
name="email"
|
|
38
|
+
required
|
|
39
|
+
autocomplete="email"
|
|
40
|
+
aria-describedby="email-hint"
|
|
41
|
+
data-error="email-error"
|
|
42
|
+
>
|
|
43
|
+
<div id="email-error" class="error-msg">
|
|
44
|
+
<span role="img" aria-label="Error">❌</span> Enter an email address in the format you@example.com.
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
</form>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```css
|
|
51
|
+
.hint {
|
|
52
|
+
display: block;
|
|
53
|
+
color: #5f6368;
|
|
54
|
+
font-size: 0.85rem;
|
|
55
|
+
margin-bottom: 0.25rem;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.error-msg {
|
|
59
|
+
display: none;
|
|
60
|
+
color: #d93025;
|
|
61
|
+
font-size: 0.875rem;
|
|
62
|
+
margin-top: 0.25rem;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
DO: Only show error styles after user interaction.
|
|
67
|
+
Use multiple indicators (border/background shift + icon/text) to avoid color-only states.
|
|
68
|
+
*/
|
|
69
|
+
input:user-invalid {
|
|
70
|
+
border-color: #d93025;
|
|
71
|
+
background-color: #fce8e6;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* DO: Reveal the error message using the adjacent sibling selector */
|
|
75
|
+
input:user-invalid + .error-msg {
|
|
76
|
+
display: block;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* DO: Provide a clear success indication on :user-valid */
|
|
80
|
+
input:user-valid {
|
|
81
|
+
border-color: #188038;
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Use Case 2: Password Complexity
|
|
86
|
+
|
|
87
|
+
MANDATORY: Define the complexity rule using a Regex Lookahead pattern in the `pattern` attribute. The rules list is shown above the input to guide the user, and highlighted if there's an error.
|
|
88
|
+
|
|
89
|
+
```html
|
|
90
|
+
<form>
|
|
91
|
+
<div class="field">
|
|
92
|
+
<label for="password">New Password</label>
|
|
93
|
+
<!-- MANDATORY: Place hints and rules above the input so mobile keyboards do not obscure them -->
|
|
94
|
+
<ul id="password-rules" class="rules-list">
|
|
95
|
+
<li>At least 8 characters</li>
|
|
96
|
+
<li>One uppercase letter</li>
|
|
97
|
+
<li>One lowercase letter</li>
|
|
98
|
+
<li>One number</li>
|
|
99
|
+
<li>One special character</li>
|
|
100
|
+
</ul>
|
|
101
|
+
<!-- DO: Use pattern and minlength for complex password validation
|
|
102
|
+
DO: Match all constraints with lookaheads via pattern attribute
|
|
103
|
+
-->
|
|
104
|
+
<!-- Set data-error to the error message's id. The aria-invalid script lists that id in aria-describedby while the field is invalid. -->
|
|
105
|
+
<input
|
|
106
|
+
type="password"
|
|
107
|
+
id="password"
|
|
108
|
+
autocomplete="new-password"
|
|
109
|
+
required
|
|
110
|
+
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\W_]).{8,}"
|
|
111
|
+
minlength="8"
|
|
112
|
+
aria-describedby="password-rules"
|
|
113
|
+
data-error="password-error"
|
|
114
|
+
>
|
|
115
|
+
<!-- MANDATORY: Give the password its own error text. Turning the rules list red
|
|
116
|
+
doesn't say what is wrong, and screen readers don't convey the color change. -->
|
|
117
|
+
<div id="password-error" class="error-msg">
|
|
118
|
+
<span role="img" aria-label="Error">❌</span> Password doesn't meet all the requirements listed above.
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
</form>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
```css
|
|
125
|
+
/* DO: State the default styling as neutral */
|
|
126
|
+
.rules-list {
|
|
127
|
+
color: #5f6368;
|
|
128
|
+
margin-bottom: 0.5rem;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* DO: Show invalid state (After interaction): Error */
|
|
132
|
+
input:user-invalid {
|
|
133
|
+
border-color: #d93025;
|
|
134
|
+
background-color: #fce8e6;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* DO: Reveal the error message using the adjacent sibling selector */
|
|
138
|
+
input:user-invalid + .error-msg {
|
|
139
|
+
display: block;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* DO: Highlight rules list when error is shown using the modern :has() selector */
|
|
143
|
+
.field:has(input:user-invalid) .rules-list {
|
|
144
|
+
color: #d93025;
|
|
145
|
+
font-weight: 600;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* DO: Add success indications for :user-valid state */
|
|
149
|
+
input:user-valid {
|
|
150
|
+
border-color: #188038;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* DO: Hide rules once satisfied. visibility keeps their space: collapsing the list on
|
|
154
|
+
blur would move the submit button between mousedown and mouseup, and the click
|
|
155
|
+
would be lost. */
|
|
156
|
+
.field:has(input:user-valid) .rules-list {
|
|
157
|
+
visibility: hidden;
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Fallbacking & Browser Support
|
|
162
|
+
|
|
163
|
+
### Fallbacks & browser support for :user-valid and :user-invalid
|
|
164
|
+
|
|
165
|
+
Baseline status for :user-valid and :user-invalid: Widely available. It's been Baseline since 2023-11-02.
|
|
166
|
+
Supported by: Chrome 119 (Oct 2023), Edge 119 (Nov 2023), Firefox 88 (Apr 2021), and Safari 16.5 (May 2023).
|
|
167
|
+
|
|
168
|
+
### CSS for Fallback
|
|
169
|
+
|
|
170
|
+
```css
|
|
171
|
+
/* Applies to every field that can be invalid (input, select, textarea). :is() keeps the
|
|
172
|
+
rule working where :user-invalid isn't supported: in a plain selector list, one
|
|
173
|
+
unsupported selector drops the whole rule. */
|
|
174
|
+
:is(:user-invalid, .user-invalid-fallback) {
|
|
175
|
+
border-color: #d93025;
|
|
176
|
+
background-color: #fce8e6;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
:is(:user-invalid, .user-invalid-fallback) + .error-msg {
|
|
180
|
+
display: block;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### JavaScript Fallback
|
|
185
|
+
|
|
186
|
+
Use a reusable utility that tracks interaction state using a `WeakMap`. This avoids polluting the DOM with "dirty" classes or data attributes.
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
const UserInvalidFallback = (() => {
|
|
190
|
+
const dirtyState = new WeakMap();
|
|
191
|
+
|
|
192
|
+
const updateState = (input) => {
|
|
193
|
+
// validity.valid gives the current state without firing an 'invalid' event, as checkValidity() does.
|
|
194
|
+
const isValid = input.validity.valid;
|
|
195
|
+
|
|
196
|
+
// Update both visual and ARIA state
|
|
197
|
+
input.classList.toggle('user-invalid-fallback', !isValid);
|
|
198
|
+
input.classList.toggle('user-valid-fallback', isValid);
|
|
199
|
+
|
|
200
|
+
input.setAttribute('aria-invalid', isValid ? 'false' : 'true');
|
|
201
|
+
linkError(input, !isValid);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// List the error message (the id in data-error) in aria-describedby only while it's
|
|
205
|
+
// shown: text that aria-describedby references is announced even when it's hidden.
|
|
206
|
+
const linkError = (input, shown) => {
|
|
207
|
+
const errorId = input.dataset.error;
|
|
208
|
+
if (!errorId) return;
|
|
209
|
+
const ids = (input.getAttribute('aria-describedby') || '').split(/\s+/).filter((id) => id && id !== errorId);
|
|
210
|
+
if (shown) ids.push(errorId);
|
|
211
|
+
if (ids.length) input.setAttribute('aria-describedby', ids.join(' '));
|
|
212
|
+
else input.removeAttribute('aria-describedby');
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const handleEvent = (event) => {
|
|
216
|
+
const input = event.target;
|
|
217
|
+
|
|
218
|
+
if (event.type === 'reset') {
|
|
219
|
+
const controls = input.elements || [];
|
|
220
|
+
for (const control of controls) {
|
|
221
|
+
dirtyState.delete(control);
|
|
222
|
+
control.classList.remove('user-invalid-fallback');
|
|
223
|
+
control.classList.remove('user-valid-fallback');
|
|
224
|
+
if (control.matches('input, select, textarea')) control.setAttribute('aria-invalid', 'false');
|
|
225
|
+
if (control.dataset?.error) linkError(control, false);
|
|
226
|
+
}
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (!input.checkValidity) return;
|
|
231
|
+
|
|
232
|
+
// A submit attempt counts as interaction: the browser fires 'invalid' on each failing
|
|
233
|
+
// field, including required fields the user never touched, so flag them all.
|
|
234
|
+
if (event.type === 'invalid') {
|
|
235
|
+
dirtyState.set(input, { hasInteracted: true, hasBlurred: true });
|
|
236
|
+
updateState(input);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (event.type === 'input' || event.type === 'change') {
|
|
241
|
+
const state = dirtyState.get(input) || { hasInteracted: false, hasBlurred: false };
|
|
242
|
+
state.hasInteracted = true;
|
|
243
|
+
dirtyState.set(input, state);
|
|
244
|
+
if (state.hasBlurred) {
|
|
245
|
+
updateState(input);
|
|
246
|
+
}
|
|
247
|
+
} else if (event.type === 'blur') {
|
|
248
|
+
const state = dirtyState.get(input) || { hasInteracted: false, hasBlurred: false };
|
|
249
|
+
state.hasBlurred = true;
|
|
250
|
+
dirtyState.set(input, state);
|
|
251
|
+
if (state.hasInteracted) {
|
|
252
|
+
updateState(input);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const init = (root = document) => {
|
|
258
|
+
if (CSS.supports('selector(:user-invalid)')) return;
|
|
259
|
+
|
|
260
|
+
// Firefox and Safari expose an empty required field as invalid from page load.
|
|
261
|
+
root.querySelectorAll('input, select, textarea').forEach((el) => {
|
|
262
|
+
if (!el.hasAttribute('aria-invalid')) el.setAttribute('aria-invalid', 'false');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
root.addEventListener('blur', handleEvent, true); // Capture phase
|
|
266
|
+
root.addEventListener('input', handleEvent);
|
|
267
|
+
root.addEventListener('change', handleEvent);
|
|
268
|
+
root.addEventListener('invalid', handleEvent, true); // invalid doesn't bubble
|
|
269
|
+
root.addEventListener('reset', handleEvent, true); // Capture resets
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
return { init };
|
|
273
|
+
})();
|
|
274
|
+
|
|
275
|
+
// Initialize for a specific form
|
|
276
|
+
const form = document.querySelector('#demo-form');
|
|
277
|
+
UserInvalidFallback.init(form);
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Other Considerations
|
|
281
|
+
|
|
282
|
+
1. **Accessibility**:
|
|
283
|
+
* MANDATORY: Use `aria-describedby` to link the rules list to the input.
|
|
284
|
+
* DO NOT: Hide rules lists entirely until the input is valid; users need to know what to type!
|
|
285
|
+
2. **Pattern Attribute Limits**: MANDATORY: The `pattern` attribute performs a full match (implied `^...$`). Ensure your password regex accounts for the entire string.
|
|
286
|
+
3. **Validation Strictness**: DO note that the browser's default `type="email"` validation is quite permissive (e.g., `user@localserver` might pass). If you need stricter validation, you may need to use a more robust validation library or a custom validation function alongside `type="email"`.
|
|
287
|
+
4. **Focus Management**: MANDATORY: If a user submits the form with an invalid field, the browser will automatically focus the first invalid field. Your `:user-invalid` styles will apply immediately because a submission attempt counts as an interaction.
|
|
288
|
+
5. **Consistent ARIA Experience**: Native `:user-invalid` does not automatically sync with ARIA attributes. Add the following JavaScript to keep `aria-invalid` in sync with the visual state:
|
|
289
|
+
|
|
290
|
+
* Set `aria-invalid="false"` until `:user-invalid` matches, rather than leaving it unset. Firefox and Safari expose an empty `required` field as invalid from page load, and Chromium doesn't expose an empty `required` field as invalid after interaction unless `aria-invalid="true"` is set.
|
|
291
|
+
* Link each field to its error message by setting the field's `data-error` attribute to the error message's `id` (`data-error="email-error"` for `<div id="email-error">`), and let the script list that `id` in `aria-describedby` only while the field is invalid. Don't reference the error from `aria-describedby` in the markup: the error element is always in the page, and text that `aria-describedby` references is announced even when it's hidden.
|
|
292
|
+
* Announce an error that appears when the user leaves or changes a field through one polite live region for the page, a moment later so it doesn't talk over the next field. Don't make each error message a live region: a live region that is shown, rather than changed, isn't announced reliably. After a failed submit, move focus to the first invalid field so that its error is announced instead.
|
|
293
|
+
|
|
294
|
+
```javascript
|
|
295
|
+
// List the field's error message (the id in data-error) in aria-describedby only while
|
|
296
|
+
// it's shown: text that aria-describedby references is announced even when it's hidden.
|
|
297
|
+
const linkError = (el, shown) => {
|
|
298
|
+
const errorId = el.dataset.error;
|
|
299
|
+
if (!errorId) return;
|
|
300
|
+
const ids = (el.getAttribute('aria-describedby') || '').split(/\s+/).filter((id) => id && id !== errorId);
|
|
301
|
+
if (shown) ids.push(errorId);
|
|
302
|
+
if (ids.length) el.setAttribute('aria-describedby', ids.join(' '));
|
|
303
|
+
else el.removeAttribute('aria-describedby');
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// One polite live region for the page announces an error that appears when the user
|
|
307
|
+
// leaves or changes a field. Run this once the form is in the page.
|
|
308
|
+
const announcer = document.createElement('div');
|
|
309
|
+
announcer.setAttribute('aria-live', 'polite');
|
|
310
|
+
announcer.classList.add('visually-hidden');
|
|
311
|
+
document.body.append(announcer);
|
|
312
|
+
let announceTimer;
|
|
313
|
+
let announcedField;
|
|
314
|
+
|
|
315
|
+
// Text as a screen reader reads it: icons' text alternatives in, aria-hidden text out.
|
|
316
|
+
const spokenText = (node) => {
|
|
317
|
+
const copy = node.cloneNode(true);
|
|
318
|
+
copy.querySelectorAll('[aria-hidden="true"]').forEach((n) => n.remove());
|
|
319
|
+
copy.querySelectorAll('[role="img"][aria-label]').forEach((n) => n.replaceWith(`${n.getAttribute('aria-label')}: `));
|
|
320
|
+
return copy.textContent.replace(/\s+/g, ' ').trim();
|
|
321
|
+
};
|
|
322
|
+
const announceError = (el) => {
|
|
323
|
+
const error = document.getElementById(el.dataset.error);
|
|
324
|
+
if (!error) return;
|
|
325
|
+
const label = el.labels?.[0] ? `${spokenText(el.labels[0])}: ` : '';
|
|
326
|
+
clearTimeout(announceTimer);
|
|
327
|
+
announcer.textContent = '';
|
|
328
|
+
announcedField = el;
|
|
329
|
+
// Wait until the screen reader has announced the field that receives focus next.
|
|
330
|
+
announceTimer = setTimeout(() => { announcer.textContent = label + spokenText(error); }, 500);
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// Sync aria-invalid with the CSS :user-invalid state. Only form fields are synced, and
|
|
334
|
+
// an aria-invalid="true" that this script didn't set (for example from a server check)
|
|
335
|
+
// is left alone.
|
|
336
|
+
const flagged = new WeakSet();
|
|
337
|
+
// Fields whose current error has been announced, or read out by focus after a failed
|
|
338
|
+
// submit. A field can become invalid while the user types, so this is tracked separately.
|
|
339
|
+
const announced = new WeakSet();
|
|
340
|
+
const syncAria = (el, announce = false) => {
|
|
341
|
+
if (!el.matches?.('input, select, textarea')) return;
|
|
342
|
+
const invalid = el.matches(':user-invalid');
|
|
343
|
+
if (invalid) {
|
|
344
|
+
if (announce && !announced.has(el)) {
|
|
345
|
+
announceError(el);
|
|
346
|
+
announced.add(el);
|
|
347
|
+
}
|
|
348
|
+
el.setAttribute('aria-invalid', 'true');
|
|
349
|
+
linkError(el, true);
|
|
350
|
+
flagged.add(el);
|
|
351
|
+
} else if (flagged.has(el) || el.getAttribute('aria-invalid') !== 'true') {
|
|
352
|
+
el.setAttribute('aria-invalid', 'false');
|
|
353
|
+
linkError(el, false);
|
|
354
|
+
flagged.delete(el);
|
|
355
|
+
announced.delete(el);
|
|
356
|
+
// Clear a fixed field's announcement so it isn't found later when reading the page.
|
|
357
|
+
if (announcedField === el) {
|
|
358
|
+
clearTimeout(announceTimer);
|
|
359
|
+
announcer.textContent = '';
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
// Start every field at aria-invalid="false".
|
|
365
|
+
document.querySelectorAll('input, select, textarea').forEach((el) => syncAria(el));
|
|
366
|
+
|
|
367
|
+
// Update on blur (to show and announce an error) and input (to clear it)
|
|
368
|
+
document.addEventListener('blur', (e) => syncAria(e.target, true), true);
|
|
369
|
+
document.addEventListener('input', (e) => {
|
|
370
|
+
if (e.target.hasAttribute('aria-invalid')) syncAria(e.target);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// Checkboxes, radio buttons and other controls that commit on 'change' can become
|
|
374
|
+
// :user-invalid without losing focus, so update on change too.
|
|
375
|
+
document.addEventListener('change', (e) => syncAria(e.target, true), true);
|
|
376
|
+
|
|
377
|
+
// A failed submit fires 'invalid' on each failing field, including required fields the
|
|
378
|
+
// user never touched, so update those too. 'invalid' doesn't bubble. Focus moving to the
|
|
379
|
+
// first invalid field announces its error, so these aren't announced.
|
|
380
|
+
document.addEventListener('invalid', (e) => {
|
|
381
|
+
announced.add(e.target);
|
|
382
|
+
syncAria(e.target);
|
|
383
|
+
}, true);
|
|
384
|
+
|
|
385
|
+
// Reset clears :user-invalid after the 'reset' event, so update each field afterwards.
|
|
386
|
+
document.addEventListener('reset', (e) => {
|
|
387
|
+
setTimeout(() => [...e.target.elements].forEach((el) => syncAria(el)));
|
|
388
|
+
}, true);
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Hide the live region with the `.visually-hidden` utility:
|
|
392
|
+
|
|
393
|
+
```css
|
|
394
|
+
/* Hides content visually but keeps it in the accessibility tree */
|
|
395
|
+
.visually-hidden:where(:not(:focus-within, :active)) {
|
|
396
|
+
position: absolute !important;
|
|
397
|
+
clip-path: inset(50%) !important;
|
|
398
|
+
overflow: hidden !important;
|
|
399
|
+
width: 1px !important;
|
|
400
|
+
height: 1px !important;
|
|
401
|
+
margin: -1px !important;
|
|
402
|
+
padding: 0 !important;
|
|
403
|
+
border: 0 !important;
|
|
404
|
+
white-space: nowrap !important;
|
|
405
|
+
}
|
|
406
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Break Up Long Tasks
|
|
2
|
+
|
|
3
|
+
Heavy computations or long loops can block the main thread, delaying event handlers and causing poor Interaction to Next Paint (INP) responsiveness. To prevent this, yield control back to the browser periodically with `scheduler.yield()`, which pauses an already-running task so the browser can handle pending user input and rendering before continuing.
|
|
4
|
+
|
|
5
|
+
`scheduler.yield()` only splits a single running task—it does not order separate work streams (`'user-blocking'`, `'user-visible'`, `'background'`), defer non-urgent background work before it starts, or abort and reprioritize queued tasks via `TaskController`. **DO NOT** replace `scheduler.postTask()` or `TaskController` with `scheduler.yield()` alone when scheduling work at different priorities; see `schedule-tasks-by-priority`. When a background task scheduled with `scheduler.postTask()` itself exceeds 50ms, combine both APIs by calling `await scheduler.yield()` inside the `postTask()` callback—continuations automatically inherit the enclosing task's priority and `TaskSignal`.
|
|
6
|
+
|
|
7
|
+
### Breaking up long tasks
|
|
8
|
+
|
|
9
|
+
Use `scheduler.yield()` inside async functions to break up work.
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
async function processLargeArray(items) {
|
|
13
|
+
// DO: Set a time-based deadline 50 milliseconds into the future. 50
|
|
14
|
+
// milliseconds is the boundary for when a task becomes a long task.
|
|
15
|
+
let deadline = performance.now() + 50; // 50ms budget
|
|
16
|
+
|
|
17
|
+
for (const item of items) {
|
|
18
|
+
// Process the item
|
|
19
|
+
processItem(item);
|
|
20
|
+
|
|
21
|
+
// MANDATORY: Yield to the main thread periodically to keep the UI
|
|
22
|
+
// responsive. This can be done by checking if the deadline set earlier
|
|
23
|
+
// has been exceeded. When it has been, yield, then reset the deadline
|
|
24
|
+
// another 50 milliseconds into the future.
|
|
25
|
+
if (performance.now() >= deadline) {
|
|
26
|
+
await scheduler.yield();
|
|
27
|
+
deadline = performance.now() + 50;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Fallback strategies
|
|
34
|
+
|
|
35
|
+
Browser support for Scheduler API: Limited availability.
|
|
36
|
+
Supported by: Chrome 129 (Sep 2024), Edge 129 (Sep 2024), and Firefox 142 (Aug 2025).
|
|
37
|
+
Unsupported in: Safari.
|
|
38
|
+
|
|
39
|
+
If your Baseline target does not support the Scheduler API, implement a fallback using `setTimeout` so long loops still yield to the main thread without throwing. (If combining `scheduler.yield()` with `scheduler.postTask()`, feature-detect `postTask` separately as well.)
|
|
40
|
+
|
|
41
|
+
#### Fallback for `scheduler.yield()`
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
async function processLargeArrayWithFallback(items) {
|
|
45
|
+
// DO: Set a time-based deadline 50 milliseconds into the future.
|
|
46
|
+
let deadline = performance.now() + 50;
|
|
47
|
+
|
|
48
|
+
for (const item of items) {
|
|
49
|
+
processItem(item);
|
|
50
|
+
|
|
51
|
+
// MANDATORY: Yield to the main thread periodically to keep the UI responsive.
|
|
52
|
+
if (performance.now() >= deadline) {
|
|
53
|
+
// DO: Feature detect scheduler.yield
|
|
54
|
+
if ('scheduler' in window && 'yield' in window.scheduler) {
|
|
55
|
+
await scheduler.yield();
|
|
56
|
+
} else {
|
|
57
|
+
// DO: Fallback to setTimeout for older browsers
|
|
58
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
59
|
+
}
|
|
60
|
+
deadline = performance.now() + 50;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Identify heavy-running JavaScript
|
|
2
|
+
|
|
3
|
+
Heavy-running JavaScript can have a detrimental effect on both page load performance and interactivity. Modern web applications are more heavily reliant on JavaScript than ever before, from multiple sources. These include the application code itself (and the framework code it relies on), as well as third-party scripts that add functionality like chat widgets and video players. Behind-the-scenes analytics and marketing scripts are also common contributors that are all too easy to forget.
|
|
4
|
+
|
|
5
|
+
Identifying root causes of an unresponsive web page can be tricky with certain expertise required to run web performance tracing or profiling and how to interpret the results. Additionally field data is often very different to lab data, which only replicates a small subset of real user scenarios. This can make it difficult to identify the root causes of poor performance, especially for interactions.
|
|
6
|
+
|
|
7
|
+
The Long Animation Frames API is a lightweight API that can be used to identify heavy-running JavaScript in the field. A heavy-running script can be either a single long-running script, or a script that runs multiple times during the page lifecycle.
|
|
8
|
+
|
|
9
|
+
## How to implement
|
|
10
|
+
|
|
11
|
+
Long animation frames are monitored using the `PerformanceObserver` interface. It emits a `long-animation-frame` entry when an animation frame takes longer than 50ms to render. The entry contains information about the long animation frame, including the duration of the frame and the scripts that were executed during the frame.
|
|
12
|
+
|
|
13
|
+
The `long-animation-frame` entry contains a `scripts` property which is an array of `PerformanceScript` objects. Each `PerformanceScript` object contains information about the script that was executed during the long animation frame, including the `sourceURL` and `duration` of the script.
|
|
14
|
+
|
|
15
|
+
### Example of identifying the longest running scripts that contribute to long animation frames
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
// Accumulate all script entries across the page lifecycle so no
|
|
19
|
+
// data is lost between observer callbacks.
|
|
20
|
+
const allScripts = [];
|
|
21
|
+
|
|
22
|
+
const observer = new PerformanceObserver(list => {
|
|
23
|
+
// Collect all script entries across frames to find the biggest offenders.
|
|
24
|
+
allScripts.push(...list.getEntries().flatMap(entry => entry.scripts));
|
|
25
|
+
|
|
26
|
+
// Group by sourceURL so you can identify which scripts contribute
|
|
27
|
+
// the most total time, even if each individual invocation is short.
|
|
28
|
+
const scriptSource = [...new Set(allScripts.map(script => script.sourceURL))];
|
|
29
|
+
const scriptsBySource = scriptSource.map(sourceURL => ([sourceURL,
|
|
30
|
+
allScripts.filter(script => script.sourceURL === sourceURL)
|
|
31
|
+
]));
|
|
32
|
+
const processedScripts = scriptsBySource.map(([sourceURL, scripts]) => ({
|
|
33
|
+
sourceURL,
|
|
34
|
+
count: scripts.length,
|
|
35
|
+
totalDuration: scripts.reduce((subtotal, script) => subtotal + script.duration, 0)
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
// Only include scripts above a certain threshold to reduce noise.
|
|
39
|
+
const heavyScripts = processedScripts.filter(script => {
|
|
40
|
+
return script.totalDuration > 100;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Sort by total duration so the worst offenders appear first,
|
|
44
|
+
// making it easier to prioritize optimization efforts.
|
|
45
|
+
heavyScripts.sort((a, b) => b.totalDuration - a.totalDuration);
|
|
46
|
+
|
|
47
|
+
// Log to the console for local debugging. In production, replace
|
|
48
|
+
// this with a call to send the data to your analytics service.
|
|
49
|
+
console.table(heavyScripts);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Use buffered: true to capture any long frames that occurred before
|
|
53
|
+
// this observer was registered.
|
|
54
|
+
observer.observe({type: 'long-animation-frame', buffered: true});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Best Practices
|
|
58
|
+
|
|
59
|
+
- **DO** prefer the Long Animation Frames API over alternatives like the JS Self-Profiling API, which carries higher runtime overhead.
|
|
60
|
+
- **DO** summarize the key information as the Long Animation Frames API contains a lot of detail.
|
|
61
|
+
- **DO** send the required information to an analytics service in production.
|
|
62
|
+
|
|
63
|
+
## Browser support and fallback strategies
|
|
64
|
+
|
|
65
|
+
Browser support for Long animation frames performance entries: Limited availability.
|
|
66
|
+
Supported by: Chrome 123 (Mar 2024) and Edge 123 (Mar 2024).
|
|
67
|
+
Unsupported in: Firefox and Safari..
|
|
68
|
+
|
|
69
|
+
The Long Animation Frames API is ignored by browsers that do not support it, so it can be safely used without fallbacks. In most cases the performance opportunities it identifies will apply to other browsers as well.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Identify causes of poor INP
|
|
2
|
+
|
|
3
|
+
Poor responsiveness to interactions leads to a poor impression of a page being slow or even completely broken. Interaction to Next Paint (INP) is a metric based on the Event Timing API. It measures the worst interaction (minus some outliers) as a measure of the page's responsiveness.
|
|
4
|
+
|
|
5
|
+
Identifying root causes of an unresponsive web page can be tricky especially as it depends on user interactions and environmental conditions such as device capabilities and network conditions. This makes it even more difficult to diagnose compared to a more repeatable and predictable scenario like page load. Lab data only replicates a small subset of real user scenarios so measuring the causes of slow INP in the field is essential.
|
|
6
|
+
|
|
7
|
+
The Event Timing API allows for splitting the INP duration into three subparts: Input Delay (processing that is already happening when the interaction happens), Processing Duration (delays due as a direct result of the interaction), and Presentation Delay (delays that are due to rendering the next frame after the interaction). This helps identify if the issue is in other code, the interaction JavaScript code, or browser processing rendering updates respectively rather than jumping straight to the interaction code.
|
|
8
|
+
|
|
9
|
+
It is possible to gather further insights into JavaScript, style recalculation, and layout work delaying an interaction. A full performance trace using the JS Self-Profiling API is a heavyweight solution that is liable to cause performance problems. The Long Animation Frames API is a lightweight API that can be used in the field to identify slow-running JavaScript and distinguish between style recalculation and layout costs during INP interactions:
|
|
10
|
+
|
|
11
|
+
- **Script-level forced style and layout (`forcedStyleDuration` and `forcedLayoutDuration`):** Reports synchronous style recalculations (such as calling `getComputedStyle()` after DOM mutations) and forced layouts/reflows (such as reading `getBoundingClientRect()` or `offsetWidth` after mutations) inside a running script during **Input Delay** or **Processing Duration**.
|
|
12
|
+
- **Frame-level rendering style and layout (`styleDuration` and `layoutDuration`):** Reports time spent recalculating styles versus updating layout during the frame's rendering update, helping explain high **Presentation Delay**.
|
|
13
|
+
|
|
14
|
+
Distinguishing style recalculation from layout is critical because they have different root causes and fixes: high style duration points to expensive CSS selector matching or broad style invalidation (remediated by simplifying selectors or reducing rule scope), whereas high layout duration points to expensive geometry calculations or synchronous layout thrashing (remediated by batching DOM reads before writes, simplifying DOM structure, or using CSS containment).
|
|
15
|
+
|
|
16
|
+
## How to implement
|
|
17
|
+
|
|
18
|
+
Calculating INP from the raw Event Timing API is complicated and has several nuances. You are advised to use a RUM tool or library to gather this data.
|
|
19
|
+
|
|
20
|
+
`web-vitals` is an open-source library from Google that calculates the Core Web Vitals including INP, and also includes subparts and long animation frame data for the INP interaction.
|
|
21
|
+
|
|
22
|
+
## Get attributions for INP interactions using web-vitals library
|
|
23
|
+
|
|
24
|
+
The `web-vitals` library is a tiny library used to measure Core Web Vitals and other performance metrics. The `onINP()` function can be used to identify the slowest interaction and includes information about the INP subparts, scripts that were executed during the interaction, and style and layout durations using the Long Animation Frames API.
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
// Use the attribution build to get Long Animation Frame data
|
|
28
|
+
// alongside the INP metric value.
|
|
29
|
+
import { onINP } from 'web-vitals/attribution';
|
|
30
|
+
|
|
31
|
+
onINP((metric) => {
|
|
32
|
+
const { attribution } = metric;
|
|
33
|
+
const longestScript = attribution.longestScript;
|
|
34
|
+
|
|
35
|
+
// Sum rendering-phase style and layout durations across all LoAF entries
|
|
36
|
+
// intersecting the INP interaction (primarily explains presentationDelay).
|
|
37
|
+
let renderStyleDuration = 0;
|
|
38
|
+
let renderLayoutDuration = 0;
|
|
39
|
+
for (const entry of attribution.longAnimationFrameEntries) {
|
|
40
|
+
renderStyleDuration += entry.styleDuration ?? 0;
|
|
41
|
+
renderLayoutDuration += entry.layoutDuration ?? 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Beacon script, style, and layout attribution for the INP interaction,
|
|
45
|
+
// so you can identify the root cause in production.
|
|
46
|
+
navigator.sendBeacon(
|
|
47
|
+
'/analytics',
|
|
48
|
+
JSON.stringify({
|
|
49
|
+
name: 'INP',
|
|
50
|
+
value: metric.value,
|
|
51
|
+
// These fields give the INP subparts:
|
|
52
|
+
inputDelay: attribution.inputDelay,
|
|
53
|
+
presentationDelay: attribution.presentationDelay,
|
|
54
|
+
processingDuration: attribution.processingDuration,
|
|
55
|
+
interactionTarget: attribution.interactionTarget,
|
|
56
|
+
// These fields identify which script function was responsible
|
|
57
|
+
// for the longest processing during the INP interaction.
|
|
58
|
+
invokerType: longestScript?.entry?.invokerType,
|
|
59
|
+
sourceURL: longestScript?.entry?.sourceURL,
|
|
60
|
+
sourceFunctionName: longestScript?.entry?.sourceFunctionName,
|
|
61
|
+
sourceCharPosition: longestScript?.entry?.sourceCharPosition,
|
|
62
|
+
// subpart indicates which phase (input delay, processing, or
|
|
63
|
+
// presentation delay) the longest script overlapped with most.
|
|
64
|
+
subpart: longestScript?.subpart,
|
|
65
|
+
intersectingDuration: longestScript?.intersectingDuration,
|
|
66
|
+
// Synchronous style and layout work forced inside the longest script
|
|
67
|
+
// (with forcedStyleAndLayoutDuration as a combined fallback):
|
|
68
|
+
forcedStyleDuration: longestScript?.entry?.forcedStyleDuration,
|
|
69
|
+
forcedLayoutDuration: longestScript?.entry?.forcedLayoutDuration,
|
|
70
|
+
forcedStyleAndLayoutDuration: longestScript?.entry?.forcedStyleAndLayoutDuration,
|
|
71
|
+
// Rendering-phase style and layout work across the interaction's frames
|
|
72
|
+
// (with totalStyleAndLayoutDuration as a combined fallback):
|
|
73
|
+
renderStyleDuration,
|
|
74
|
+
renderLayoutDuration,
|
|
75
|
+
totalStyleAndLayoutDuration: attribution.totalStyleAndLayoutDuration
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Best Practices
|
|
82
|
+
|
|
83
|
+
- **DO** use INP subparts initially to identify whether the delay is already running JavaScript (input delay), the event handlers JavaScript for the interaction (processing duration), or the subsequent rendering (presentation delay).
|
|
84
|
+
- **DO** attempt to identify the biggest blocking JavaScript as additional detail, particularly for input delay, and processing duration.
|
|
85
|
+
- **DO** distinguish between style recalculation (`styleDuration`, `forcedStyleDuration`) and layout (`layoutDuration`, `forcedLayoutDuration`) when diagnosing high processing duration or presentation delay: high style times indicate expensive CSS selectors or broad invalidations, while high layout times indicate DOM geometry bottlenecks or synchronous layout thrashing.
|
|
86
|
+
- **DO** prefer the Long Animation Frames API for providing this further detail over alternatives like the JS Self-Profiling API, which carries higher runtime overhead.
|
|
87
|
+
- **DO** use the `web-vitals` library if no other RUM solution is in place. It can identify the INP interaction and includes information about the subparts and the scripts that were executed during the interaction (using the Long Animation Frames API).
|
|
88
|
+
- **DO** beacon back the required information to an analytics service rather than just log it locally.
|
|
89
|
+
|
|
90
|
+
## Browser support and fallback strategies
|
|
91
|
+
|
|
92
|
+
Baseline status for Event timing performance entries: Newly available. It's been Baseline since 2025-12-12.
|
|
93
|
+
Supported by: Chrome 76 (Jul 2019), Edge 79 (Jan 2020), Firefox 89 (Jun 2021), and Safari 26.2 (Dec 2025).
|
|
94
|
+
|
|
95
|
+
The Event Timing API is available in most modern browsers and is necessary to calculate INP and the INP subparts. For browsers that do not support this API INP cannot be measured.
|
|
96
|
+
|
|
97
|
+
Browser support for Long animation frames performance entries: Limited availability.
|
|
98
|
+
Supported by: Chrome 123 (Mar 2024) and Edge 123 (Mar 2024).
|
|
99
|
+
Unsupported in: Firefox and Safari.
|
|
100
|
+
|
|
101
|
+
The Long Animation Frames API provides optional, additional details. It can be safely used without fallbacks. In most cases the performance opportunities it identifies will apply to other browsers as well.
|
|
102
|
+
|
|
103
|
+
If your Baseline target supports the Long Animation Frames API (`long-animation-frames`) but does not support separate style and layout duration properties (`styleDuration` and `layoutDuration` on `PerformanceLongAnimationFrameTiming`, or `forcedStyleDuration` and `forcedLayoutDuration` on `PerformanceScriptTiming`), fall back to the combined style-and-layout timings:
|
|
104
|
+
- Use `script.forcedStyleAndLayoutDuration` on `PerformanceScriptTiming` for synchronous forced style and layout work inside scripts.
|
|
105
|
+
- Use `metric.attribution.totalStyleAndLayoutDuration` in `web-vitals/attribution` (or compute `(entry.paintTime || entry.startTime + entry.duration) - entry.styleAndLayoutStart` on each `PerformanceLongAnimationFrameTiming` entry) for combined style and layout work.
|