Keep your coding agent up to date with the latest web best practices
Release v0.0.82
github-actions[bot]13469d1fd5a4
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.jsonindex 3b54def..2a64f1b 100644--- a/.claude-plugin/marketplace.json+++ b/.claude-plugin/marketplace.json@@ -8,7 +8,7 @@"name": "modern-web-guidance","source": "./","description": "Google Chrome's agent skills collection",- "version": "0.0.81"+ "version": "0.0.82"}]}diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.jsonindex de90017..8defa71 100644--- a/.claude-plugin/plugin.json+++ b/.claude-plugin/plugin.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Google Chrome's agent skills collection",- "version": "0.0.81",+ "version": "0.0.82","author": {"name": "Google Chrome"}diff --git a/README.md b/README.mdindex 3afe8a7..7570b96 100644--- a/README.md+++ b/README.md@@ -2,10 +2,10 @@This curated collection of skills, tools, and AI-ready documentation injects Chrome's web platform knowledge directly into your workflow, ensuring your coding agent builds apps that are modern, fast, and secure by default.-#### Skill Coverage in `v0.0.81`+#### Skill Coverage in `v0.0.82`<details>-<summary><strong>78 web features with implementation guidance from Chrome's experts</strong>: `::backdrop`, `:autofill`, `:has()`, `:not()`, `:user-valid and :user-invalid`, `@starting-style`, `<details>`, `<dialog closedby>`, `<dialog>`, `<link rel="expect">`, `<link rel="preload">`, `AbortController and AbortSignal`, `accent-color`, `Active view transition`, `Anchor positioning`, `blocking="render"`, `calc-size()`, `color-scheme`, `Container queries`, `content-visibility`, `Cross-document view transitions`, `Customizable <select>`, `Email, telephone, and URL <input> types`, `enterkeyhint`, `Fetch`, `Fetch priority`, `fetchLater`, `field-sizing`, `font-size-adjust`, `Form-associated WebMCP attributes`, `hidden="until-found"`, `image-set()`, `Individual transform properties`, `inert`, `inputmode`, `Interest invokers`, `interpolate-size`, `Intersection observer`, `Intl.DurationFormat`, `Invoker commands`, `Language detector`, `light-dark()`, `linear() easing`, `Long animation frames`, `Masks`, `moveBefore()`, `Mutually exclusive <details> elements`, `Navigation API`, `navigator.modelContext`, `overlay`, `Page visibility state`, `Popover`, `popover="hint"`, `prefers-color-scheme media query`, `prefers-contrast media query`, `prefers-reduced-motion media query`, `Registered custom properties`, `Scheduler API`, `Scroll snap`, `Scroll-driven animations`, `scroll-initial-target`, `scrollbar-color`, `scrollbar-width`, `scrollIntoView()`, `sibling-count() and sibling-index()`, `sin(), cos(), tan(), asin(), acos(), atan(), and atan2() (CSS)`, `Speculation rules`, `Summarizer`, `Temporal`, `text-box`, `text-wrap`, `text-wrap: balance`, `text-wrap: pretty`, `Top-level await`, `transition-behavior`, `Translator`, `View transitions`, `view-transition-class`</summary>+<summary><strong>79 web features with implementation guidance from Chrome's experts</strong>: `::backdrop`, `:autofill`, `:has()`, `:not()`, `:user-valid and :user-invalid`, `@starting-style`, `<details>`, `<dialog closedby>`, `<dialog>`, `<link rel="expect">`, `<link rel="preload">`, `AbortController and AbortSignal`, `accent-color`, `Active view transition`, `Anchor positioning`, `blocking="render"`, `calc-size()`, `color-scheme`, `Container queries`, `content-visibility`, `Cross-document view transitions`, `Customizable <select>`, `Email, telephone, and URL <input> types`, `enterkeyhint`, `Fetch`, `Fetch priority`, `fetchLater`, `field-sizing`, `font-size-adjust`, `Form-associated WebMCP attributes`, `hidden="until-found"`, `image-set()`, `Individual transform properties`, `inert`, `inputmode`, `Interest invokers`, `interpolate-size`, `Intersection observer`, `Intl.DurationFormat`, `Invoker commands`, `Language detector`, `light-dark()`, `linear() easing`, `Long animation frames`, `Masks`, `moveBefore()`, `Mutually exclusive <details> elements`, `Navigation API`, `navigator.modelContext`, `overlay`, `Page visibility`, `Page visibility state`, `Popover`, `popover="hint"`, `prefers-color-scheme media query`, `prefers-contrast media query`, `prefers-reduced-motion media query`, `Registered custom properties`, `Scheduler API`, `Scroll snap`, `Scroll-driven animations`, `scroll-initial-target`, `scrollbar-color`, `scrollbar-width`, `scrollIntoView()`, `sibling-count() and sibling-index()`, `sin(), cos(), tan(), asin(), acos(), atan(), and atan2() (CSS)`, `Speculation rules`, `Summarizer`, `Temporal`, `text-box`, `text-wrap`, `text-wrap: balance`, `text-wrap: pretty`, `Top-level await`, `transition-behavior`, `Translator`, `View transitions`, `view-transition-class`</summary>- **[::backdrop](https://webstatus.dev/features/backdrop), [<dialog>](https://webstatus.dev/features/dialog), [overlay](https://webstatus.dev/features/overlay), [Popover](https://webstatus.dev/features/popover), [@starting-style](https://webstatus.dev/features/starting-style), [transition-behavior](https://webstatus.dev/features/transition-behavior)**- **animate-to-from-top-layer**: Animate elements such as dialogs, popovers, and tooltips as they're entering/exiting the top layer.@@ -116,6 +116,8 @@ This curated collection of skills, tools, and AI-ready documentation injects Chr- **persistent-top-layer-ui**: Keep a modal dialog, fullscreen element, or native popover visibly open and functionally active when its underlying DOM node is moved or reparented in the DOM.- **[navigator.modelContext](https://webstatus.dev/features/navigator-modelcontext)**- **agentic-javascript-tools**: Programmatically register client-side JavaScript functions as tools for AI agents using the WebMCP Imperative API.+- **[Page visibility](https://webstatus.dev/features/page-visibility), [Page visibility state](https://webstatus.dev/features/page-visibility-state)**+ - **detect-initial-visibility-state**: Reliably determine whether a page was initially loaded in the background, even in cases where the script is loaded asynchronously after the user foregrounded the page.- **[Page visibility state](https://webstatus.dev/features/page-visibility-state)**- **calculate-total-foreground-time**: Calculate the total time a user actually spent viewing a page, excluding periods when the tab was in the background.- **[prefers-contrast media query](https://webstatus.dev/features/prefers-contrast), [scrollbar-color](https://webstatus.dev/features/scrollbar-color)**diff --git a/gemini-extension.json b/gemini-extension.jsonindex 9a31ec7..07e4eeb 100644--- a/gemini-extension.json+++ b/gemini-extension.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Google Chrome's web development agent skills.",- "version": "0.0.81",+ "version": "0.0.82","author": {"name": "Google Chrome"}diff --git a/package.json b/package.jsonindex e55d79d..d6effa7 100644--- a/package.json+++ b/package.json@@ -2,7 +2,7 @@"name": "modern-web-guidance","displayName": "Modern Web Guidance","description": "Curated collection of agent skills for modern web development.",- "version": "0.0.81",+ "version": "0.0.82","publisher": "GoogleChrome","engines": {"vscode": "^1.90.0",diff --git a/skills/modern-web/guides/performance/detect-initial-visibility-state.md b/skills/modern-web/guides/performance/detect-initial-visibility-state.mdnew file mode 100644index 0000000..2ff9e88--- /dev/null+++ b/skills/modern-web/guides/performance/detect-initial-visibility-state.md@@ -0,0 +1,97 @@+Determining if a page was initially loaded in the background (e.g., opened in a new background tab) is critical for accurate performance monitoring. Pages loaded in the background often have delayed rendering and longer metric times (like First Contentful Paint). Identifying these pages allows you to filter them out of performance analytics to avoid skewed data.++The most accurate way to measure this is by using the `VisibilityStateEntry` API, which reliably records visibility changes on the browser's performance timeline, regardless of when your script actually executes.++### Detecting initial visibility and background time++MANDATORY: Use `performance.getEntriesByType('visibility-state')` to access the exact visibility history. Do not rely solely on checking `document.visibilityState` at execution time, as it is susceptible to race conditions.++```javascript+/**+ * Accurately determines visibility state history using the Performance API.+ */+function getVisibilityInfo() {+ // Retrieve VisibilityStateEntry members:+ const entries = performance.getEntriesByType('visibility-state');++ if (entries.length > 0) {+ const firstEntry = entries[0];++ // If the first performance entry for visibility is 'hidden',+ // the page was loaded in the background.+ const initiallyBackgrounded = firstEntry.name === 'hidden';++ // Find the precise, high-resolution timestamp of when the page+ // was first backgrounded.+ let timeBackgrounded = null;+ for (const entry of entries) {+ if (entry.name === 'hidden') {+ // entry.startTime is used because it provides the exact browser+ // timestamp of the visibility change, which is required for precision+ timeBackgrounded = entry.startTime;+ break;+ }+ }++ return {+ initiallyBackgrounded,+ timeBackgrounded+ };+ }+}+```++### Fallback strategies++Page visibility state has limited availability.++For unsupported environments, you may fall back to checking the `document.visibilityState` property or listening for the `visibilitychange` event.++**MANDATORY:** You must understand that this fallback approach is often **highly inaccurate for determining initial background state**. Because scripts can load and execute asynchronously, a page could be opened in a background tab and then foregrounded by the user *before* your script has finished downloading and executing. When your script finally runs, `document.visibilityState` will synchronously read as `'visible'`, and you will incorrectly assume the page was loaded in the foreground, completely missing its initial hidden state. Furthermore, the fallback timestamp lacks the internal precision of the Performance API. If precision is a high priority, do not use the fallback.++```javascript+/**+ * Fallback implementation using document.visibilityState.+ * This approach is prone to race conditions if the script loads asynchronously.+ */+function getFallbackVisibilityInfo() {+ // Check the state exactly when this script executes.+ // This will fail to detect an initial background state if the user+ // foregrounded the page before this script executed.+ let initiallyBackgrounded = document.visibilityState === 'hidden';++ // If it's hidden now, we approximate that it was hidden from load (time 0).+ let timeBackgrounded = initiallyBackgrounded ? 0 : null;++ // Listen for future visibility changes to capture if it is backgrounded later.+ document.addEventListener('visibilitychange', () => {+ if (document.visibilityState === 'hidden' && timeBackgrounded === null) {+ // performance.now() is used here as a fallback, but it only gives+ // us the time the event listener fired, not the precise internal+ // browser time the visibility actually changed.+ timeBackgrounded = performance.now();+ }+ });++ return {+ get initiallyBackgrounded() { return initiallyBackgrounded; },+ get timeBackgrounded() { return timeBackgrounded; }+ };+}++// Modern implementation using VisibilityStateEntry API.+function getVisibilityInfo() {+ // Code omitted here would be the same modern+ // implementation shown earlier in this guide+ // ...+}++// DO: Detect if the VisibilityStateEntry API is available+if ('VisibilityStateEntry' in window) {+ // DO: If VisibilityStateEntry is available, use it first:+ getVisibilityInfo();+} else {+ // DO: If VisibilityStateEntry is unavailable, fall back to `document.visibilityState`:+ getFallbackVisibilityInfo();+}+```