This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
/
senderror.js
140 lines (128 loc) · 4.16 KB
/
senderror.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* globals startBackground, analytics, communication, makeUuid, Raven, catcher, auth, log */
"use strict";
this.senderror = (function() {
const exports = {};
const manifest = browser.runtime.getManifest();
// Do not show an error more than every ERROR_TIME_LIMIT milliseconds:
const ERROR_TIME_LIMIT = 3000;
const messages = {
REQUEST_ERROR: {
title: browser.i18n.getMessage("requestErrorTitle"),
info: browser.i18n.getMessage("requestErrorDetails"),
},
CONNECTION_ERROR: {
title: browser.i18n.getMessage("connectionErrorTitle"),
info: browser.i18n.getMessage("connectionErrorDetails"),
},
LOGIN_ERROR: {
title: browser.i18n.getMessage("requestErrorTitle"),
info: browser.i18n.getMessage("loginErrorDetails"),
},
LOGIN_CONNECTION_ERROR: {
title: browser.i18n.getMessage("connectionErrorTitle"),
info: browser.i18n.getMessage("connectionErrorDetails"),
},
UNSHOOTABLE_PAGE: {
title: browser.i18n.getMessage("unshootablePageErrorTitle"),
info: browser.i18n.getMessage("unshootablePageErrorDetails"),
},
SHOT_PAGE: {
title: browser.i18n.getMessage("selfScreenshotErrorTitle"),
},
MY_SHOTS: {
title: browser.i18n.getMessage("selfScreenshotErrorTitle"),
},
EMPTY_SELECTION: {
title: browser.i18n.getMessage("emptySelectionErrorTitle"),
},
PRIVATE_WINDOW: {
title: browser.i18n.getMessage("privateWindowErrorTitle"),
info: browser.i18n.getMessage("privateWindowErrorDetails"),
},
generic: {
title: browser.i18n.getMessage("genericErrorTitle"),
info: browser.i18n.getMessage("genericErrorDetails"),
showMessage: true,
},
};
communication.register("reportError", (sender, error) => {
catcher.unhandled(error);
});
let lastErrorTime;
exports.showError = function(error) {
if (lastErrorTime && (Date.now() - lastErrorTime) < ERROR_TIME_LIMIT) {
return;
}
lastErrorTime = Date.now();
const id = makeUuid();
let popupMessage = error.popupMessage || "generic";
if (!messages[popupMessage]) {
popupMessage = "generic";
}
const title = messages[popupMessage].title;
let message = messages[popupMessage].info || "";
const showMessage = messages[popupMessage].showMessage;
if (error.message && showMessage) {
if (message) {
message += "\n" + error.message;
} else {
message = error.message;
}
}
if (Date.now() - startBackground.startTime > 5 * 1000) {
browser.notifications.create(id, {
type: "basic",
// FIXME: need iconUrl for an image, see #2239
title,
message,
});
}
};
exports.reportError = function(e) {
if (!analytics.isTelemetryEnabled()) {
log.error("Telemetry disabled. Not sending critical error:", e);
return;
}
const dsn = auth.getSentryPublicDSN();
if (!dsn) {
log.warn("Screenshots error:", e);
return;
}
if (!Raven.isSetup()) {
Raven.config(dsn, {allowSecretKey: true}).install();
}
const exception = new Error(e.message);
exception.stack = e.multilineStack || e.stack || undefined;
// To improve Sentry reporting & grouping, replace the
// moz-extension://$uuid base URL with a generic resource:// URL.
if (exception.stack) {
exception.stack = exception.stack.replace(
/moz-extension:\/\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/g,
"resource://screenshots-addon"
);
}
const rest = {};
for (const attr in e) {
if (!["name", "message", "stack", "multilineStack", "popupMessage", "version", "sentryPublicDSN", "help", "fromMakeError"].includes(attr)) {
rest[attr] = e[attr];
}
}
rest.stack = exception.stack;
Raven.captureException(exception, {
logger: "addon",
tags: {category: e.popupMessage},
release: manifest.version,
message: exception.message,
extra: rest,
});
};
catcher.registerHandler((errorObj) => {
if (!errorObj.noPopup) {
exports.showError(errorObj);
}
if (!errorObj.noReport) {
exports.reportError(errorObj);
}
});
return exports;
})();