Keep your coding agent up to date with the latest web best practices
Release v0.0.151
github-actions[bot]9174c0d6cf98
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.jsonindex 8c8b070..6a7faf6 100644--- a/.claude-plugin/marketplace.json+++ b/.claude-plugin/marketplace.json@@ -8,7 +8,7 @@"name": "modern-web-guidance","source": "./","description": "Keep your coding agent up to date with the latest web best practices",- "version": "0.0.150"+ "version": "0.0.151"}]}diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.jsonindex aacd58d..c65639c 100644--- a/.claude-plugin/plugin.json+++ b/.claude-plugin/plugin.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Keep your coding agent up to date with the latest web best practices",- "version": "0.0.150",+ "version": "0.0.151","author": {"name": "Google Chrome"}diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.jsonindex aacd58d..c65639c 100644--- a/.cursor-plugin/plugin.json+++ b/.cursor-plugin/plugin.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Keep your coding agent up to date with the latest web best practices",- "version": "0.0.150",+ "version": "0.0.151","author": {"name": "Google Chrome"}diff --git a/README.md b/README.mdindex f047c9b..ab5ed6f 100644--- a/README.md+++ b/README.md@@ -36,7 +36,7 @@ Here's a tiny sampling of the **124 use-case-centric guides**:* **Accessibility & Security**: accessible error announcements, keyboard focus management.* **Built-in AI**: Leveraging local, on-device client models (native Language Detection, Summarization, and Translation APIs).-#### Full Skill Coverage (v0.0.150)+#### Full Skill Coverage (v0.0.151)<details><summary>Includes expert guidance across <strong>99 modern web features</strong></summary>diff --git a/gemini-extension.json b/gemini-extension.jsonindex aacd58d..c65639c 100644--- a/gemini-extension.json+++ b/gemini-extension.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Keep your coding agent up to date with the latest web best practices",- "version": "0.0.150",+ "version": "0.0.151","author": {"name": "Google Chrome"}diff --git a/package.json b/package.jsonindex 7376d31..5d836e6 100644--- a/package.json+++ b/package.json@@ -3,7 +3,7 @@"displayName": "Modern Web Guidance","description": "Keep your agent up to date on the latest web best practices.","license": "Apache-2.0",- "version": "0.0.150",+ "version": "0.0.151","publisher": "GoogleChrome","engines": {"vscode": "^1.90.0",diff --git a/skills/modern-web-guidance/guides/performance/calculate-total-foreground-time.md b/skills/modern-web-guidance/guides/performance/calculate-total-foreground-time.mdindex 6049ffb..9794788 100644--- a/skills/modern-web-guidance/guides/performance/calculate-total-foreground-time.md+++ b/skills/modern-web-guidance/guides/performance/calculate-total-foreground-time.md@@ -1,6 +1,8 @@-This guide details how to accurately calculate the total time a user spends actively viewing a page. Traditional metrics like time-on-page often incorrectly include time spent with the tab in the background. By using the `VisibilityStateEntry` API, you can measure only the "foreground time," providing a better metric of user engagement.+# Calculate total foreground time-### Implementing foreground time calculation+This guide details how to accurately calculate the total time a user spends actively viewing a page. Traditional metrics like time-on-page often incorrectly include time spent with the page in the background. By using the `VisibilityStateEntry` API, you can measure only the "foreground time," providing a better metric of user engagement.++## Implementing foreground time calculationThe `PerformanceTimeline` API exposes visibility state changes as performance entries. Rather than reacting to `visibilitychange` events and manually accumulating time throughout a session, you can query the entire visibility history at any time.@@ -9,14 +11,14 @@ MANDATORY: You must query the `visibility-state` performance entries to calculat```javascript/*** Calculates total time the page was in the visible state.- *+ ** @returns {number} Total foreground time in milliseconds.*/function getTotalForegroundTime() {// MANDATORY: Query the visibility-state entries from the performance timeline.const entries = performance.getEntriesByType('visibility-state');- // Fallback: If the browser does not support VisibilityStateEntry,+ // Fallback: If the browser does not support VisibilityStateEntry,// the API will gracefully return an empty array.if (entries.length === 0) {// Return total time since navigation start as a fallback.@@ -29,13 +31,13 @@ function getTotalForegroundTime() {// Only calculate duration for periods where the state was 'visible'if (entries[i].name === 'visible') {const start = entries[i].startTime;-- // The end time is the start time of the next state change,++ // The end time is the start time of the next state change,// or the current time if this is the final entry.const end = i + 1 < entries.length? entries[i + 1].startTime: performance.now();-+totalForegroundTime += (end - start);}}@@ -44,23 +46,24 @@ function getTotalForegroundTime() {}```-### Fallback strategies+## Fallbacks & browser supportPage visibility state has limited availability.Supported by: Chrome 115 (Jul 2023) and Edge 115 (Jul 2023).Unsupported in: Firefox and Safari.-The `VisibilityStateEntry` API has limited availability and is currently unsupported in several major browsers.+The `VisibilityStateEntry` API is a modern addition to the Performance Timeline and may not be supported in all browsers.-Because `performance.getEntriesByType('visibility-state')` will return an empty array in browsers that do not support it, feature detection is straightforward and built directly into the execution flow. You must always check if the returned array is empty before attempting to calculate foreground time.+Because `performance.getEntriesByType('visibility-state')` returns an empty array in unsupported browsers, feature detection is built into the calculation flow. You should always check if entries are returned before proceeding.-If it is empty, the recommended fallback strategy is to gracefully degrade to standard time-on-page analytics by returning `performance.now()`. This represents the total time elapsed since the page was loaded, ensuring a valid duration is still recorded without throwing runtime errors.+If the API is unsupported, the recommended fallback is to return `performance.now()`. This represents the total time since navigation, which serves as a reasonable upper bound for engagement time when visibility state history is unavailable.```javascriptconst entries = performance.getEntriesByType('visibility-state');-// Empty array means unsupported+// If the array is empty, the API is likely unsupported.if (entries.length === 0) {- return performance.now(); // Fallback+ // Fallback: Return total time since page load.+ return performance.now();}```