8000 fix: Permission denied to access property name (#1812) · productinfo/sentry-javascript@73b8d65 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73b8d65

Browse files
josketreskamilogorek
authored andcommitted
fix: Permission denied to access property name (getsentry#1812)
Sometimes a "Permission denied" Error is thrown when trying to access the "name" property of a wrapped function.
1 parent 1d64ace commit 73b8d65

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

packages/browser/src/integrations/trycatch.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class TryCatch implements Integration {
2424
const originalCallback = args[0];
2525
args[0] = wrap(originalCallback, {
2626
mechanism: {
27-
data: { function: original.name || '<anonymous>' },
27+
data: { function: getFunctionName(original) },
2828
handled: true,
2929
type: 'instrument',
3030
},
@@ -41,7 +41,7 @@ export class TryCatch implements Integration {
4141
mechanism: {
4242
data: {
4343
function: 'requestAnimationFrame',
44-
handler: (original && original.name) || '<anonymous>',
44+
handler: getFunctionName(original),
4545
},
4646
handled: true,
4747
type: 'instrument',
@@ -74,7 +74,7 @@ export class TryCatch implements Integration {
7474
mechanism: {
7575
data: {
7676
function: 'handleEvent',
77-
handler: (fn && ((fn as any) as SentryWrappedFunction).name) || '<anonymous>',
77+
handler: getFunctionName(fn),
7878
target,
7979
},
8080
handled: true,
@@ -129,7 +129,7 @@ export class TryCatch implements Integration {
129129
mechanism: {
130130
data: {
131131
function: 'addEventListener',
132-
handler: (fn && ((fn as any) as SentryWrappedFunction).name) || '<anonymous>',
132+
handler: getFunctionName(fn),
133133
target,
134134
},
135135
handled: true,
@@ -209,3 +209,13 @@ export class TryCatch implements Integration {
209209
].forEach(this.wrapEventTarget.bind(this));
210210
}
211211
}
212+
213+
function getFunctionName(fn: any): string {
214+
try {
215+
return fn && fn.name || '<anonymous>';
216+
} catch (e) {
217+
// Just accessing custom props in some Selenium environments
218+
// can cause a "Permission denied" exception (see raven-js#495).
219+
return '<anonymous>';
220+
}
221+
}

0 commit comments

Comments
 (0)
0