MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / instrumentError

Function instrumentError

packages/core/src/instrument/globalError.ts:19–49  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17}
18
19function instrumentError(): void {
20 _oldOnErrorHandler = GLOBAL_OBJ.onerror;
21
22 // Note: The reason we are doing window.onerror instead of window.addEventListener('error')
23 // is that we are using this handler in the Loader Script, to handle buffered errors consistently
24 GLOBAL_OBJ.onerror = function (
25 msg: string | object,
26 url?: string,
27 line?: number,
28 column?: number,
29 error?: Error,
30 ): boolean {
31 const handlerData: HandlerDataError = {
32 column,
33 error,
34 line,
35 msg,
36 url,
37 };
38 triggerHandlers('error', handlerData);
39
40 if (_oldOnErrorHandler) {
41 // eslint-disable-next-line prefer-rest-params
42 return _oldOnErrorHandler.apply(this, arguments);
43 }
44
45 return false;
46 };
47
48 GLOBAL_OBJ.onerror.__SENTRY_INSTRUMENTED__ = true;
49}

Callers

nothing calls this directly

Calls 2

triggerHandlersFunction · 0.90
applyMethod · 0.45

Tested by

no test coverage detected