-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathclient.js
More file actions
55 lines (48 loc) · 1.8 KB
/
client.js
File metadata and controls
55 lines (48 loc) · 1.8 KB
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
/**
* 手机端调试利器
* 手机端的log会直接输出到PC端浏览器的控制面板
*
* author: fwon
* 2016.5.20
*/
!(function(){
'use strict';
function detect(arr, val) {
return arr.some(function(v) {
return val.match(v);
})
}
var devices = ["android", "webos", "iphone", "ipad", "ipod", "blackberry", "windows phone", "mobile"];
var agent = navigator.userAgent.toLowerCase();
var isMobile = detect(devices, agent);
var slice = [].slice;
var socket = io && io("G_HOST_PORT");
var consoleTypes = ['log', 'info', 'warn', 'error', 'debug'];
var consoleEvents = consoleTypes.map(function(item) {return item.toUpperCase()});
if (socket && window.console) {
consoleTypes.forEach(function(item, index) {
var oldLog = window.console[item]
if (oldLog) {
socket.on(consoleEvents[index], function(msg) {
oldLog.apply(window.console, msg);
});
if (isMobile) {
window.console[item] = function() {
var args = slice.call(arguments);
socket.emit(consoleEvents[index], args);
}
}
}
});
if (window.console.error && isMobile) {
window.onerror = function(errorMsg, url, lineNumber, column, errorObj) {
if (errorMsg.indexOf('Script error.') > -1) {
console.error('外部脚本报错!')
} else {
console.error('Error: ' + errorMsg + '\nScript: ' + url + '\nLine: ' + lineNumber + '\nColumn: ' + column + '\nStackTrace: ' + errorObj);
}
// return true; //stop default error
}
}
}
})();