Skip to content

Commit 3784ee1

Browse files
authored
fix(browser): Use apply rather than call in try-catch integration (#4695)
Users have reported running into a bug in Chrome wherein calling `addEventListener` or `requestAnimationFrame` too many times on `window` eventually throws an error when our `try-catch` integration is running, specifically because of how we wrap those functions. In the discussion of that bug, [one user](#2074 (comment)) reported that replacing our `call` call with an `apply` call in our wrapping functions solved the problem for him. This makes that change, in the hopes it will fix the problem for everyone. Fixes #3388 Fixes #2074
1 parent 008982f commit 3784ee1

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

packages/browser/src/integrations/trycatch.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ function _wrapRAF(original: any): (callback: () => void) => any {
128128
// eslint-disable-next-line @typescript-eslint/no-explicit-any
129129
return function (this: any, callback: () => void): () => void {
130130
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
131-
return original.call(
132-
this,
131+
return original.apply(this, [
133132
wrap(callback, {
134133
mechanism: {
135134
data: {
@@ -140,7 +139,7 @@ function _wrapRAF(original: any): (callback: () => void) => any {
140139
type: 'instrument',
141140
},
142141
}),
143-
);
142+
]);
144143
};
145144
}
146145

@@ -225,8 +224,7 @@ function _wrapEventTarget(target: string): void {
225224
// can sometimes get 'Permission denied to access property "handle Event'
226225
}
227226

228-
return original.call(
229-
this,
227+
return original.apply(this, [
230228
eventName,
231229
// eslint-disable-next-line @typescript-eslint/no-explicit-any
232230
wrap(fn as any as WrappedFunction, {
@@ -241,7 +239,7 @@ function _wrapEventTarget(target: string): void {
241239
},
242240
}),
243241
options,
244-
);
242+
]);
245243
};
246244
});
247245

0 commit comments

Comments
 (0)