@@ -3,9 +3,10 @@ import { clearBadge, clearTabSession } from './tab-store'
33import { clearDynamicSnapshotTimer , clearPendingDynamicSnapshot } from './dynamic-snapshot'
44import { buildHeaderRecord , dedupeApiRecords } from './headers'
55import { clearActiveDetectionTimer , refreshAllBadges , saveTabDataAndBadge , scheduleActivePageDetection } from './detection'
6- import { getTabData } from './tab-store'
6+ import { getTabData , getTabSnapshot } from './tab-store'
77import { SETTINGS_STORAGE_KEY , applyDetectorSettingsUpdate , loadDetectorSettings , loadTechRules } from './detector-settings'
88import { registerMessageRouter } from './message-router'
9+ import { isDetectablePageUrl , isObservableRequestUrl } from '@/utils/page-support'
910
1011registerMessageRouter ( )
1112
@@ -24,7 +25,21 @@ chrome.tabs.onRemoved.addListener(tabId => {
2425 clearTabSession ( tabId )
2526} )
2627
27- chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo ) => {
28+ const clearTabDetectionState = ( tabId : number ) => {
29+ clearActiveDetectionTimer ( tabId )
30+ clearDynamicSnapshotTimer ( tabId )
31+ clearPendingDynamicSnapshot ( tabId )
32+ clearBadge ( tabId )
33+ clearTabSession ( tabId ) . catch ( ( ) => { } )
34+ }
35+
36+ chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
37+ const url = changeInfo . url || tab . url || ''
38+ if ( url && ! isDetectablePageUrl ( url ) ) {
39+ clearTabDetectionState ( tabId )
40+ return
41+ }
42+
2843 if ( changeInfo . status === 'loading' ) {
2944 clearActiveDetectionTimer ( tabId )
3045 clearDynamicSnapshotTimer ( tabId )
@@ -34,7 +49,11 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
3449 }
3550
3651 if ( changeInfo . status === 'complete' ) {
37- scheduleActivePageDetection ( tabId , 600 )
52+ if ( isDetectablePageUrl ( url ) ) {
53+ scheduleActivePageDetection ( tabId , 600 )
54+ } else {
55+ clearTabDetectionState ( tabId )
56+ }
3857 }
3958} )
4059
@@ -48,17 +67,26 @@ chrome.storage.onChanged.addListener((changes, areaName) => {
4867chrome . webRequest . onHeadersReceived . addListener (
4968 details => {
5069 if ( details . tabId < 0 || ! details . responseHeaders ) return
70+ if ( ! isObservableRequestUrl ( details . url ) ) return
5171
52- Promise . all ( [ getTabData ( details . tabId ) , loadTechRules ( ) , loadDetectorSettings ( ) ] )
53- . then ( ( [ data , rules , settings ] ) => {
72+ Promise . all ( [ getTabData ( details . tabId ) , loadTechRules ( ) , loadDetectorSettings ( ) , getTabSnapshot ( details . tabId ) ] )
73+ . then ( ( [ data , rules , settings , tab ] ) => {
74+ if ( details . type === 'main_frame' && ! isDetectablePageUrl ( details . url ) ) {
75+ clearTabDetectionState ( details . tabId )
76+ return
77+ }
78+ if ( details . type !== 'main_frame' && ! isDetectablePageUrl ( tab . url ) ) {
79+ clearTabDetectionState ( details . tabId )
80+ return
81+ }
5482 const record = buildHeaderRecord ( details , rules . headers || { } , settings )
5583 if ( details . type === 'main_frame' ) {
5684 data . main = record
5785 data . apis = [ ]
5886 data . frames = [ ]
5987 delete data . page
6088 delete data . dynamic
61- } else if ( details . type === 'xmlhttprequest' || ( details . type as string ) === 'fetch' ) {
89+ } else if ( details . type === 'xmlhttprequest' || ( details . type as string ) === 'fetch' || details . type === 'websocket' ) {
6290 data . apis = dedupeApiRecords ( [ record , ...( data . apis || [ ] ) ] )
6391 } else if ( details . type === 'sub_frame' ) {
6492 data . frames = dedupeApiRecords ( [ record , ...( data . frames || [ ] ) ] ) . slice ( 0 , 10 )
@@ -68,6 +96,6 @@ chrome.webRequest.onHeadersReceived.addListener(
6896 } )
6997 . catch ( ( ) => { } )
7098 } ,
71- { urls : [ '<all_urls> ' ] } ,
99+ { urls : [ 'http://*/*' , 'https://*/*' , 'ws://*/*' , 'wss://*/* '] } ,
72100 [ 'responseHeaders' , 'extraHeaders' ]
73101)
0 commit comments