Repository navigation
fix(stats): 统计面板只在统计页挂载 - #3
Merged
Merged
Conversation
The stats content script runs on every chatgpt.com page because SPA route changes do not re-inject content scripts. Mounting relied on WXT's autoMount, which only requires the anchor selector to resolve, and the fallback selectors match generic layout containers that also exist in the chat UI. The panel therefore appeared at the bottom of normal chat pages while waiting for analytics data that never arrives. Gate mounting on the analytics route and replace autoMount with an explicit mount/unmount sync. wxt:locationchange fires before the URL commits, so unmounting uses the event's destination path; entering the analytics route mounts on the first render mutation after the commit. Remount when the official container is replaced, and keep the panel when only its children are re-ordered. The two exact match patterns are redundant with chatgpt.com/*, which the SPA requires, so the runtime route check is the single source of truth. Fixes #2
devcxl
force-pushed
the
fix/stats-mount-only-on-analytics-pages
branch
from
October 18, 2026 15:22
fbd72eb to
fb48d82
Compare
Owner
Author
审查范围
Standards仓库没有文档化的编码规范(无
Minor: Spec(a) 缺失或部分实现
(b) 未被要求的改动
(c) 看似实现但实现有误
总结
审查后修复已合入 fb48d82,CI(39140216385)通过;Playwright 行为验证(普通页不挂载、统计页挂载、SPA 双向切换、仅路由变化、容器替换、重新挂载后渲染数据)全部通过。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
修复 #2:普通聊天界面也会注入「ChatGPT 使用统计」面板,内容停在「等待官方统计数据」。
根因
stats内容脚本必须匹配https://chatgpt.com/*:ChatGPT 是 SPA,站内路由切换不会重新注入内容脚本,只匹配统计页 URL 会让「首页 → 统计页」的导航失效。ui.autoMount(),其判定条件仅为ANALYTICS_ANCHOR_SELECTOR能匹配到元素。选择器的回退项是通用布局类名(div:not([hidden]) > div.flex.flex-col > div.flex.w-full.flex-col、div.pb-8:nth-child(2)),聊天页主列同样满足,面板就被追加到聊天布局末尾。修改
entrypoints/stats.content/index.ts:isAnalyticsPage():按location.pathname判定/settings/usage与旧版/codex/cloud/settings/analytics(兼容末尾斜杠)。wxt:locationchange:SPA 前进/后退时重新同步,离开统计页立即ui.remove()。sync()替代autoMount():非统计页不挂载;统计页等待官方卡片容器异步渲染后再挂载;官方容器被整体替换时重新挂载。matches保持不变(SPA 需要),补充注释说明页面过滤由运行时路由判定负责。验证
npm run lint、npm run type-check:通过npm run build:chrome、npm run build:firefox、./scripts/verify-manifest.sh:通过https://chatgpt.com/**fixture 做行为验证,全部通过:/settings:不挂载/settings/usage(含末尾斜杠)/ 旧版 Codex 统计页:挂载,且位于统计卡片容器末尾风险与回滚
ANALYTICS_PAGE_PATHS;漏改的表现是统计页不显示面板(而不是错误页面显示面板)。