Skip to content

Commit 0fc4393

Browse files
committed
feat: Rebase master with beacon transport
1 parent 3e0544e commit 0fc4393

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/browser/src/backend.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Backend, logger, Options, SentryError } from '@sentry/core';
22
import { SentryEvent, SentryEventHint, SentryResponse, Severity, Status, Transport } from '@sentry/types';
33
import { isDOMError, isDOMException, isError, isErrorEvent, isPlainObject } from '@sentry/utils/is';
4-
import { supportsFetch } from '@sentry/utils/supports';
4+
import { supportsBeacon, supportsFetch } from '@sentry/utils/supports';
55
import { eventFromPlainObject, eventFromStacktrace, prepareFramesForEvent } from './parsers';
66
import { computeStackTrace } from './tracekit';
7-
import { FetchTransport, XHRTransport } from './transports';
7+
import { BeaconTransport, FetchTransport, XHRTransport } from './transports';
88

99
/**
1010
* Configuration options for the Sentry Browser SDK.
@@ -149,11 +149,16 @@ export class BrowserBackend implements Backend {
149149
const transportOptions = this.options.transportOptions
150150
? this.options.transportOptions
151151
: { dsn: this.options.dsn };
152-
this.transport = this.options.transport
153-
? new this.options.transport({ dsn: this.options.dsn })
154-
: supportsFetch()
155-
? new FetchTransport(transportOptions)
156-
: new XHRTransport(transportOptions);
152+
153+
if (this.options.transport) {
154+
this.transport = new this.options.transport({ dsn: this.options.dsn });
155+
} else if (supportsBeacon()) {
156+
this.transport = new BeaconTransport(transportOptions);
157+
} else if (supportsFetch()) {
158+
this.transport = new FetchTransport(transportOptions);
159+
} else {
160+
this.transport = new XHRTransport(transportOptions);
161+
}
157162
}
158163

159164
return this.transport.send(event);

0 commit comments

Comments
 (0)