File tree Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { addGlobalEventProcessor , getCurrentHub } from '@sentry/hub' ;
2
- import { Event , Integration } from '@sentry/types' ;
2
+ import { Event , Integration , StackFrame } from '@sentry/types' ;
3
3
import { getEventDescription , isMatchingPattern , logger } from '@sentry/utils' ;
4
4
5
5
// "Script error." is hard coded into browsers for errors that it can't read.
@@ -189,17 +189,30 @@ export class InboundFilters implements Integration {
189
189
return [ ] ;
190
190
}
191
191
192
+ /** JSDoc */
193
+ private _getLastValidUrl ( frames : StackFrame [ ] = [ ] ) : string | null {
194
+ for ( let i = frames . length - 1 ; i >= 0 ; i -- ) {
195
+ const frame = frames [ i ] ;
196
+
197
+ if ( frame ?. filename !== '<anonymous>' ) {
198
+ return frame . filename || null ;
199
+ }
200
+ }
201
+
202
+ return null ;
203
+ }
204
+
192
205
/** JSDoc */
193
206
private _getEventFilterUrl ( event : Event ) : string | null {
194
207
try {
195
208
if ( event . stacktrace ) {
196
209
const frames = event . stacktrace . frames ;
197
- return ( frames && frames [ frames . length - 1 ] . filename ) || null ;
210
+ return this . _getLastValidUrl ( frames ) ;
198
211
}
199
212
if ( event . exception ) {
200
213
const frames =
201
214
event . exception . values && event . exception . values [ 0 ] . stacktrace && event . exception . values [ 0 ] . stacktrace . frames ;
202
- return ( frames && frames [ frames . length - 1 ] . filename ) || null ;
215
+ return this . _getLastValidUrl ( frames ) ;
203
216
}
204
217
return null ;
205
218
} catch ( oO ) {
Original file line number Diff line number Diff line change @@ -456,5 +456,36 @@ describe('InboundFilters', () => {
456
456
) ,
457
457
) . toBe ( true ) ;
458
458
} ) ;
459
+
460
+ it ( 'should search for script names when there is an anonymous callback at the last frame' , ( ) => {
461
+ const messageEvent = {
462
+ message : 'any' ,
463
+ stacktrace : {
464
+ frames : [
465
+ { filename : 'https://our-side.com/js/bundle.js' } ,
466
+ { filename : 'https://awesome-analytics.io/some/file.js' } ,
467
+ { filename : '<anonymous>' } ,
468
+ ] ,
469
+ } ,
470
+ } ;
471
+
472
+ expect (
473
+ inboundFilters . _isAllowedUrl (
474
+ messageEvent ,
475
+ inboundFilters . _mergeOptions ( {
476
+ allowUrls : [ 'https://awesome-analytics.io/some/file.js' ] ,
477
+ } ) ,
478
+ ) ,
479
+ ) . toBe ( true ) ;
480
+
481
+ expect (
482
+ inboundFilters . _isDeniedUrl (
483
+ messageEvent ,
484
+ inboundFilters . _mergeOptions ( {
485
+ denyUrls : [ 'https://awesome-analytics.io/some/file.js' ] ,
486
+ } ) ,
487
+ ) ,
488
+ ) . toBe ( true ) ;
489
+ } ) ;
459
490
} ) ;
460
491
} ) ;
You can’t perform that action at this time.
0 commit comments