qb-pc-sdk 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +85 -0
- package/package.json +1 -1
- package/src/ad-sdk-wrapper.js +85 -0
package/index.js
CHANGED
|
@@ -6,6 +6,91 @@
|
|
|
6
6
|
|
|
7
7
|
const isBrowser = typeof window !== 'undefined';
|
|
8
8
|
|
|
9
|
+
// 拦截并过滤微信游戏SDK相关的错误日志(在加载底层SDK之前,仅拦截一次)
|
|
10
|
+
if (isBrowser && typeof window !== 'undefined' && window.console && !window.console.error._qbsdkFiltered) {
|
|
11
|
+
const originalError = window.console.error;
|
|
12
|
+
const originalWarn = window.console.warn;
|
|
13
|
+
|
|
14
|
+
// 过滤函数,检查是否应该过滤
|
|
15
|
+
const shouldFilter = function(...args) {
|
|
16
|
+
const errorText = args.join(' ').toLowerCase();
|
|
17
|
+
return (
|
|
18
|
+
errorText.includes('微信') ||
|
|
19
|
+
errorText.includes('wechat') ||
|
|
20
|
+
errorText.includes('weixin') ||
|
|
21
|
+
errorText.includes('wxgame') ||
|
|
22
|
+
errorText.includes('微信游戏') ||
|
|
23
|
+
errorText.includes('微信小游戏') ||
|
|
24
|
+
errorText.includes('wxgamesdkframe') ||
|
|
25
|
+
errorText.includes('localhost.weixin.qq.com') ||
|
|
26
|
+
errorText.includes('wx_game_base') ||
|
|
27
|
+
errorText.includes('getgamesession') ||
|
|
28
|
+
errorText.includes('xmlhttprequest') ||
|
|
29
|
+
errorText.includes('err_failed') ||
|
|
30
|
+
errorText.includes('err_connection_refused') ||
|
|
31
|
+
errorText.includes('cors policy') ||
|
|
32
|
+
errorText.includes('secure context') ||
|
|
33
|
+
errorText.includes('loopback') ||
|
|
34
|
+
errorText.includes('more-private address space')
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const filteredError = function(...args) {
|
|
39
|
+
// 如果不是微信相关的错误,正常输出
|
|
40
|
+
if (!shouldFilter(...args)) {
|
|
41
|
+
originalError.apply(window.console, args);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const filteredWarn = function(...args) {
|
|
46
|
+
// 如果不是微信相关的警告,正常输出
|
|
47
|
+
if (!shouldFilter(...args)) {
|
|
48
|
+
originalWarn.apply(window.console, args);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// 标记已过滤,避免重复拦截
|
|
53
|
+
filteredError._qbsdkFiltered = true;
|
|
54
|
+
filteredWarn._qbsdkFiltered = true;
|
|
55
|
+
window.console.error = filteredError;
|
|
56
|
+
window.console.warn = filteredWarn;
|
|
57
|
+
|
|
58
|
+
// 拦截全局错误事件,过滤微信游戏SDK相关的错误
|
|
59
|
+
if (!window._qbsdkErrorHandlerAdded) {
|
|
60
|
+
const originalOnError = window.onerror;
|
|
61
|
+
window.onerror = function(message, source, lineno, colno, error) {
|
|
62
|
+
const errorText = (message || '').toLowerCase() + (source || '').toLowerCase();
|
|
63
|
+
if (shouldFilter(errorText)) {
|
|
64
|
+
// 静默处理,不输出
|
|
65
|
+
return true; // 阻止默认错误处理
|
|
66
|
+
}
|
|
67
|
+
// 其他错误正常处理
|
|
68
|
+
if (originalOnError) {
|
|
69
|
+
return originalOnError.call(this, message, source, lineno, colno, error);
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// 拦截未捕获的 Promise rejection
|
|
75
|
+
const originalUnhandledRejection = window.onunhandledrejection;
|
|
76
|
+
window.addEventListener('unhandledrejection', function(event) {
|
|
77
|
+
const reason = event.reason || {};
|
|
78
|
+
const errorText = (reason.message || reason || '').toString().toLowerCase();
|
|
79
|
+
if (shouldFilter(errorText)) {
|
|
80
|
+
// 阻止默认行为,静默处理
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// 其他错误正常处理
|
|
85
|
+
if (originalUnhandledRejection) {
|
|
86
|
+
originalUnhandledRejection.call(window, event);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
window._qbsdkErrorHandlerAdded = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
9
94
|
// 浏览器中预加载底层 SDK(仅 side-effect,挂载 window.GDTAdSDK)
|
|
10
95
|
if (isBrowser) {
|
|
11
96
|
try {
|
package/package.json
CHANGED
package/src/ad-sdk-wrapper.js
CHANGED
|
@@ -8,6 +8,91 @@
|
|
|
8
8
|
// 兼容浏览器和 Node.js 环境
|
|
9
9
|
const window = typeof global !== 'undefined' && global.window ? global.window : (typeof window !== 'undefined' ? window : global);
|
|
10
10
|
|
|
11
|
+
// 拦截并过滤微信游戏SDK相关的错误日志(仅拦截一次)
|
|
12
|
+
if (typeof window !== 'undefined' && window.console && !window.console.error._qbsdkFiltered) {
|
|
13
|
+
const originalError = window.console.error;
|
|
14
|
+
const originalWarn = window.console.warn;
|
|
15
|
+
|
|
16
|
+
// 过滤函数,检查是否应该过滤
|
|
17
|
+
const shouldFilter = function(...args) {
|
|
18
|
+
const errorText = args.join(' ').toLowerCase();
|
|
19
|
+
return (
|
|
20
|
+
errorText.includes('微信') ||
|
|
21
|
+
errorText.includes('wechat') ||
|
|
22
|
+
errorText.includes('weixin') ||
|
|
23
|
+
errorText.includes('wxgame') ||
|
|
24
|
+
errorText.includes('微信游戏') ||
|
|
25
|
+
errorText.includes('微信小游戏') ||
|
|
26
|
+
errorText.includes('wxgamesdkframe') ||
|
|
27
|
+
errorText.includes('localhost.weixin.qq.com') ||
|
|
28
|
+
errorText.includes('wx_game_base') ||
|
|
29
|
+
errorText.includes('getgamesession') ||
|
|
30
|
+
errorText.includes('xmlhttprequest') ||
|
|
31
|
+
errorText.includes('err_failed') ||
|
|
32
|
+
errorText.includes('err_connection_refused') ||
|
|
33
|
+
errorText.includes('cors policy') ||
|
|
34
|
+
errorText.includes('secure context') ||
|
|
35
|
+
errorText.includes('loopback') ||
|
|
36
|
+
errorText.includes('more-private address space')
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const filteredError = function(...args) {
|
|
41
|
+
// 如果不是微信相关的错误,正常输出
|
|
42
|
+
if (!shouldFilter(...args)) {
|
|
43
|
+
originalError.apply(window.console, args);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const filteredWarn = function(...args) {
|
|
48
|
+
// 如果不是微信相关的警告,正常输出
|
|
49
|
+
if (!shouldFilter(...args)) {
|
|
50
|
+
originalWarn.apply(window.console, args);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// 标记已过滤,避免重复拦截
|
|
55
|
+
filteredError._qbsdkFiltered = true;
|
|
56
|
+
filteredWarn._qbsdkFiltered = true;
|
|
57
|
+
window.console.error = filteredError;
|
|
58
|
+
window.console.warn = filteredWarn;
|
|
59
|
+
|
|
60
|
+
// 拦截全局错误事件,过滤微信游戏SDK相关的错误
|
|
61
|
+
if (!window._qbsdkErrorHandlerAdded) {
|
|
62
|
+
const originalOnError = window.onerror;
|
|
63
|
+
window.onerror = function(message, source, lineno, colno, error) {
|
|
64
|
+
const errorText = (message || '').toLowerCase() + (source || '').toLowerCase();
|
|
65
|
+
if (shouldFilter(errorText)) {
|
|
66
|
+
// 静默处理,不输出
|
|
67
|
+
return true; // 阻止默认错误处理
|
|
68
|
+
}
|
|
69
|
+
// 其他错误正常处理
|
|
70
|
+
if (originalOnError) {
|
|
71
|
+
return originalOnError.call(this, message, source, lineno, colno, error);
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// 拦截未捕获的 Promise rejection
|
|
77
|
+
const originalUnhandledRejection = window.onunhandledrejection;
|
|
78
|
+
window.addEventListener('unhandledrejection', function(event) {
|
|
79
|
+
const reason = event.reason || {};
|
|
80
|
+
const errorText = (reason.message || reason || '').toString().toLowerCase();
|
|
81
|
+
if (shouldFilter(errorText)) {
|
|
82
|
+
// 阻止默认行为,静默处理
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
// 其他错误正常处理
|
|
87
|
+
if (originalUnhandledRejection) {
|
|
88
|
+
originalUnhandledRejection.call(window, event);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
window._qbsdkErrorHandlerAdded = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
11
96
|
// 内部常量配置
|
|
12
97
|
const API_CONFIG = {
|
|
13
98
|
INIT: 'http://test.qubiankeji.com:8084/pc/init',
|