Skip to content

Commit 9dbc6bd

Browse files
committed
Fix Raven.js throwing exception when run in Selenium (fixes #495)
1 parent 3ceadc1 commit 9dbc6bd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-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

+13
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,19 @@ 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+
assert.throw(function () { fn.__raven__; }, 'Permission denied');
1741+
var wrapped = Raven.wrap(fn);
1742+
assert.equal(fn, wrapped);
1743+
});
1744+
17321745
});
17331746

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

0 commit comments

Comments
 (0)