Skip to content

Add Raven.showReportDialog (experimental) #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<head>
<title>Scratch Disk</title>
</head>
<script src="../vendor/TraceKit/tracekit.js"></script>
<script src="../src/raven.js"></script>
<script src="../dist/raven.js"></script>
<!-- <script src="scratch.min.js"></script> -->
<script src="scratch.js" crossorigin></script>
<script src="file.min.js" crossorigin></script>
Expand All @@ -14,7 +13,8 @@
//awesome
Raven.config('http://50dbe04cd1224d439e9c49bf1d0464df@localhost:8000/1', {
whitelistUrls: [
/localhost/
/localhost/,
/127\.0\.0\.1/
],
dataCallback: function(data) {
console.log(data);
Expand All @@ -25,7 +25,8 @@
Raven.setUserContext({
email: '[email protected]',
id: 5
})
});


</script>
<body>
Expand All @@ -36,6 +37,7 @@
<button onclick="derp()">window.onerror</button>
<button onclick="testOptions()">test options</button>
<button onclick="throwString()">throw string</button>
<button onclick="showDialog()">show dialog</button>

</body>
</html>
5 changes: 5 additions & 0 deletions example/scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ function testOptions() {
function throwString() {
throw 'oops';
}

function showDialog() {
broken();
Raven.showReportDialog();
}
43 changes: 38 additions & 5 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ Raven.prototype = {
});
}

this._dsn = dsn;

// "Script error." is hard coded into browsers for errors that it can't read.
// this is the result of a script being pulled in from an external domain and CORS.
this._globalOptions.ignoreErrors.push(/^Script error\.?$/);
Expand All @@ -123,12 +125,13 @@ Raven.prototype = {

// assemble the endpoint from the uri pieces
this._globalServer = '//' + uri.host +
(uri.port ? ':' + uri.port : '') +
'/' + path + 'api/' + this._globalProject + '/store/';
(uri.port ? ':' + uri.port : '');

if (uri.protocol) {
this._globalServer = uri.protocol + ':' + this._globalServer;
}
this._globalEndpoint = this._globalServer +
'/' + path + 'api/' + this._globalProject + '/store/';

if (this._globalOptions.fetchContext) {
TraceKit.remoteFetching = true;
Expand Down Expand Up @@ -498,6 +501,35 @@ Raven.prototype = {
}
},

showReportDialog: function (options) {
if (!window.document) // doesn't work without a document (React native)
return;

options = options || {};

var lastEventId = options.eventId || this.lastEventId();
if (!lastEventId)
return;

var encode = encodeURIComponent;
var qs = '';
qs += '?eventId=' + encode(lastEventId);
qs += '&dsn=' + encode(this._dsn || '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dsn needs to be configurable via options


var user = this._globalContext.user;
if (user) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be configurable via options

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would the DSN differ from what's specified via Raven.config?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the DSN contains the project, and the eventID is bound to the project

often server side project != client side project

if (user.name)
qs += '&name=' + encode(user.name);
if (user.email)
qs += '&email=' + encode(user.email);
}

var script = document.createElement('script');
script.async = true;
script.src = this._globalServer + '/api/embed/error-page/' + qs;
document.getElementsByTagName('body')[0].appendChild(script);
},

/**** Private functions ****/
_ignoreNextOnError: function () {
var self = this;
Expand Down Expand Up @@ -933,8 +965,9 @@ Raven.prototype = {

if (!this.isSetup()) return;

var url = this._globalEndpoint;
(globalOptions.transport || this._makeRequest).call(this, {
url: this._globalServer,
url: url,
auth: {
sentry_version: '7',
sentry_client: 'raven-js/' + this.VERSION,
Expand All @@ -945,13 +978,13 @@ Raven.prototype = {
onSuccess: function success() {
self._triggerEvent('success', {
data: data,
src: self._globalServer
src: url
});
},
onError: function failure() {
self._triggerEvent('failure', {
data: data,
src: self._globalServer
src: url
});
}
});
Expand Down
16 changes: 8 additions & 8 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ describe('globals', function() {
maxMessageLength: 100,
release: 'abc123',
};
Raven._globalServer = 'http://localhost/store/';
Raven._globalEndpoint = 'http://localhost/store/';
Raven._globalOptions = globalOptions;

Raven._send({message: 'bar'});
Expand Down Expand Up @@ -1226,7 +1226,7 @@ describe('globals', function() {

it('should populate crossOrigin based on options', function() {
Raven._makeImageRequest({
url: Raven._globalServer,
url: Raven._globalEndpoint,
auth: {lol: '1'},
data: {foo: 'bar'},
options: {
Expand All @@ -1239,7 +1239,7 @@ describe('globals', function() {

it('should populate crossOrigin if empty string', function() {
Raven._makeImageRequest({
url: Raven._globalServer,
url: Raven._globalEndpoint,
auth: {lol: '1'},
data: {foo: 'bar'},
options: {
Expand All @@ -1252,7 +1252,7 @@ describe('globals', function() {

it('should not populate crossOrigin if falsey', function() {
Raven._makeImageRequest({
url: Raven._globalServer,
url: Raven._globalEndpoint,
auth: {lol: '1'},
data: {foo: 'bar'},
options: {
Expand Down Expand Up @@ -1487,7 +1487,7 @@ describe('Raven (public API)', function() {
Raven.afterLoad();

assert.equal(Raven._globalKey, 'random');
assert.equal(Raven._globalServer, 'http://some.other.server:80/api/2/store/');
assert.equal(Raven._globalEndpoint, 'http://some.other.server:80/api/2/store/');

assert.equal(Raven._globalOptions.some, 'config');
assert.equal(Raven._globalProject, '2');
Expand All @@ -1504,7 +1504,7 @@ describe('Raven (public API)', function() {
assert.equal(Raven, Raven.config(SENTRY_DSN, {foo: 'bar'}), 'it should return Raven');

assert.equal(Raven._globalKey, 'abc');
assert.equal(Raven._globalServer, 'http://example.com:80/api/2/store/');
assert.equal(Raven._globalEndpoint, 'http://example.com:80/api/2/store/');
assert.equal(Raven._globalOptions.foo, 'bar');
assert.equal(Raven._globalProject, '2');
assert.isTrue(Raven.isSetup());
Expand All @@ -1514,15 +1514,15 @@ describe('Raven (public API)', function() {
Raven.config('//[email protected]/2');

assert.equal(Raven._globalKey, 'abc');
assert.equal(Raven._globalServer, '//example.com/api/2/store/');
assert.equal(Raven._globalEndpoint, '//example.com/api/2/store/');
assert.equal(Raven._globalProject, '2');
assert.isTrue(Raven.isSetup());
});

it('should work should work at a non root path', function() {
Raven.config('//[email protected]/sentry/2');
assert.equal(Raven._globalKey, 'abc');
assert.equal(Raven._globalServer, '//example.com/sentry/api/2/store/');
assert.equal(Raven._globalEndpoint, '//example.com/sentry/api/2/store/');
assert.equal(Raven._globalProject, '2');
assert.isTrue(Raven.isSetup());
});
Expand Down