Skip to content

Commit c808ecd

Browse files
authored
Merge pull request #757 from rollbar/wj-onerror-args-fix
Improve detection of chrome anonymous errors vs omitting the error arg
2 parents 335806c + c020a9c commit c808ecd

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/browser/rollbar.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ Rollbar.prototype.handleUncaughtException = function(message, url, lineno, colno
241241
if (!this.options.captureUncaught && !this.options.handleUncaughtExceptions) {
242242
return;
243243
}
244-
if (this.options.inspectAnonymousErrors && this.isChrome && !error) {
244+
245+
// Chrome will always send 5+ arrguments and error will be valid or null, not undefined.
246+
// If error is undefined, we have a different caller.
247+
if (this.options.inspectAnonymousErrors && this.isChrome && (error === null)) {
245248
this.anonymousErrorsPending += 1; // See Rollbar.prototype.handleAnonymousErrors()
246249
return;
247250
}

test/browser.rollbar.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,52 @@ describe('log', function() {
595595
done();
596596
})
597597
});
598+
599+
// Test direct call to onerror, as used in verification of browser js install.
600+
describe('onerror', function() {
601+
before(function (done) {
602+
window.server = sinon.createFakeServer();
603+
done();
604+
});
605+
606+
after(function () {
607+
window.server.restore();
608+
});
609+
610+
function stubResponse(server) {
611+
server.respondWith('POST', 'api/1/item',
612+
[
613+
200,
614+
{ 'Content-Type': 'application/json' },
615+
'{"err": 0, "result":{ "uuid": "d4c7acef55bf4c9ea95e4fe9428a8287"}}'
616+
]
617+
);
618+
}
619+
620+
it('should send message when calling onerror directly', function(done) {
621+
var server = window.server;
622+
stubResponse(server);
623+
server.requests.length = 0;
624+
625+
var options = {
626+
accessToken: 'POST_CLIENT_ITEM_TOKEN',
627+
captureUncaught: true
628+
};
629+
new Rollbar(options);
630+
631+
window.onerror("TestRollbarError: testing window.onerror", window.location.href);
632+
633+
server.respond();
634+
635+
var body = JSON.parse(server.requests[0].requestBody);
636+
637+
expect(body.access_token).to.eql('POST_CLIENT_ITEM_TOKEN');
638+
expect(body.data.body.trace.exception.message).to.eql('testing window.onerror');
639+
640+
done();
641+
})
642+
});
643+
598644
describe('captureEvent', function() {
599645
it('should handle missing/default type and level', function(done) {
600646
var options = {};

0 commit comments

Comments
 (0)