Skip to content

Commit e9e15e0

Browse files
committed
fix: 全量识别在入口处兜底节流,加诊断日志定位源头
schedule 端的节流仍被绕过,把节流硬卡到 runActivePageDetection 入口,无论从哪条路径进来都过 30 秒节流;用户主动重检走 message-router 改传 force:true 跳过节流。同时给 schedule、run、onUpdated complete 三个关键点加 console.log,便于通过 service worker DevTools 控制台定位反复触发的真实源头。将版本号提升到 1.2.87。
1 parent e68883f commit e9e15e0

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "stackprism",
33
"private": true,
4-
"version": "1.2.86",
4+
"version": "1.2.87",
55
"type": "module",
66
"description": "StackPrism 用于检测网页前端、后端、CDN、SaaS、广告营销、统计、登录、支付、网站程序和主题模板线索。",
77
"scripts": {

src/background/detection.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const refreshAllBadges = async () => {
8686
}
8787
}
8888

89-
export const runActivePageDetection = async (tabId: number) => {
89+
export const runActivePageDetection = async (tabId: number, options: { force?: boolean } = {}) => {
9090
if (typeof tabId !== 'number' || tabId < 0) return
9191

9292
try {
@@ -96,7 +96,15 @@ export const runActivePageDetection = async (tabId: number) => {
9696
clearBadge(tabId)
9797
return
9898
}
99+
if (!options.force) {
100+
const last = lastDetectionRunAt.get(tabId) || 0
101+
if (last && Date.now() - last < DETECTION_THROTTLE_MS) {
102+
console.log('[SP detection] run skipped (throttle)', tabId, 'sinceLast', Date.now() - last + 'ms')
103+
return
104+
}
105+
}
99106
lastDetectionRunAt.set(tabId, Date.now())
107+
console.log('[SP detection] run start', tabId, 'force:', Boolean(options.force))
100108
await injectContentObserver(tabId)
101109
const [data, rules, settings] = await Promise.all([getTabData(tabId), loadTechRules(), loadDetectorSettings()])
102110
const pageRules = buildEffectivePageRules(rules.page || {}, settings)
@@ -154,8 +162,10 @@ export const scheduleActivePageDetection = (tabId: number, delay = 600) => {
154162
if (typeof tabId !== 'number' || tabId < 0) return
155163
const last = lastDetectionRunAt.get(tabId) || 0
156164
if (last && Date.now() - last < DETECTION_THROTTLE_MS) {
165+
console.log('[SP detection] schedule skipped (throttle)', tabId, 'sinceLast', Date.now() - last + 'ms')
157166
return
158167
}
168+
console.log('[SP detection] schedule', tabId, 'delay', delay + 'ms')
159169
clearActiveDetectionTimer(tabId)
160170
const timer = setTimeout(() => {
161171
activeDetectionTimers.delete(tabId)

src/background/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
7878
}
7979

8080
if (changeInfo.status === 'complete') {
81+
console.log('[SP detection] onUpdated complete', tabId, 'url', url)
8182
if (isDetectablePageUrl(url)) {
8283
scheduleActivePageDetection(tabId, 600)
8384
} else {

src/background/message-router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const registerMessageRouter = () => {
7777
if (!isDetectablePageUrl(tab.url)) {
7878
return clearUnsupportedTab(tabId)
7979
}
80-
return runActivePageDetection(tabId)
80+
return runActivePageDetection(tabId, { force: true })
8181
})
8282
.catch(() => {})
8383
return false

0 commit comments

Comments
 (0)