Files
TrueGrowth/vendor/aigcpanel/electron/mapi/log/beacon-render.ts
Jammy 52636c91ae
Some checks failed
CI / main (push) Has been cancelled
CI / release-e2e (push) Has been cancelled
Track bundled vendor runtime sources
2026-07-07 10:05:50 +08:00

74 lines
1.7 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 渲染进程异常上报HTTP Beacon
* 仅在 isPackaged非开发模式下上报批量异步发送。
*/
import { AppConfig } from "../../../src/config";
declare const __BUILD_ID__: string;
const BEACON_URL = "https://g.tecmz.com/grow/load.gif";
const BEACON_APP = "aigcpanel";
const isPackaged = process.env["IS_PACKAGED"] === "true";
const sessionId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
const buildId = typeof __BUILD_ID__ !== "undefined" ? __BUILD_ID__ : "unknown";
interface BeaconEvent {
et: "error";
path: string;
did: string;
sid: string;
ts: number;
type: string;
bid: string;
props: {
msg: string;
stack?: string;
src?: string;
line?: number;
col?: number;
};
}
let pending: BeaconEvent[] = [];
let timer: ReturnType<typeof setTimeout> | null = null;
const flush = () => {
if (!pending.length) return;
const events = pending.splice(0);
try {
const encoded = encodeURIComponent(btoa(JSON.stringify(events)));
const url = `${BEACON_URL}?app=${BEACON_APP}&data=${encoded}`;
fetch(url).catch(() => {});
} catch {}
};
const schedule = () => {
if (timer) return;
timer = setTimeout(() => {
timer = null;
flush();
}, 3000);
};
export const reportErrorRender = (
msg: string,
stack?: string,
src?: string,
line?: number,
col?: number,
path = "/renderer",
) => {
if (!isPackaged) return;
pending.push({
et: "error",
path,
did: "renderer",
sid: sessionId,
ts: Date.now(),
type: `app-${AppConfig.version}`,
bid: buildId,
props: { msg, stack, src, line, col },
});
schedule();
};