Skip to content

Commit 30f1caa

Browse files
committed
Add Raven.showReportDialog (experimental)
1 parent 6d5a919 commit 30f1caa

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

example/index.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
<head>
44
<title>Scratch Disk</title>
55
</head>
6-
<script src="../vendor/TraceKit/tracekit.js"></script>
7-
<script src="../src/raven.js"></script>
6+
<script src="../dist/raven.js"></script>
87
<!-- <script src="scratch.min.js"></script> -->
98
<script src="scratch.js" crossorigin></script>
109
<script src="file.min.js" crossorigin></script>
@@ -14,7 +13,8 @@
1413
//awesome
1514
Raven.config('http://50dbe04cd1224d439e9c49bf1d0464df@localhost:8000/1', {
1615
whitelistUrls: [
17-
/localhost/
16+
/localhost/,
17+
/127\.0\.0\.1/
1818
],
1919
dataCallback: function(data) {
2020
console.log(data);
@@ -25,7 +25,8 @@
2525
Raven.setUserContext({
2626
2727
id: 5
28-
})
28+
});
29+
2930

3031
</script>
3132
<body>
@@ -36,6 +37,7 @@
3637
<button onclick="derp()">window.onerror</button>
3738
<button onclick="testOptions()">test options</button>
3839
<button onclick="throwString()">throw string</button>
40+
<button onclick="showDialog()">show dialog</button>
3941

4042
</body>
4143
</html>

example/scratch.js

+5
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ function testOptions() {
4040
function throwString() {
4141
throw 'oops';
4242
}
43+
44+
function showDialog() {
45+
broken();
46+
Raven.showReportDialog();
47+
}

src/raven.js

+38-5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Raven.prototype = {
107107
});
108108
}
109109

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

124126
// assemble the endpoint from the uri pieces
125127
this._globalServer = '//' + uri.host +
126-
(uri.port ? ':' + uri.port : '') +
127-
'/' + path + 'api/' + this._globalProject + '/store/';
128+
(uri.port ? ':' + uri.port : '');
128129

129130
if (uri.protocol) {
130131
this._globalServer = uri.protocol + ':' + this._globalServer;
131132
}
133+
this._globalEndpoint = this._globalServer +
134+
'/' + path + 'api/' + this._globalProject + '/store/';
132135

133136
if (this._globalOptions.fetchContext) {
134137
TraceKit.remoteFetching = true;
@@ -498,6 +501,35 @@ Raven.prototype = {
498501
}
499502
},
500503

504+
showReportDialog: function (options) {
505+
if (!window.document) // doesn't work without a document (React native)
506+
return;
507+
508+
options = options || {};
509+
510+
var lastEventId = options.eventId || this.lastEventId();
511+
if (!lastEventId)
512+
return;
513+
514+
var encode = encodeURIComponent;
515+
var qs = '';
516+
qs += '?eventId=' + encode(lastEventId);
517+
qs += '&dsn=' + encode(this._dsn || '');
518+
519+
var user = this._globalContext.user;
520+
if (user) {
521+
if (user.name)
522+
qs += '&name=' + encode(user.name);
523+
if (user.email)
524+
qs += '&email=' + encode(user.email);
525+
}
526+
527+
var script = document.createElement('script');
528+
script.async = true;
529+
script.src = this._globalServer + '/api/embed/error-page/' + qs;
530+
(document.getElementsByTagName('body')[0]).appendChild(script);
531+
},
532+
501533
/**** Private functions ****/
502534
_ignoreNextOnError: function () {
503535
var self = this;
@@ -933,8 +965,9 @@ Raven.prototype = {
933965

934966
if (!this.isSetup()) return;
935967

968+
var url = this._globalEndpoint;
936969
(globalOptions.transport || this._makeRequest).call(this, {
937-
url: this._globalServer,
970+
url: url,
938971
auth: {
939972
sentry_version: '7',
940973
sentry_client: 'raven-js/' + this.VERSION,
@@ -945,13 +978,13 @@ Raven.prototype = {
945978
onSuccess: function success() {
946979
self._triggerEvent('success', {
947980
data: data,
948-
src: self._globalServer
981+
src: url
949982
});
950983
},
951984
onError: function failure() {
952985
self._triggerEvent('failure', {
953986
data: data,
954-
src: self._globalServer
987+
src: url
955988
});
956989
}
957990
});

0 commit comments

Comments
 (0)