This commit is contained in:
Your Name
2026-03-13 14:08:52 +08:00
parent 08dd9cd307
commit eb283f008b
667 changed files with 8425 additions and 27053 deletions
+150
View File
@@ -0,0 +1,150 @@
/**
* 应用诊断脚本
* 在浏览器控制台中运行此脚本来诊断问题
*
* 使用方法:
* 1. 打开浏览器开发者工具 (F12)
* 2. 切换到 Console 标签页
* 3. 复制并粘贴此脚本
* 4. 按 Enter 运行
*/
console.log('%c========== 应用诊断开始 ==========', 'color: #4A5DFF; font-size: 16px; font-weight: bold;')
// 1. 检查协议
console.log('\n%c[1] 协议检查', 'color: #4A5DFF; font-weight: bold;')
const isHttps = window.location.protocol === 'https:'
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
console.log(`当前协议: ${window.location.protocol}`)
console.log(`是否 HTTPS: ${isHttps ? '✓ 是' : '✗ 否'}`)
console.log(`是否 localhost: ${isLocalhost ? '✓ 是' : '✗ 否'}`)
if (!isHttps && !isLocalhost) {
console.warn('%c⚠ 警告: WebRTC 需要 HTTPS 或 localhost 环境', 'color: #ff6b6b; font-weight: bold;')
}
// 2. 检查浏览器兼容性
console.log('\n%c[2] 浏览器兼容性检查', 'color: #4A5DFF; font-weight: bold;')
const ua = navigator.userAgent
console.log(`User Agent: ${ua}`)
const browserInfo = {
'Chrome': /Chrome\/(\d+)/.exec(ua),
'Firefox': /Firefox\/(\d+)/.exec(ua),
'Safari': /Version\/(\d+).*Safari/.exec(ua),
'Edge': /Edg\/(\d+)/.exec(ua)
}
for (const [browser, match] of Object.entries(browserInfo)) {
if (match) {
const version = parseInt(match[1])
console.log(`${browser}: ${version}`)
// 检查最低版本要求
const minVersions = { Chrome: 60, Firefox: 55, Safari: 11, Edge: 79 }
if (version >= minVersions[browser]) {
console.log(` ✓ 支持 WebRTC`)
} else {
console.warn(` ✗ 不支持 WebRTC (需要 ${minVersions[browser]}+)`)
}
}
}
// 3. 检查 WebRTC 支持
console.log('\n%c[3] WebRTC 支持检查', 'color: #4A5DFF; font-weight: bold;')
const hasWebRTC = !!(
navigator.mediaDevices &&
navigator.mediaDevices.getUserMedia &&
navigator.mediaDevices.getDisplayMedia
)
console.log(`getUserMedia: ${navigator.mediaDevices?.getUserMedia ? '✓' : '✗'}`)
console.log(`getDisplayMedia: ${navigator.mediaDevices?.getDisplayMedia ? '✓' : '✗'}`)
console.log(`RTCPeerConnection: ${window.RTCPeerConnection ? '✓' : '✗'}`)
console.log(`总体 WebRTC 支持: ${hasWebRTC ? '✓ 是' : '✗ 否'}`)
// 4. 检查权限
console.log('\n%c[4] 设备权限检查', 'color: #4A5DFF; font-weight: bold;')
if (navigator.permissions) {
navigator.permissions.query({ name: 'camera' }).then(result => {
console.log(`摄像头权限: ${result.state}`)
})
navigator.permissions.query({ name: 'microphone' }).then(result => {
console.log(`麦克风权限: ${result.state}`)
})
} else {
console.log('权限 API 不可用')
}
// 5. 检查网络连接
console.log('\n%c[5] 网络连接检查', 'color: #4A5DFF; font-weight: bold;')
console.log(`在线状态: ${navigator.onLine ? '✓ 在线' : '✗ 离线'}`)
console.log(`连接类型: ${navigator.connection?.effectiveType || '未知'}`)
console.log(`下行速度: ${navigator.connection?.downlink || '未知'} Mbps`)
// 6. 检查 TUIKit 状态
console.log('\n%c[6] TUIKit 状态检查', 'color: #4A5DFF; font-weight: bold;')
console.log(`TUIKit 初始化: ${window.__TUIKIT_INITIALIZED__ ? '✓ 是' : '✗ 否'}`)
console.log(`TUICallKit 可用: ${window.TUICallKit ? '✓ 是' : '✗ 否'}`)
console.log(`TUICallKitAPI 可用: ${window.TUICallKitAPI ? '✓ 是' : '✗ 否'}`)
// 7. 检查存储
console.log('\n%c[7] 存储检查', 'color: #4A5DFF; font-weight: bold;')
try {
localStorage.setItem('test', 'test')
localStorage.removeItem('test')
console.log('localStorage: ✓ 可用')
} catch (e) {
console.warn('localStorage: ✗ 不可用')
}
try {
sessionStorage.setItem('test', 'test')
sessionStorage.removeItem('test')
console.log('sessionStorage: ✓ 可用')
} catch (e) {
console.warn('sessionStorage: ✗ 不可用')
}
// 8. 检查 API 连接
console.log('\n%c[8] API 连接检查', 'color: #4A5DFF; font-weight: bold;')
const apiUrl = window.location.origin + '/api/app/config'
fetch(apiUrl)
.then(res => {
console.log(`API 连接: ✓ ${res.status}`)
return res.json()
})
.then(data => {
console.log('API 响应:', data)
})
.catch(err => {
console.error(`API 连接: ✗ ${err.message}`)
})
// 9. 性能指标
console.log('\n%c[9] 性能指标', 'color: #4A5DFF; font-weight: bold;')
const perfData = performance.getEntriesByType('navigation')[0]
if (perfData) {
console.log(`页面加载时间: ${perfData.loadEventEnd - perfData.fetchStart}ms`)
console.log(`DOM 解析时间: ${perfData.domInteractive - perfData.fetchStart}ms`)
console.log(`资源加载时间: ${perfData.loadEventEnd - perfData.domContentLoadedEventEnd}ms`)
}
// 10. 内存使用
console.log('\n%c[10] 内存使用', 'color: #4A5DFF; font-weight: bold;')
if (performance.memory) {
const memory = performance.memory
console.log(`已用内存: ${(memory.usedJSHeapSize / 1048576).toFixed(2)} MB`)
console.log(`总堆大小: ${(memory.totalJSHeapSize / 1048576).toFixed(2)} MB`)
console.log(`堆限制: ${(memory.jsHeapSizeLimit / 1048576).toFixed(2)} MB`)
}
console.log('\n%c========== 诊断完成 ==========', 'color: #4A5DFF; font-size: 16px; font-weight: bold;')
// 导出诊断结果
console.log('\n%c诊断结果摘要:', 'color: #4A5DFF; font-weight: bold;')
const summary = {
protocol: isHttps ? 'HTTPS' : isLocalhost ? 'localhost' : 'HTTP',
webrtc: hasWebRTC ? '支持' : '不支持',
online: navigator.onLine ? '在线' : '离线',
timestamp: new Date().toISOString()
}
console.table(summary)