Skip to content

Commit fb848ea

Browse files
authored
fix: Remove beacon transport (#1953)
Same as #1952 for `4.x`
1 parent d9bb595 commit fb848ea

File tree

8 files changed

+7
-181
lines changed

8 files changed

+7
-181
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## 4.6.5
6+
7+
- [browser] fix: Remove beacon transport.
8+
59
## 4.6.4
610

711
- [utils] fix: Prevent decycling from referencing original objects

packages/browser/src/backend.ts

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

99
/**
1010
* Configuration options for the Sentry Browser SDK.
@@ -58,8 +58,6 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
5858

5959
if (this.options.transport) {
6060
return new this.options.transport(transportOptions);
61-
} else if (supportsBeacon()) {
62-
return new BeaconTransport(transportOptions);
6361
} else if (supportsFetch()) {
6462
return new FetchTransport(transportOptions);
6563
}

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { logger } from '@sentry/utils/logger';
55
import { getEventDescription, getGlobalObject, parseUrl } from '@sentry/utils/misc';
66
import { deserialize, fill, safeNormalize } from '@sentry/utils/object';
77
import { includes, safeJoin } from '@sentry/utils/string';
8-
import { supportsBeacon, supportsHistory, supportsNativeFetch } from '@sentry/utils/supports';
8+
import { supportsHistory, supportsNativeFetch } from '@sentry/utils/supports';
99
import { BrowserClient } from '../client';
1010
import { breadcrumbEventHandler, keypressEventHandler, wrap } from './helpers';
1111

@@ -24,7 +24,6 @@ export interface SentryWrappedXMLHttpRequest extends XMLHttpRequest {
2424

2525
/** JSDoc */
2626
interface BreadcrumbIntegrations {
27-
beacon?: boolean;
2827
console?: boolean;
2928
dom?: boolean;
3029
fetch?: boolean;
@@ -53,7 +52,6 @@ export class Breadcrumbs implements Integration {
5352
*/
5453
public constructor(options?: BreadcrumbIntegrations) {
5554
this.options = {
56-
beacon: true,
5755
console: true,
5856
dom: true,
5957
fetch: true,
@@ -64,56 +62,6 @@ export class Breadcrumbs implements Integration {
6462
};
6563
}
6664

67-
/** JSDoc */
68-
private instrumentBeacon(): void {
69-
if (!supportsBeacon()) {
70-
return;
71-
}
72-
73-
/** JSDoc */
74-
function beaconReplacementFunction(originalBeaconFunction: () => void): () => void {
75-
return function(this: History, ...args: any[]): void {
76-
const url = args[0];
77-
const data = args[1];
78-
// If the browser successfully queues the request for delivery, the method returns "true" and returns "false" otherwise.
79-
// https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API/Using_the_Beacon_API
80-
const result = originalBeaconFunction.apply(this, args);
81-
82-
const client = getCurrentHub().getClient() as BrowserClient;
83-
const dsn = client && client.getDsn();
84-
if (dsn) {
85-
const filterUrl = new API(dsn).getStoreEndpoint();
86-
// if Sentry key appears in URL, don't capture it as a request
87-
// but rather as our own 'sentry' type breadcrumb
88-
if (filterUrl && includes(url, filterUrl)) {
89-
addSentryBreadcrumb(data);
90-
return result;
91-
}
92-
}
93-
94-
// What is wrong with you TypeScript...
95-
const breadcrumbData = ({
96-
category: 'beacon',
97-
data,
98-
type: 'http',
99-
} as any) as { [key: string]: any };
100-
101-
if (!result) {
102-
breadcrumbData.level = Severity.Error;
103-
}
104-
105-
Breadcrumbs.addBreadcrumb(breadcrumbData, {
106-
input: args,
107-
result,
108-
});
109-
110-
return result;
111-
};
112-
}
113-
114-
fill(global.navigator, 'sendBeacon', beaconReplacementFunction);
115-
}
116-
11765
/** JSDoc */
11866
private instrumentConsole(): void {
11967
if (!('console' in global)) {
@@ -481,9 +429,6 @@ export class Breadcrumbs implements Integration {
481429
if (this.options.fetch) {
482430
this.instrumentFetch();
483431
}
484-
if (this.options.beacon) {
485-
this.instrumentBeacon();
486-
}
487432
if (this.options.history) {
488433
this.instrumentHistory();
489434
}

packages/browser/src/transports/beacon.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export { BaseTransport } from './base';
22
export { FetchTransport } from './fetch';
33
export { XHRTransport } from './xhr';
4-
export { BeaconTransport } from './beacon';

packages/browser/test/transports/beacon.test.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

packages/utils/src/supports.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,6 @@ export function supportsNativeFetch(): boolean {
9292
return fetch.toString().indexOf('native') !== -1;
9393
}
9494

95-
/**
96-
* Tells whether current environment supports sendBeacon API
97-
* {@link supportsBeacon}.
98-
*
99-
* @returns Answer to the given question.
100-
*/
101-
export function supportsBeacon(): boolean {
102-
const global = getGlobalObject();
103-
return 'navigator' in global && 'sendBeacon' in global.navigator;
104-
}
105-
10695
/**
10796
* Tells whether current environment supports ReportingObserver API
10897
* {@link supportsReportingObserver}.

packages/utils/test/supports.test.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)