0

I want to add Rollbar error-monitoring tool to a browser JS application written in angularJS. In our browser application, strict mode of javascript is used globally everywhere.

The problem is, that in order for me to take Rollbar into use, I need to insert the code of Rollbar to my application. The code of rollbar for JS can be seen here: Rollbar Browser JS. The code unfortunately does not support for javascript strict mode. When I run the app, rollbar causes this error: Uncaught TypeError: Cannot read property 'logger' of undefined.

How could I solve this? Is there a way to disable strict mode, if it is globally defined already? Disabling strict mode globally is probably not an option. Could I use the Node.js version for monitoring browser application?

2
  • this would happen in non-strict mode as well. Mar 13, 2015 at 12:09
  • It does not. Tried multiple times. If I disable strict mode, it works well even when this.logger is used. If I enable strict mode, then it worked when I replaced all this.logger with window.logger Mar 13, 2015 at 12:24

1 Answer 1

1

I was able to solve this by modifying the Rollbar snippet code. I replaced all occurences of 'this.logger' with 'window.logger', and it started working even strict-mode was on.

1
  • 3
    A simpler (and easier to maintain) fix would have been to wrap the code with (fuction(){ [...Rollbar code hoes here...]}).apply(window). Then it will be easier when you upgrade Rollbar Mar 13, 2015 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.