Modern Web Guidance

repository·main·Indexed 23 days ago

https://github.com/googlechrome/modern-web-guidance

A toolset providing expert-curated web platform expertise to help coding agents avoid legacy patterns and implement modern, performant, and accessible browser APIs. It covers core disciplines including CSS Layout, User Experience, Performance, Forms & UI, Accessibility, and Built-in AI. The library includes specific implementation guides for features such as View Transitions, Container Queries, the Popover API, Passkeys, and on-device AI capabilities like the Prompt and Summarizer APIs.

Tokens
255.7K
Snippets
531
Records
792
Agent score
81%

What's inside Modern Web Guidance

  1. Overview of Modern Web Guidance core disciplines

    main

    Modern Web Guidance provides token-efficient guides for cutting-edge web platform features. The content is organized into several core disciplines:

    • User Experience: Focuses on smooth visual states (e.g., View Transitions, entry/exit animations, parallax scroll, and scrollbar-color).
    • CSS Layout: Covers modern layout systems (e.g., container queries, subgrid, modern color spaces like oklch, text-wrap tuning, and line-height trimming).
    • Performance: Includes speed optimizations (e.g., instant preloading, Interaction to Next Paint (INP) diagnostics, and task scheduling via scheduler.yield).
    • Forms & UI: Covers native components (e.g., Anchor Positioning for tooltips, Popover API, dialogs, :user-invalid validation, and auto-sizing fields).
    • Accessibility: Focuses on screen reader and keyboard operability, content navigation, and discoverability.
    • Built-in AI: Covers local client models (e.g., native translation, summarization, and language detection APIs).
  2. Overview of Modern Web Guidance

    main

    Modern Web Guidance provides a set of skills designed to embed web platform expertise, best practices, and browser compatibility data into coding agents. It aims to steer AI agents away from legacy patterns and toward modern, high-performance web platform solutions.

    Key focus areas include:

    • Modern Browser APIs: Correctly structuring APIs that models frequently misuse.
    • Performance & Accessibility: Prioritizing platform-level APIs with built-in accessibility and browser optimization.
    • Responsible Fallbacks: Encouraging lightweight fallbacks over heavy polyfills or legacy libraries.
  3. Overview of Chrome Extension development with Modern Web Guidance

    main

    The chrome-extensions skill provides guidance for building, debugging, and publishing production-quality Chrome extensions using Manifest V3 best practices. It covers the entire lifecycle, from initial development to publishing on the Chrome Web Store.

    Key areas of coverage include:

    • Core Components: Working with manifest.json, content scripts, service workers, popups, and side panels.
    • Chrome APIs: Implementing functionality using chrome.* APIs, declarativeNetRequest, omnibox, and context menus.
    • User Scripts: Managing and building user scripts or script manager functionality.
    • Publishing & Compliance: Preparing extensions for the Chrome Web Store, responding to review rejections, writing permission justifications, and drafting privacy policies.
  4. Explore User Experience (UX) guidance guides

    main

    The modern-web-guidance repository provides a collection of specialized guides for implementing modern web features. The User Experience (UX) category includes guides for:

    • Accessibility & Themes: adapt-scrollbar-to-contrast-preferences, dark-mode, component-specific-light-dark-theme.
    • Animations & Transitions: animate-element-entry-exit, animate-to-from-top-layer, animate-to-intrinsic-sizes, carousel-slide-effects, cross-document-transitions, directional-navigation-transitions, dynamic-sibling-animations, group-element-transitions.
    • Layout & Styling: anchor-positioning-tab-underline, child-state-based-styling, complex-shapes, content-based-styling, dynamic-sibling-styling, fluid-scaling.
    • Data & Logic: calculate-event-differentials, capture-location-agnostic-data, coordinate-global-events, format-human-readable-durations.
    • Interactive Components: carousel-snap-highlights, custom-button-actions, declarative-dialog-popover-control.
    • Media & Canvas: apply-webgl-shaders, deliver-optimized-decorative-images, export-html-media-from-canvas, expose-canvas-content-to-browser-features.
    • Performance & Optimization: flicker-free-client-side-ab-testing, consistent-cross-document-transitions.

    Each guide provides specific implementation patterns and best practices for these modern web capabilities.

  5. Best Practices for Animated Select Pickers

    main

    When implementing customizable selects, follow these strategic guidelines:

    • Use @starting-style: Essential for triggering animations when an element transitions from display: none to visible.
    • Avoid ad-hoc scroll locking: Top-layer elements managed by base-select should allow natural backdrop dismiss behaviors.
    • Respect motion preferences: Always wrap animation constraints in a prefers-reduced-motion media query to ensure accessibility.
    • Test layout behavior: appearance: base-select removes default browser sizing based on the longest option. You may need to set a fixed width or use flex/grid to prevent layout shifts.
    • Maintain accessibility: Ensure your <select> has a name attribute and an associated <label>.
    • Provide multiple indicators: For the :checked state, do not rely on color alone; use additional indicators like bold font or distinct backgrounds to avoid color-only state communication.
  6. Choose between `async execute` and synchronous `execute`

    main

    The execute function's signature depends on the nature of the operation:

    • Use async execute for operations that return a Promise or take time, such as Network calls (e.g., fetch), Asynchronous Storage (e.g., IndexedDB), or External Events.
    • Use synchronous execute for immediate operations like Pure logic (math, filtering) or reading from Synchronous state (e.g., localStorage).
    // Async example
    async execute(input) {
      const response = await fetch(`/api/data/${input.id}`);
      return await response.json();
    }
    
    // Synchronous example
    execute(input) {
      return input.items.filter(item => item.active);
    }
  7. Manage AI sessions: Cloning and Restoring

    main

    Cloning Sessions

    Use session.clone() to create parallel conversations that share the same initial context (like a system prompt) without re-initializing. It is a best practice to call destroy() on the base session after cloning if the clones will manage their own context.

    Restoring Sessions

    To recreate a session from previous history, pass an array of {role, content} objects to the initialPrompts option in LanguageModel.create().

    Privacy Note: If using localStorage to persist history, be aware that it is unencrypted and may contain user PII.

    // Cloning
    const mainSession = await LanguageModel.create({
    	initialPrompts: [{ role: 'system', content: 'You speak like a pirate.' }],
    });
    const branchA = await mainSession.clone();
    mainSession.destroy();
    
    // Restoring
    const history = JSON.parse(localStorage.getItem('chat_history') || '[]');
    const session = await LanguageModel.create({
    	initialPrompts: history,
    });
  8. Accessibility considerations for Scroll Snap

    main

    When synchronizing UI elements (like a sidebar) with scroll snap positions, remember that visual synchronization does not automatically update the Accessibility Tree. You must manually manage programmatic relationships.

    • Active States: For a Table of Contents, ensure active links use aria-current="true" or aria-current="location".
    • Landmarks: Wrap Table of Contents links inside a proper <nav> landmark with an aria-label.
    • Mandatory Snapping: Use caution with scroll-snap-type: mandatory. If content between snap points is longer than the viewport, it may become inaccessible to users.
  9. Ensure accessibility for tab indicators

    main

    When using visual indicators like animated underlines or dots for active tabs, you must provide explicit state for assistive technologies. Use aria-current="page" for navigation links or aria-selected for tab components.

    <!-- MANDATORY: Provide explicit assistive technology state alongside the visual tab underline -->
    <nav aria-label="Primary">
      <ul>
        <li class="active">
          <a href="/home" aria-current="page">Home</a>
        </li>
        <li>
          <a href="/about">About</a>
        </li>
      </ul>
    </nav>
  10. Choose between Popover and Dialog for overlays

    main

    When implementing UI overlays, choose the primitive based on the interaction type:

    • popover: Use for transient, non-modal UI like flyouts, toasts, or tooltips. These live in the top layer and do not require z-index management.
    • <dialog> with .showModal(): Use for modal interactions that require focus trapping and an inert backdrop.

    Note: popover and .showModal() are mutually exclusive runtime states; do not combine them on the same element.

  11. Understand the `chrome.userScripts` API

    main

    The chrome.userScripts API allows extensions to run arbitrary code provided by the user at runtime. This code is not part of the extension package.

    When to use userScripts:

    • Building a script manager.
    • Custom automation tools.
    • Features where users supply their own JavaScript to run on web pages.

    Comparison with other methods:

    • Content Scripts: Use when the code is written by you and bundled with the extension.
    • chrome.scripting.executeScript: Use for one-off execution of known, extension-owned code.