forked from h4xrOx/gamesense.pub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdk.js
220 lines (220 loc) · 6.28 KB
/
sdk.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
import { getGlobalObject, SyncPromise } from '@sentry/utils';
import { BrowserClient } from './client';
import { wrap as internalWrap } from './helpers';
import { Breadcrumbs, GlobalHandlers, LinkedErrors, TryCatch, UserAgent } from './integrations';
export var defaultIntegrations = [
new CoreIntegrations.InboundFilters(),
new CoreIntegrations.FunctionToString(),
new TryCatch(),
new Breadcrumbs(),
new GlobalHandlers(),
new LinkedErrors(),
new UserAgent(),
];
/**
* The Sentry Browser SDK Client.
*
* To use this SDK, call the {@link init} function as early as possible when
* loading the web page. To set context information or send manual events, use
* the provided methods.
*
* @example
*
* ```
*
* import { init } from '@sentry/browser';
*
* init({
* dsn: '__DSN__',
* // ...
* });
* ```
*
* @example
* ```
*
* import { configureScope } from '@sentry/browser';
* configureScope((scope: Scope) => {
* scope.setExtra({ battery: 0.7 });
* scope.setTag({ user_mode: 'admin' });
* scope.setUser({ id: '4711' });
* });
* ```
*
* @example
* ```
*
* import { addBreadcrumb } from '@sentry/browser';
* addBreadcrumb({
* message: 'My Breadcrumb',
* // ...
* });
* ```
*
* @example
*
* ```
*
* import * as Sentry from '@sentry/browser';
* Sentry.captureMessage('Hello, world!');
* Sentry.captureException(new Error('Good bye'));
* Sentry.captureEvent({
* message: 'Manual',
* stacktrace: [
* // ...
* ],
* });
* ```
*
* @see {@link BrowserOptions} for documentation on configuration options.
*/
export function init(options) {
if (options === void 0) { options = {}; }
if (options.defaultIntegrations === undefined) {
options.defaultIntegrations = defaultIntegrations;
}
if (options.release === undefined) {
var window_1 = getGlobalObject();
// This supports the variable that sentry-webpack-plugin injects
if (window_1.SENTRY_RELEASE && window_1.SENTRY_RELEASE.id) {
options.release = window_1.SENTRY_RELEASE.id;
}
}
if (options.autoSessionTracking === undefined) {
options.autoSessionTracking = false;
}
initAndBind(BrowserClient, options);
if (options.autoSessionTracking) {
startSessionTracking();
}
}
/**
* Present the user with a report dialog.
*
* @param options Everything is optional, we try to fetch all info need from the global scope.
*/
export function showReportDialog(options) {
if (options === void 0) { options = {}; }
if (!options.eventId) {
options.eventId = getCurrentHub().lastEventId();
}
var client = getCurrentHub().getClient();
if (client) {
client.showReportDialog(options);
}
}
/**
* This is the getter for lastEventId.
*
* @returns The last event id of a captured event.
*/
export function lastEventId() {
return getCurrentHub().lastEventId();
}
/**
* This function is here to be API compatible with the loader.
* @hidden
*/
export function forceLoad() {
// Noop
}
/**
* This function is here to be API compatible with the loader.
* @hidden
*/
export function onLoad(callback) {
callback();
}
/**
* A promise that resolves when all current events have been sent.
* If you provide a timeout and the queue takes longer to drain the promise returns false.
*
* @param timeout Maximum time in ms the client should wait.
*/
export function flush(timeout) {
var client = getCurrentHub().getClient();
if (client) {
return client.flush(timeout);
}
return SyncPromise.reject(false);
}
/**
* A promise that resolves when all current events have been sent.
* If you provide a timeout and the queue takes longer to drain the promise returns false.
*
* @param timeout Maximum time in ms the client should wait.
*/
export function close(timeout) {
var client = getCurrentHub().getClient();
if (client) {
return client.close(timeout);
}
return SyncPromise.reject(false);
}
/**
* Wrap code within a try/catch block so the SDK is able to capture errors.
*
* @param fn A function to wrap.
*
* @returns The result of wrapped function call.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function wrap(fn) {
return internalWrap(fn)();
}
/**
* Enable automatic Session Tracking for the initial page load.
*/
function startSessionTracking() {
var window = getGlobalObject();
var hub = getCurrentHub();
/**
* We should be using `Promise.all([windowLoaded, firstContentfulPaint])` here,
* but, as always, it's not available in the IE10-11. Thanks IE.
*/
var loadResolved = document.readyState === 'complete';
var fcpResolved = false;
var possiblyEndSession = function () {
if (fcpResolved && loadResolved) {
hub.endSession();
}
};
var resolveWindowLoaded = function () {
loadResolved = true;
possiblyEndSession();
window.removeEventListener('load', resolveWindowLoaded);
};
hub.startSession();
if (!loadResolved) {
// IE doesn't support `{ once: true }` for event listeners, so we have to manually
// attach and then detach it once completed.
window.addEventListener('load', resolveWindowLoaded);
}
try {
var po = new PerformanceObserver(function (entryList, po) {
entryList.getEntries().forEach(function (entry) {
if (entry.name === 'first-contentful-paint' && entry.startTime < firstHiddenTime_1) {
po.disconnect();
fcpResolved = true;
possiblyEndSession();
}
});
});
// There's no need to even attach this listener if `PerformanceObserver` constructor will fail,
// so we do it below here.
var firstHiddenTime_1 = document.visibilityState === 'hidden' ? 0 : Infinity;
document.addEventListener('visibilitychange', function (event) {
firstHiddenTime_1 = Math.min(firstHiddenTime_1, event.timeStamp);
}, { once: true });
po.observe({
type: 'paint',
buffered: true,
});
}
catch (e) {
fcpResolved = true;
possiblyEndSession();
}
}
//# sourceMappingURL=sdk.js.map