Skip to content

Commit 992907a

Browse files
authored
fix: Remove beacon transport (#1952)
https://www.chromestatus.com/features#milestone%3D73 https://bugs.chromium.org/p/chromium/issues/detail?id=720283 Chrome & Firefox changed / disabled the beacon transport, we have to remove the code an fall back to fetch / xhr.
1 parent 2b16f8d commit 992907a

File tree

10 files changed

+57
-236
lines changed

10 files changed

+57
-236
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 5.0.0-rc.2
4+
5+
- [browser] fix: Remove beacon transport.
6+
37
## 5.0.0-rc.1
48

59
- [node] fix: Check if buffer isReady before sending/creating Promise for request.

packages/browser/examples/app.js

+47-44
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Very happy integration that'll prepend and append very happy stick figure to the message
22
class HappyIntegration {
33
constructor() {
4-
this.name = "HappyIntegration";
4+
this.name = 'HappyIntegration';
55
}
66

77
setupOnce() {
8-
Sentry.addGlobalEventProcessor(async (event) => {
8+
Sentry.addGlobalEventProcessor(async event => {
99
const self = getCurrentHub().getIntegration(HappyIntegration);
1010
// Run the integration ONLY when it was installed on the current Hub
1111
if (self) {
12-
if (event.message === "Happy Message") {
12+
if (event.message === 'Happy Message') {
1313
event.message = `\\o/ ${event.message} \\o/`;
1414
}
1515
}
@@ -20,23 +20,26 @@ class HappyIntegration {
2020

2121
class HappyTransport extends Sentry.Transports.BaseTransport {
2222
captureEvent(event) {
23-
console.log(`This is the place where you'd implement your own sending logic. It'd get url: ${this.url} and an event itself:`, event);
23+
console.log(
24+
`This is the place where you'd implement your own sending logic. It'd get url: ${this.url} and an event itself:`,
25+
event,
26+
);
2427

2528
return {
26-
status: 'success'
27-
}
29+
status: 'success',
30+
};
2831
}
2932
}
3033

3134
Sentry.init({
3235
// Client's DSN.
33-
dsn: "https://[email protected]/297378",
36+
dsn: 'https://[email protected]/297378',
3437
// An array of strings or regexps that'll be used to ignore specific errors based on their type/message
35-
ignoreErrors: [/PickleRick_\d\d/, "RangeError"],
38+
ignoreErrors: [/PickleRick_\d\d/, 'RangeError'],
3639
// // An array of strings or regexps that'll be used to ignore specific errors based on their origin url
37-
blacklistUrls: ["external-lib.js"],
40+
blacklistUrls: ['external-lib.js'],
3841
// // An array of strings or regexps that'll be used to allow specific errors based on their origin url
39-
whitelistUrls: ["http://localhost:5000", "https://browser.sentry-cdn"],
42+
whitelistUrls: ['http://localhost:5000', 'https://browser.sentry-cdn'],
4043
// // Debug mode with valuable initialization/lifecycle informations.
4144
debug: true,
4245
// Whether SDK should be enabled or not.
@@ -46,9 +49,9 @@ Sentry.init({
4649
return [new HappyIntegration(), ...integrations];
4750
},
4851
// A release identifier.
49-
release: "1537345109360",
52+
release: '1537345109360',
5053
// An environment identifier.
51-
environment: "staging",
54+
environment: 'staging',
5255
// Custom event transport that will be used to send things to Sentry
5356
transport: HappyTransport,
5457
// Method called for every captured event
@@ -58,11 +61,11 @@ Sentry.init({
5861
// Our CustomError defined in errors.js has `someMethodAttachedToOurCustomError`
5962
// which can mimick something like a network request to grab more detailed error info or something.
6063
// hint is original exception that was triggered, so we check for our CustomError name
61-
if (hint.originalException.name === "CustomError") {
64+
if (hint.originalException.name === 'CustomError') {
6265
const serverData = await hint.originalException.someMethodAttachedToOurCustomError();
6366
event.extra = {
6467
...event.extra,
65-
serverData
68+
serverData,
6669
};
6770
}
6871
console.log(event);
@@ -71,88 +74,88 @@ Sentry.init({
7174
// Method called for every captured breadcrumb
7275
beforeBreadcrumb(breadcrumb, hint) {
7376
// We ignore our own logger and rest of the buttons just for presentation purposes
74-
if (breadcrumb.message.startsWith("Sentry Logger")) return null;
75-
if (breadcrumb.category !== "ui.click" || hint.event.target.id !== "breadcrumb-hint") return null;
77+
if (breadcrumb.message.startsWith('Sentry Logger')) return null;
78+
if (breadcrumb.category !== 'ui.click' || hint.event.target.id !== 'breadcrumb-hint') return null;
7679

7780
// If we have a `ui.click` type of breadcrumb, eg. clicking on a button we defined in index.html
7881
// We will extract a `data-label` attribute from it and use it as a part of the message
79-
if (breadcrumb.category === "ui.click") {
82+
if (breadcrumb.category === 'ui.click') {
8083
const label = hint.event.target.dataset.label;
8184
if (label) {
8285
breadcrumb.message = `User clicked on a button with label "${label}"`;
8386
}
8487
}
8588
console.log(breadcrumb);
8689
return breadcrumb;
87-
}
90+
},
8891
});
8992

9093
// Testing code, irrelevant vvvvv
9194

92-
document.addEventListener("DOMContentLoaded", () => {
93-
document.querySelector("#blacklist-url").addEventListener("click", () => {
94-
const script = document.createElement("script");
95-
script.crossOrigin = "anonymous";
95+
document.addEventListener('DOMContentLoaded', () => {
96+
document.querySelector('#blacklist-url').addEventListener('click', () => {
97+
const script = document.createElement('script');
98+
script.crossOrigin = 'anonymous';
9699
script.src =
97-
"https://rawgit.com/kamilogorek/cfbe9f92196c6c61053b28b2d42e2f5d/raw/3aef6ff5e2fd2ad4a84205cd71e2496a445ebe1d/external-lib.js";
100+
'https://rawgit.com/kamilogorek/cfbe9f92196c6c61053b28b2d42e2f5d/raw/3aef6ff5e2fd2ad4a84205cd71e2496a445ebe1d/external-lib.js';
98101
document.body.appendChild(script);
99102
});
100103

101-
document.querySelector("#whitelist-url").addEventListener("click", () => {
102-
const script = document.createElement("script");
103-
script.crossOrigin = "anonymous";
104+
document.querySelector('#whitelist-url').addEventListener('click', () => {
105+
const script = document.createElement('script');
106+
script.crossOrigin = 'anonymous';
104107
script.src =
105-
"https://rawgit.com/kamilogorek/cb67dafbd0e12b782bdcc1fbcaed2b87/raw/3aef6ff5e2fd2ad4a84205cd71e2496a445ebe1d/lib.js";
108+
'https://rawgit.com/kamilogorek/cb67dafbd0e12b782bdcc1fbcaed2b87/raw/3aef6ff5e2fd2ad4a84205cd71e2496a445ebe1d/lib.js';
106109
document.body.appendChild(script);
107110
});
108111

109-
document.querySelector("#ignore-message").addEventListener("click", () => {
110-
throw new Error("Exception that will be ignored because of this keyword => PickleRick_42 <=");
112+
document.querySelector('#ignore-message').addEventListener('click', () => {
113+
throw new Error('Exception that will be ignored because of this keyword => PickleRick_42 <=');
111114
});
112115

113-
document.querySelector("#ignore-type").addEventListener("click", () => {
116+
document.querySelector('#ignore-type').addEventListener('click', () => {
114117
throw new RangeError("Exception that will be ignored because of it's type");
115118
});
116119

117-
document.querySelector("#regular-exception").addEventListener("click", () => {
120+
document.querySelector('#regular-exception').addEventListener('click', () => {
118121
throw new Error(`Regular exception no. ${Date.now()}`);
119122
});
120123

121-
document.querySelector("#capture-exception").addEventListener("click", () => {
124+
document.querySelector('#capture-exception').addEventListener('click', () => {
122125
Sentry.captureException(new Error(`captureException call no. ${Date.now()}`));
123126
});
124127

125-
document.querySelector("#capture-message").addEventListener("click", () => {
128+
document.querySelector('#capture-message').addEventListener('click', () => {
126129
Sentry.captureMessage(`captureMessage call no. ${Date.now()}`);
127130
});
128131

129-
document.querySelector("#duplicate-exception").addEventListener("click", () => {
130-
Sentry.captureException(new Error("duplicated exception"));
132+
document.querySelector('#duplicate-exception').addEventListener('click', () => {
133+
Sentry.captureException(new Error('duplicated exception'));
131134
});
132135

133-
document.querySelector("#duplicate-message").addEventListener("click", () => {
134-
Sentry.captureMessage("duplicate captureMessage");
136+
document.querySelector('#duplicate-message').addEventListener('click', () => {
137+
Sentry.captureMessage('duplicate captureMessage');
135138
});
136139

137-
document.querySelector("#integration-example").addEventListener("click", () => {
138-
Sentry.captureMessage("Happy Message");
140+
document.querySelector('#integration-example').addEventListener('click', () => {
141+
Sentry.captureMessage('Happy Message');
139142
});
140143

141-
document.querySelector("#exception-hint").addEventListener("click", () => {
144+
document.querySelector('#exception-hint').addEventListener('click', () => {
142145
class CustomError extends Error {
143146
constructor(...args) {
144147
super(...args);
145-
this.name = "CustomError";
148+
this.name = 'CustomError';
146149
}
147150
someMethodAttachedToOurCustomError() {
148151
return new Promise(resolve => {
149-
resolve("some data, who knows what exactly");
152+
resolve('some data, who knows what exactly');
150153
});
151154
}
152155
}
153156

154-
throw new CustomError("Hey there");
157+
throw new CustomError('Hey there');
155158
});
156159

157-
document.querySelector("#breadcrumb-hint").addEventListener("click", () => {});
160+
document.querySelector('#breadcrumb-hint').addEventListener('click', () => {});
158161
});

packages/browser/examples/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<!doctype html>
1+
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta charset="utf-8">
4+
<meta charset="utf-8" />
55
<title>@sentry/browser SDK examples</title>
66
<script src="bundle.js"></script>
77
<script src="app.js"></script>
@@ -33,4 +33,4 @@
3333
<button id="exception-hint">event hints example</button>
3434
<button data-label="User Defined Label" id="breadcrumb-hint">breadcrumb hints example</button>
3535
</body>
36-
</html>
36+
</html>

packages/browser/src/backend.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { BaseBackend } from '@sentry/core';
22
import { Event, EventHint, Options, Severity, Transport } from '@sentry/types';
33
import { isDOMError, isDOMException, isError, isErrorEvent, isPlainObject } from '@sentry/utils/is';
44
import { addExceptionTypeValue } from '@sentry/utils/misc';
5-
import { supportsBeacon, supportsFetch } from '@sentry/utils/supports';
5+
import { supportsFetch } from '@sentry/utils/supports';
66
import { SyncPromise } from '@sentry/utils/syncpromise';
77

88
import { eventFromPlainObject, eventFromStacktrace, prepareFramesForEvent } from './parsers';
99
import { computeStackTrace } from './tracekit';
10-
import { BeaconTransport, FetchTransport, XHRTransport } from './transports';
10+
import { FetchTransport, XHRTransport } from './transports';
1111

1212
/**
1313
* Configuration options for the Sentry Browser SDK.
@@ -50,9 +50,6 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
5050
if (this._options.transport) {
5151
return new this._options.transport(transportOptions);
5252
}
53-
if (supportsBeacon()) {
54-
return new BeaconTransport(transportOptions);
55-
}
5653
if (supportsFetch()) {
5754
return new FetchTransport(transportOptions);
5855
}

packages/browser/src/integrations/breadcrumbs.ts

+1-60
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 { fill, normalize } from '@sentry/utils/object';
77
import { safeJoin } from '@sentry/utils/string';
8-
import { supportsBeacon, supportsHistory, supportsNativeFetch } from '@sentry/utils/supports';
8+
import { supportsHistory, supportsNativeFetch } from '@sentry/utils/supports';
99

1010
import { BrowserClient } from '../client';
1111

@@ -28,7 +28,6 @@ export interface SentryWrappedXMLHttpRequest extends XMLHttpRequest {
2828

2929
/** JSDoc */
3030
interface BreadcrumbIntegrations {
31-
beacon?: boolean;
3231
console?: boolean;
3332
dom?: boolean;
3433
fetch?: boolean;
@@ -57,7 +56,6 @@ export class Breadcrumbs implements Integration {
5756
*/
5857
public constructor(options?: BreadcrumbIntegrations) {
5958
this._options = {
60-
beacon: true,
6159
console: true,
6260
dom: true,
6361
fetch: true,
@@ -68,60 +66,6 @@ export class Breadcrumbs implements Integration {
6866
};
6967
}
7068

71-
/**
72-
* @hidden
73-
*/
74-
private _instrumentBeacon(): void {
75-
if (!supportsBeacon()) {
76-
return;
77-
}
78-
79-
/**
80-
* @hidden
81-
*/
82-
function beaconReplacementFunction(originalBeaconFunction: () => void): () => void {
83-
return function(this: History, ...args: any[]): void {
84-
const url = args[0];
85-
const data = args[1];
86-
// If the browser successfully queues the request for delivery, the method returns "true" and returns "false" otherwise.
87-
// https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API/Using_the_Beacon_API
88-
const result = originalBeaconFunction.apply(this, args);
89-
90-
const client = getCurrentHub().getClient<BrowserClient>();
91-
const dsn = client && client.getDsn();
92-
if (dsn) {
93-
const filterUrl = new API(dsn).getStoreEndpoint();
94-
// if Sentry key appears in URL, don't capture it as a request
95-
// but rather as our own 'sentry' type breadcrumb
96-
if (filterUrl && url.includes(filterUrl)) {
97-
addSentryBreadcrumb(data);
98-
return result;
99-
}
100-
}
101-
102-
// What is wrong with you TypeScript...
103-
const breadcrumbData = ({
104-
category: 'beacon',
105-
data,
106-
type: 'http',
107-
} as any) as { [key: string]: any };
108-
109-
if (!result) {
110-
breadcrumbData.level = Severity.Error;
111-
}
112-
113-
Breadcrumbs.addBreadcrumb(breadcrumbData, {
114-
input: args,
115-
result,
116-
});
117-
118-
return result;
119-
};
120-
}
121-
122-
fill(global.navigator, 'sendBeacon', beaconReplacementFunction);
123-
}
124-
12569
/** JSDoc */
12670
private _instrumentConsole(): void {
12771
if (!('console' in global)) {
@@ -495,9 +439,6 @@ export class Breadcrumbs implements Integration {
495439
if (this._options.fetch) {
496440
this._instrumentFetch();
497441
}
498-
if (this._options.beacon) {
499-
this._instrumentBeacon();
500-
}
501442
if (this._options.history) {
502443
this._instrumentHistory();
503444
}

packages/browser/src/transports/beacon.ts

-22
This file was deleted.
-1
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';

0 commit comments

Comments
 (0)