Skip to content

Commit e8d7a00

Browse files
committed
Fix Raven.js throwing exception when run in Selenium (fixes #495)
1 parent d2c647e commit e8d7a00

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/raven.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,14 @@ Raven.prototype = {
221221
}
222222

223223
// We don't wanna wrap it twice!
224-
if (func.__raven__) {
224+
try {
225+
if (func.__raven__) {
226+
return func;
227+
}
228+
} catch (e) {
229+
// Just accessing the __raven__ prop in some Selenium environments
230+
// can cause a "Permission denied" exception (see raven-js#495).
231+
// Bail on wrapping and return the function as-is (defers to window.onerror).
225232
return func;
226233
}
227234

test/raven.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,18 @@ describe('Raven (public API)', function() {
17291729
}, error);
17301730
});
17311731

1732+
it('should return input funciton as-is if accessing __raven__ prop throws exception', function (){
1733+
// see raven-js#495
1734+
var fn = function () {};
1735+
Object.defineProperty(fn, '__raven__', {
1736+
get: function () {
1737+
throw new Error('Permission denied')
1738+
}
1739+
});
1740+
var wrappedFn = Raven.wrap(fn);
1741+
assert.equal(fn, wrappedFn);
1742+
});
1743+
17321744
});
17331745

17341746
describe('.context', function() {

0 commit comments

Comments
 (0)