',
'
',
'',
''
];
}
rootNode.innerHTML = htmlList.join('');
var reloadBtn = document.getElementById('yq-blank-detection-reload-button');
if (reloadBtn) {
reloadBtn.onclick = function() {
if (window.YuqueDesktopJSBridge) {
window.YuqueDesktopJSBridge.postMessage('app.relaunch');
} else {
window.location.reload();
}
};
}
}
// 获取当前平台
function getClientPlatform() {
// 区分页面运行平台:蚂蚁钉桌面端/蚂蚁钉移动端/桌面端/移动端/default
const platformMap = {
isAntDingTalkDesktopApp: "antDingTalkDesktopApp",
isAntDingTalkMobileApp: "antDingTalkMobileApp",
isDesktopApp: "desktopApp",
isYuqueMobileApp: "yuqueMobileApp"
};
const platformKey = Object.keys(platformMap).find(key => window.appData?.[key]);
return platformKey ? platformMap[platformKey] : 'default';
};
function reportToYuYan() {
if (!window.yuyanMonitor) return;
var traceId = window.appData.traceId || '';
const fromClient = getClientPlatform();
// 「蚂蚁钉桌面端/蚂蚁钉移动端」的白屏报错单独记录在「蚂蚁钉页面加载白屏监控-9008」监控码
if (['antDingTalkDesktopApp', 'antDingTalkMobileApp'].includes(fromClient)) {
window.yuyanMonitor.logError(new Error('AntDing page is blank!'), {
code: 9008,
msg: 'antding_web_page_blank_error',
d1: fromClient,
d2: traceId,
d3: errorMessage,
});
} else {
// 其他白屏报错记录在「页面加载白屏监控-45」监控码
window.yuyanMonitor.logError(new Error('Page is blank!'), {
code: 45,
msg: 'web_page_blank_error',
d1: fromClient,
d2: traceId,
d3: errorMessage
});
}
}
function unregisterServiceWorker() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.getRegistrations()
.then(function(registrations) {
registrations.forEach(function(sw) {
sw.unregister();
});
});
}
}
function report() {
try {
// 清理掉 localStorage
if (isSupportLocalStorage) {
window.localStorage.removeItem(BLANK_DETECTION_RELOAD);
}
// 清理掉 serviceWorker
unregisterServiceWorker();
// 展示反馈
renderFeedBackTips();
// 上报雨燕
reportToYuYan();
} catch (e) {
console.error(e);
}
}
function checkRootNode() {
if (rootNode && rootNode.innerHTML && rootNode.innerHTML !== '
') {
return true;
}
return false;
}
function reload() {
// 清理掉 serviceWorker
unregisterServiceWorker();
// 主动刷新一次
window.localStorage.setItem(BLANK_DETECTION_RELOAD, true);
if (window.localStorage.getItem(BLANK_DETECTION_RELOAD)) {
window.location.reload(true);
} else {
report();
}
}
function checkAndReport() {
// 插入节点前再次检查是否白屏
if (checkRootNode()) {
if (isSupportLocalStorage) {
window.localStorage.removeItem(BLANK_DETECTION_RELOAD);
}
return;
}
// 是否重新加载
if (isSupportLocalStorage && !window.localStorage.getItem(BLANK_DETECTION_RELOAD)) {
reload();
} else {
report();
}
}
function onloadHandler() {
if (checkRootNode()) {
if (isSupportLocalStorage) {
window.localStorage.removeItem(BLANK_DETECTION_RELOAD);
}
return;
} else {
// 10s 后检测白屏
setTimeout(function() {
errorMessage = 'INNERHTML_NOT_EXIST';
checkAndReport();
}, 10 * 1000);
}
}
window.addEventListener('error', function(event) {
if (event) {
// 5s 后检测白屏
setTimeout(function() {
errorMessage = event.message;
checkAndReport();
}, 5 * 1000);
}
}, false);
window.addEventListener('load', onloadHandler, false);
})();