Skip to content

Commit 3e49112

Browse files
committed
feat: Emit warning when some browser APIs are not in place
1 parent 1df4c1f commit 3e49112

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

packages/browser/src/helpers.ts

+33
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,39 @@ let keypressTimeout: number | undefined;
77
let lastCapturedEvent: Event | undefined;
88
let ignoreOnError: number = 0;
99

10+
/**
11+
* @hidden
12+
*/
13+
export function verifyRequiredBrowserAPIs(): void {
14+
// tslint:disable:strict-type-predicates no-unbound-method
15+
const missingAPIs = [];
16+
17+
if (typeof Promise === 'undefined') {
18+
missingAPIs.push('Promise');
19+
}
20+
21+
if (typeof Object.assign === 'undefined') {
22+
missingAPIs.push('Object.assign');
23+
}
24+
25+
if (typeof Number.isNaN === 'undefined') {
26+
missingAPIs.push('Number.isNaN');
27+
}
28+
29+
if (typeof String.prototype.includes === 'undefined') {
30+
missingAPIs.push('String.includes');
31+
}
32+
33+
if (missingAPIs.length > 0) {
34+
// tslint:disable-next-line:no-console
35+
console.warn(
36+
'Your current browser is missing following APIs:',
37+
missingAPIs.join(', '),
38+
'Sentry SDK may not work as expected. Please provide necessary polyfills. https://docs.sentry.io/platforms/javascript/#browser-table',
39+
);
40+
}
41+
}
42+
1043
/**
1144
* @hidden
1245
*/

packages/browser/src/sdk.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getGlobalObject } from '@sentry/utils';
33

44
import { BrowserOptions } from './backend';
55
import { BrowserClient, ReportDialogOptions } from './client';
6-
import { wrap as internalWrap } from './helpers';
6+
import { verifyRequiredBrowserAPIs, wrap as internalWrap } from './helpers';
77
import { Breadcrumbs, GlobalHandlers, LinkedErrors, TryCatch, UserAgent } from './integrations';
88

99
export const defaultIntegrations = [
@@ -74,6 +74,12 @@ export const defaultIntegrations = [
7474
* @see {@link BrowserOptions} for documentation on configuration options.
7575
*/
7676
export function init(options: BrowserOptions = {}): void {
77+
try {
78+
verifyRequiredBrowserAPIs();
79+
} catch (_oO) {
80+
// juuust in case
81+
}
82+
7783
if (options.defaultIntegrations === undefined) {
7884
options.defaultIntegrations = defaultIntegrations;
7985
}

0 commit comments

Comments
 (0)