1- import { configureScope } from '@sentry/core' ;
1+ import { configureScope , getCurrentHub } from '@sentry/core' ;
22import { Integration , SentryEvent } from '@sentry/types' ;
33import { getGlobalObject } from '@sentry/utils/misc' ;
44
@@ -14,24 +14,26 @@ export class UserAgent implements Integration {
1414 /**
1515 * @inheritDoc
1616 */
17- public install ( ) : void {
18- configureScope ( scope => {
19- scope . addEventProcessor ( async ( event : SentryEvent ) => {
20- if ( ! global . navigator || ! global . location ) {
21- return event ;
22- }
17+ public setupOnce ( ) : void {
18+ if ( getCurrentHub ( ) . getIntegration ( this . name ) ) {
19+ configureScope ( scope => {
20+ scope . addEventProcessor ( async ( event : SentryEvent ) => {
21+ if ( ! global . navigator || ! global . location ) {
22+ return event ;
23+ }
2324
24- // HTTP Interface: https://docs.sentry.io/clientdev/interfaces/http/?platform=javascript
25- const request = event . request || { } ;
26- request . url = request . url || global . location . href ;
27- request . headers = request . headers || { } ;
28- request . headers [ 'User-Agent' ] = global . navigator . userAgent ;
25+ // HTTP Interface: https://docs.sentry.io/clientdev/interfaces/http/?platform=javascript
26+ const request = event . request || { } ;
27+ request . url = request . url || global . location . href ;
28+ request . headers = request . headers || { } ;
29+ request . headers [ 'User-Agent' ] = global . navigator . userAgent ;
2930
30- return {
31- ...event ,
32- request,
33- } ;
31+ return {
32+ ...event ,
33+ request,
34+ } ;
35+ } ) ;
3436 } ) ;
35- } ) ;
37+ }
3638 }
3739}
0 commit comments