-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadblock-errorreporting.js
57 lines (54 loc) · 2.01 KB
/
adblock-errorreporting.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
/*
* This file is part of AdBlock <https://getadblock.com/>,
* Copyright (C) 2013-present Adblock, Inc.
*
* AdBlock is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* AdBlock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AdBlock. If not, see <http://www.gnu.org/licenses/>.
*/
/* For ESLint: List any global identifiers used in this file below */
/* global browser */
import { chromeStorageSetHelper } from './utilities/background/bg-functions';
// Send the file name and line number of any error message. This will help us
// to trace down any frequent errors we can't confirm ourselves.
/* eslint-disable no-restricted-globals */
self.addEventListener('error', (e) => {
if (!e.filename && !e.lineno && !e.colno && !e.error && !e.message) {
return;
}
let str = `Error: ${
(e.filename || 'anywhere').replace(browser.runtime.getURL(''), '')
}:${e.lineno || 'anywhere'
}:${e.colno || 'anycol'}`;
if (e.message) {
str += `: ${e.message}`;
}
const src = e.target.src || e.target.href;
if (src) {
str += `src: ${src}`;
}
if (e.error) {
let stack = `-${e.error.message || ''
}-${e.error.stack || ''}`;
stack = stack.replace(/:/gi, ';').replace(/\n/gi, '');
// only append the stack info if there isn't any URL info in the stack trace
if (stack.indexOf('http') === -1) {
str += stack;
}
// don't send large stack traces
if (str.length > 1024) {
str = str.substr(0, 1023);
}
}
chromeStorageSetHelper('errorkey', `Date added:${new Date()} ${str}`);
// eslint-disable-next-line no-console
console.log(str);
});