-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathonerror.user.js
40 lines (38 loc) · 1.16 KB
/
onerror.user.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
/* eslint-env browser */
// ==UserScript==
// @name onerror
// @description onerror
// @include *
// @version 1.0.9
// @created 2020-12-13 14:09:27
// @modified 2024-07-09 21:13:37
// @author dodying
// @namespace https://github.com/dodying/UserJs
// @supportURL https://github.com/dodying/UserJs/issues
// @icon https://github.com/dodying/UserJs/raw/master/Logo.png
// @run-at document-end
// @grant none
// @noframes
// ==/UserScript==
/* global */
/* eslint-disable no-debugger */
(function () {
// 来自 https://developer.mozilla.org/zh-CN/docs/Web/API/GlobalEventHandlers/onerror#注意事项
window.onerror = function (msg, url, lineNo, columnNo, error) {
const string = msg.toLowerCase();
const substring = 'script error';
if (string.indexOf(substring) > -1) {
window.alert('Script Error: See Browser Console for Detail');
} else {
const message = [
`Message: ${msg}`,
`URL: ${url}`,
`Line: ${lineNo}`,
`Column: ${columnNo}`,
`Error object: ${JSON.stringify(error)}`,
].join(' - ');
window.alert(message);
}
return false;
};
}());