File tree Expand file tree Collapse file tree 2 files changed +12
-29
lines changed Expand file tree Collapse file tree 2 files changed +12
-29
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ import { eventFromException, eventFromMessage } from './eventbuilder';
13
13
import { Breadcrumbs } from './integrations' ;
14
14
import { BREADCRUMB_INTEGRATION_ID } from './integrations/breadcrumbs' ;
15
15
import { BrowserTransportOptions } from './transports/types' ;
16
- import { sendReport } from './transports/utils' ;
17
16
18
17
const globalObject = getGlobalObject < Window > ( ) ;
19
18
@@ -165,7 +164,18 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
165
164
const envelope = createClientReportEnvelope ( outcomes , this . _options . tunnel && dsnToString ( this . _dsn ) ) ;
166
165
167
166
try {
168
- sendReport ( url , serializeEnvelope ( envelope ) ) ;
167
+ const global = getGlobalObject < Window > ( ) ;
168
+ const isRealNavigator = Object . prototype . toString . call ( global && global . navigator ) === '[object Navigator]' ;
169
+ const hasSendBeacon = isRealNavigator && typeof global . navigator . sendBeacon === 'function' ;
170
+ // Prevent illegal invocations - https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
171
+ if ( hasSendBeacon && ! this . _options . tunnel ) {
172
+ const sendBeacon = global . navigator . sendBeacon . bind ( global . navigator ) ;
173
+ sendBeacon ( url , serializeEnvelope ( envelope ) ) ;
174
+ } else {
175
+ // If beacon is not supported or if they are using the tunnel option
176
+ // use our regular transport to send client reports to Sentry.
177
+ this . _sendEnvelope ( envelope ) ;
178
+ }
169
179
} catch ( e ) {
170
180
__DEBUG_BUILD__ && logger . error ( e ) ;
171
181
}
Original file line number Diff line number Diff line change @@ -77,30 +77,3 @@ export function getNativeFetchImplementation(): FetchImpl {
77
77
return ( cachedFetchImpl = fetchImpl . bind ( global ) ) ;
78
78
/* eslint-enable @typescript-eslint/unbound-method */
79
79
}
80
-
81
- /**
82
- * Sends sdk client report using sendBeacon or fetch as a fallback if available
83
- *
84
- * @param url report endpoint
85
- * @param body report payload
86
- */
87
- export function sendReport ( url : string , body : string | Uint8Array ) : void {
88
- const isRealNavigator = Object . prototype . toString . call ( global && global . navigator ) === '[object Navigator]' ;
89
- const hasSendBeacon = isRealNavigator && typeof global . navigator . sendBeacon === 'function' ;
90
-
91
- if ( hasSendBeacon ) {
92
- // Prevent illegal invocations - https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
93
- const sendBeacon = global . navigator . sendBeacon . bind ( global . navigator ) ;
94
- sendBeacon ( url , body ) ;
95
- } else if ( supportsFetch ( ) ) {
96
- const fetch = getNativeFetchImplementation ( ) ;
97
- fetch ( url , {
98
- body,
99
- method : 'POST' ,
100
- credentials : 'omit' ,
101
- keepalive : true ,
102
- } ) . then ( null , error => {
103
- __DEBUG_BUILD__ && logger . error ( error ) ;
104
- } ) ;
105
- }
106
- }
You can’t perform that action at this time.
0 commit comments