Skip to content

Commit a2bdc01

Browse files
committed
perf: 降低 content-observer 主线程开销
子树扫描选择器去掉 [id]/[class] 这两条命中所有元素的宽匹配,改为靠框架专属属性识别;mutation 批处理从 requestAnimationFrame 改为 requestIdleCallback,让出用户交互帧;URL 兜底轮询从 1.2 秒拉到 5 秒。 将版本号提升到 1.2.77。
1 parent b42bbd5 commit a2bdc01

2 files changed

Lines changed: 10 additions & 9 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.76",
4+
"version": "1.2.77",
55
"type": "module",
66
"description": "StackPrism 用于检测网页前端、后端、CDN、SaaS、广告营销、统计、登录、支付、网站程序和主题模板线索。",
77
"scripts": {

src/content/content-observer.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@
214214
}
215215

216216
const SUBTREE_SCAN_LIMIT = 200
217-
const SUBTREE_SELECTOR = 'script[src], link[href], iframe[src], [id], [class], [data-v-app], [ng-version], astro-island, astro-slot'
217+
const SUBTREE_SELECTOR =
218+
'script[src], link[href], iframe[src], [data-v-app], [ng-version], [data-reactroot], [data-turbo], [data-controller], astro-island, astro-slot'
218219

219220
const matchesSkipContainer = element => {
220221
const tokens = []
@@ -342,8 +343,8 @@
342343
stopped = true
343344
clearTimeout(sendTimer)
344345
if (pendingMutationFrame) {
345-
if (typeof cancelAnimationFrame === 'function') {
346-
cancelAnimationFrame(pendingMutationFrame)
346+
if (typeof cancelIdleCallback === 'function') {
347+
cancelIdleCallback(pendingMutationFrame)
347348
} else {
348349
clearTimeout(pendingMutationFrame)
349350
}
@@ -453,10 +454,10 @@
453454

454455
const scheduleMutationFlush = () => {
455456
if (pendingMutationFrame || stopped) return
456-
if (typeof requestAnimationFrame === 'function') {
457-
pendingMutationFrame = requestAnimationFrame(processPendingMutationNodes)
457+
if (typeof requestIdleCallback === 'function') {
458+
pendingMutationFrame = requestIdleCallback(processPendingMutationNodes, { timeout: 1000 })
458459
} else {
459-
pendingMutationFrame = setTimeout(processPendingMutationNodes, 16)
460+
pendingMutationFrame = setTimeout(processPendingMutationNodes, 200)
460461
}
461462
}
462463

@@ -484,7 +485,7 @@
484485
mutationCooldownUntil = now + MUTATION_COOLDOWN_MS
485486
pendingMutationNodes = []
486487
if (pendingMutationFrame) {
487-
if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(pendingMutationFrame)
488+
if (typeof cancelIdleCallback === 'function') cancelIdleCallback(pendingMutationFrame)
488489
else clearTimeout(pendingMutationFrame)
489490
pendingMutationFrame = 0
490491
}
@@ -517,7 +518,7 @@
517518
history.pushState = wrappedPushState
518519
history.replaceState = wrappedReplaceState
519520
window.addEventListener('popstate', handleUrlChange)
520-
navigationInterval = window.setInterval(handleUrlChange, 1200)
521+
navigationInterval = window.setInterval(handleUrlChange, 5000)
521522
}
522523

523524
const installContextInvalidationGuards = () => {

0 commit comments

Comments
 (0)