Skip to content

Commit 86c9df5

Browse files
committed
Guard property access to __raven_wrapper__
Accessing the `__raven_wrapper__` property in Firefox 48 when run under Selenium results in the following error: Uncaught WebDriverError: Permission denied to access property "__raven_wrapper__" (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 10 milliseconds Build info: version: '3.0.0-beta2', revision: '2aa21c1', time: '2016-08-02 15:03:28 -0700' System info: host: '199-7-164-50', ip: '199.7.164.50', os.name: 'windows', os.arch: 'x86', os.version: '6.2', java.version: '1.8.0_91' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{browserstack.localIdentifier=travis-3840.1, raisesAccessibilityExceptions=false, browserstack.tunnelIdentifier=travis-3840.1, browserstack.selenium.jar.version=3.0.0-beta2, appBuildId=20160726073904, platform=XP, specificationLevel=0, acceptSslCerts=false, browserstack.key=GpeJcf7DBqk3pHnB3PkZ, browser=firefox, browserVersion=48.0, platformVersion=6.2, acceptSslCert=false, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, browser_version=48.0, platformName=Windows_NT, 64bit=true, browserstack.debug=false, rotatable=false, browserstack.ie.noFlash=false, browserstack.user=dhcole, version=48.0, proxy={}, command_id=1, firefox_binary=c:\Program Files (x86)\firefox 48.0\firefox.exe, browserstack.video=true, orig_os=win8, takesElementScreenshot=true, device=desktop, proxy_type=privoxy}] Session ID: 8ad81e9d-f345-48a9-b1fe-def338169a10 at WebDriverError (node_modules/selenium-webdriver/lib/error.js:27:10) at Object.checkLegacyResponse (node_modules/selenium-webdriver/lib/error.js:639:15) at parseHttpResponse (node_modules/selenium-webdriver/http/index.js:538:13) at node_modules/selenium-webdriver/http/index.js:472:11 at ManagedPromise.invokeCallback_ (node_modules/selenium-webdriver/lib/promise.js:1379:14) at TaskQueue.execute_ (node_modules/selenium-webdriver/lib/promise.js:2913:14) at TaskQueue.executeNext_ (node_modules/selenium-webdriver/lib/promise.js:2896:21) at node_modules/selenium-webdriver/lib/promise.js:2820:25 at node_modules/selenium-webdriver/lib/promise.js:639:7 From: Task: WebDriver.executeScript() at WebDriver.schedule (node_modules/selenium-webdriver/lib/webdriver.js:377:17) at WebDriver.executeScript (node_modules/selenium-webdriver/lib/webdriver.js:526:16) at WebDriver.driver.load (test/suites/selenium/_init.js:180:14) at test/suites/selenium/_init.js:100:14 at initDriver (test/suites/selenium/_init.js:192:5) at test/suites/selenium/_init.js:147:9 at node_modules/browserstack-local/lib/Local.js:46:11 at ChildProcess.exithandler (child_process.js:204:7) at maybeClose (internal/child_process.js:829:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5) By wrapping the access, we can avoid the error. Relates to getsentry#495
1 parent 9b6283f commit 86c9df5

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/raven.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,16 @@ Raven.prototype = {
258258
if (func.__raven__) {
259259
return func;
260260
}
261+
if (func.__raven_wrapper__ ){
262+
return func.__raven_wrapper__ ;
263+
}
261264
} catch (e) {
262-
// Just accessing the __raven__ prop in some Selenium environments
265+
// Just accessing custom props in some Selenium environments
263266
// can cause a "Permission denied" exception (see raven-js#495).
264267
// Bail on wrapping and return the function as-is (defers to window.onerror).
265268
return func;
266269
}
267270

268-
// If this has already been wrapped in the past, return that
269-
if (func.__raven_wrapper__ ){
270-
return func.__raven_wrapper__ ;
271-
}
272-
273271
function wrapped() {
274272
var args = [], i = arguments.length,
275273
deep = !options || options && options.deep !== false;
@@ -864,7 +862,11 @@ Raven.prototype = {
864862
}, wrappedBuiltIns);
865863
fill(proto, 'removeEventListener', function (orig) {
866864
return function (evt, fn, capture, secure) {
867-
fn = fn && (fn.__raven_wrapper__ ? fn.__raven_wrapper__ : fn);
865+
try {
866+
fn = fn && (fn.__raven_wrapper__ ? fn.__raven_wrapper__ : fn);
867+
} catch (e) {
868+
// ignore, accessing __raven_wrapper__ will throw in some Selnium environments
869+
}
868870
return orig.call(this, evt, fn, capture, secure);
869871
};
870872
}, wrappedBuiltIns);

test/raven.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,19 @@ describe('Raven (public API)', function() {
17351735
assert.equal(fn, wrapped);
17361736
});
17371737

1738+
it('should return input funciton as-is if accessing __raven_wrapper__ prop throws exception', function (){
1739+
// see raven-js#495
1740+
var fn = function () {};
1741+
Object.defineProperty(fn, '__raven_wrapper__', {
1742+
get: function () {
1743+
throw new Error('Permission denied')
1744+
}
1745+
});
1746+
assert.throw(function () { fn.__raven_wrapper__; }, 'Permission denied');
1747+
var wrapped = Raven.wrap(fn);
1748+
assert.equal(fn, wrapped);
1749+
});
1750+
17381751
});
17391752

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

0 commit comments

Comments
 (0)