diff --git a/src/raven.js b/src/raven.js index 8e818c76719f..892461e61255 100644 --- a/src/raven.js +++ b/src/raven.js @@ -258,18 +258,18 @@ Raven.prototype = { if (func.__raven__) { return func; } + + // If this has already been wrapped in the past, return that + if (func.__raven_wrapper__ ){ + return func.__raven_wrapper__ ; + } } catch (e) { - // Just accessing the __raven__ prop in some Selenium environments + // Just accessing custom props in some Selenium environments // can cause a "Permission denied" exception (see raven-js#495). // Bail on wrapping and return the function as-is (defers to window.onerror). return func; } - // If this has already been wrapped in the past, return that - if (func.__raven_wrapper__ ){ - return func.__raven_wrapper__ ; - } - function wrapped() { var args = [], i = arguments.length, deep = !options || options && options.deep !== false; @@ -864,7 +864,11 @@ Raven.prototype = { }, wrappedBuiltIns); fill(proto, 'removeEventListener', function (orig) { return function (evt, fn, capture, secure) { - fn = fn && (fn.__raven_wrapper__ ? fn.__raven_wrapper__ : fn); + try { + fn = fn && (fn.__raven_wrapper__ ? fn.__raven_wrapper__ : fn); + } catch (e) { + // ignore, accessing __raven_wrapper__ will throw in some Selenium environments + } return orig.call(this, evt, fn, capture, secure); }; }, wrappedBuiltIns); diff --git a/test/raven.test.js b/test/raven.test.js index 3881e433e1de..f5c1cc573bfc 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -1735,6 +1735,19 @@ describe('Raven (public API)', function() { assert.equal(fn, wrapped); }); + it('should return input funciton as-is if accessing __raven_wrapper__ prop throws exception', function (){ + // see raven-js#495 + var fn = function () {}; + Object.defineProperty(fn, '__raven_wrapper__', { + get: function () { + throw new Error('Permission denied') + } + }); + assert.throw(function () { fn.__raven_wrapper__; }, 'Permission denied'); + var wrapped = Raven.wrap(fn); + assert.equal(fn, wrapped); + }); + }); describe('.context', function() {