@@ -8,7 +8,7 @@ import { proxyFetch, proxyXhr } from '../lib/proxyHandler'
8
8
import getFirstVisitedState from '../lib/getFirstVisitedState'
9
9
import metricsStore from '../lib/store'
10
10
import { IReportHandler } from '../types'
11
- import { getApiPath , isIncludeArr , isEqualArr } from '../utils'
11
+ import { getApiPath , isIncludeArr , isEqualArr , isExistPath } from '../utils'
12
12
import getPath from '../utils/getPath'
13
13
import { isPerformanceSupported } from '../utils/isSupported'
14
14
import { metricsName } from '../constants'
@@ -65,7 +65,7 @@ const beforeHandler = (url, apiConfig, hashHistory, excludeRemotePath) => {
65
65
const firstVisitedState = getFirstVisitedState ( ) . state
66
66
if ( firstVisitedState ) {
67
67
const remotePath = getApiPath ( url )
68
- if ( ! excludeRemotePath ?. includes ( remotePath ) ) {
68
+ if ( ! isExistPath ( excludeRemotePath , remotePath ) ) {
69
69
if ( apiConfig && apiConfig [ path ] ) {
70
70
if ( apiConfig [ path ] . some ( ( o ) => remotePath === o ) ) {
71
71
remoteQueue . queue . push ( remotePath )
@@ -82,32 +82,33 @@ const beforeHandler = (url, apiConfig, hashHistory, excludeRemotePath) => {
82
82
}
83
83
}
84
84
85
- const afterHandler = ( url , apiConfig , store , hashHistory ) => {
85
+ const afterHandler = ( url , apiConfig , store , hashHistory , excludeRemotePath ) => {
86
86
if ( isPerformanceSupported ( ) ) {
87
87
const path = getPath ( location , hashHistory )
88
88
const firstVisitedState = getFirstVisitedState ( ) . state
89
89
if ( firstVisitedState ) {
90
90
const remotePath = getApiPath ( url )
91
- completeQueue . push ( remotePath )
92
- if ( apiConfig && apiConfig [ path ] ) {
93
- if ( isIncludeArr ( remoteQueue . queue , completeQueue ) && ! remoteQueue . hasStoreMetrics ) {
94
- console . log ( 'api list = ' , remoteQueue . queue )
95
- remoteQueue . hasStoreMetrics = true
96
- const now = performance . now ( )
97
- if ( now < getFirstHiddenTime ( ) . timeStamp ) {
98
- storeMetrics ( metricsName . ACT , now , store )
99
- computeCCPAndRL ( store )
91
+ if ( ! isExistPath ( excludeRemotePath , remotePath ) ) {
92
+ completeQueue . push ( remotePath )
93
+ if ( apiConfig && apiConfig [ path ] ) {
94
+ if ( isIncludeArr ( remoteQueue . queue , completeQueue ) && ! remoteQueue . hasStoreMetrics ) {
95
+ console . log ( 'api list = ' , remoteQueue . queue )
96
+ remoteQueue . hasStoreMetrics = true
97
+ const now = performance . now ( )
98
+ if ( now < getFirstHiddenTime ( ) . timeStamp ) {
99
+ storeMetrics ( metricsName . ACT , now , store )
100
+ computeCCPAndRL ( store )
101
+ }
100
102
}
101
- }
102
- } else {
103
- console . log ( remoteQueue . queue , completeQueue )
104
- if ( isIncludeArr ( remoteQueue . queue , completeQueue ) && ! remoteQueue . hasStoreMetrics && isDone ) {
105
- console . log ( 'api list = ' , remoteQueue . queue )
106
- remoteQueue . hasStoreMetrics = true
107
- const now = performance . now ( )
108
- if ( now < getFirstHiddenTime ( ) . timeStamp ) {
109
- storeMetrics ( metricsName . ACT , now , store )
110
- computeCCPAndRL ( store )
103
+ } else {
104
+ if ( isIncludeArr ( remoteQueue . queue , completeQueue ) && ! remoteQueue . hasStoreMetrics && isDone ) {
105
+ console . log ( 'api list = ' , remoteQueue . queue )
106
+ remoteQueue . hasStoreMetrics = true
107
+ const now = performance . now ( )
108
+ if ( now < getFirstHiddenTime ( ) . timeStamp ) {
109
+ storeMetrics ( metricsName . ACT , now , store )
110
+ computeCCPAndRL ( store )
111
+ }
111
112
}
112
113
}
113
114
}
@@ -152,6 +153,16 @@ const maxWaitTime4Report = (cb: () => void, maxWaitCCPDuration) => {
152
153
setTimeout ( cb , maxWaitCCPDuration )
153
154
}
154
155
156
+ /**
157
+ * @param {metricsStore } store
158
+ * @param {Function } report
159
+ * @param {boolean } isCustomEvent
160
+ * @param { { [prop: string]: Array<string> } } apiConfig
161
+ * @param { boolean } hashHistory
162
+ * @param { Array<string> } excludeRemotePath
163
+ * @param { number } maxWaitCCPDuration
164
+ * @param { boolean } immediately
165
+ * */
155
166
export const initCCP = (
156
167
store : metricsStore ,
157
168
report : IReportHandler ,
@@ -193,10 +204,10 @@ export const initCCP = (
193
204
194
205
proxyXhr (
195
206
( url ) => beforeHandler ( url , apiConfig , hashHistory , excludeRemotePath ) ,
196
- ( url ) => afterHandler ( url , apiConfig , store , hashHistory )
207
+ ( url ) => afterHandler ( url , apiConfig , store , hashHistory , excludeRemotePath )
197
208
)
198
209
proxyFetch (
199
210
( url ) => beforeHandler ( url , apiConfig , hashHistory , excludeRemotePath ) ,
200
- ( url ) => afterHandler ( url , apiConfig , store , hashHistory )
211
+ ( url ) => afterHandler ( url , apiConfig , store , hashHistory , excludeRemotePath )
201
212
)
202
213
}
0 commit comments