관리자 빈 화면 진단 로그 추가
This commit is contained in:
parent
85608b41ee
commit
64e06a1185
6 changed files with 224 additions and 5 deletions
|
|
@ -67,6 +67,7 @@
|
|||
(function () {
|
||||
var errors = [];
|
||||
var loadedAt = Date.now();
|
||||
var sentDiagnostics = {};
|
||||
function short(value) {
|
||||
return String(value || "").slice(0, 900);
|
||||
}
|
||||
|
|
@ -109,6 +110,58 @@
|
|||
);
|
||||
}).length;
|
||||
}
|
||||
function diagnosticApiBase() {
|
||||
var host = window.location.hostname;
|
||||
if (host === "vignette.chanpaca.net" || host.endsWith(".pages.dev")) {
|
||||
return "https://api-vignette.chanpaca.net";
|
||||
}
|
||||
if (host === "vnet.18ka.net") {
|
||||
return "https://api-vnet.18ka.net";
|
||||
}
|
||||
return "/api";
|
||||
}
|
||||
function sendDiagnostic(reason, textLength, visible) {
|
||||
var key = reason + ":" + window.location.pathname;
|
||||
if (sentDiagnostics[key]) return;
|
||||
sentDiagnostics[key] = true;
|
||||
var root = document.getElementById("root");
|
||||
var payload = {
|
||||
reason: reason,
|
||||
path: window.location.pathname,
|
||||
href: window.location.href,
|
||||
asset: assetLabel(),
|
||||
elapsed_ms: Date.now() - loadedAt,
|
||||
body_text_length: textLength,
|
||||
root_text_length: root && root.innerText ? root.innerText.trim().length : 0,
|
||||
root_child_count: root ? root.childElementCount : 0,
|
||||
visible_nodes: visible,
|
||||
document_ready_state: document.readyState,
|
||||
viewport: window.innerWidth + "x" + window.innerHeight,
|
||||
user_agent: short(window.navigator && window.navigator.userAgent),
|
||||
errors: errors.slice(-5),
|
||||
};
|
||||
var url = diagnosticApiBase().replace(/\/$/, "") + "/client-diagnostics";
|
||||
var body = JSON.stringify(payload);
|
||||
try {
|
||||
if (window.navigator && navigator.sendBeacon) {
|
||||
var blob = new Blob([body], { type: "application/json" });
|
||||
if (navigator.sendBeacon(url, blob)) return;
|
||||
}
|
||||
} catch (error) {
|
||||
/* fetch fallback below */
|
||||
}
|
||||
try {
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
keepalive: true,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: body,
|
||||
}).catch(function () {});
|
||||
} catch (error) {
|
||||
/* diagnostics must never affect app boot */
|
||||
}
|
||||
}
|
||||
function render(reason) {
|
||||
var path = window.location.pathname;
|
||||
var isAdmin = path === "/admin" || path.indexOf("/admin/") === 0;
|
||||
|
|
@ -122,9 +175,16 @@
|
|||
if (old) old.remove();
|
||||
return;
|
||||
}
|
||||
sendDiagnostic(reason, text.length, visible);
|
||||
|
||||
var panel = document.getElementById("vignette-boot-diagnostic");
|
||||
if (!panel) {
|
||||
if (!document.body) {
|
||||
window.setTimeout(function () {
|
||||
render(reason);
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
panel = document.createElement("section");
|
||||
panel.id = "vignette-boot-diagnostic";
|
||||
panel.setAttribute("role", "alert");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue