MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / installAssetFailureDiagnostics

Function installAssetFailureDiagnostics

packages/core/src/runtime/init.ts:1403–1470  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1401 };
1402
1403 const installAssetFailureDiagnostics = () => {
1404 const assetNodes = Array.from(
1405 document.querySelectorAll("img, video, audio, source, link[rel='stylesheet']"),
1406 );
1407 for (const node of assetNodes) {
1408 const onError = () => {
1409 if (!(node instanceof Element)) {
1410 return;
1411 }
1412 const tagName = node.tagName.toLowerCase();
1413 const assetUrl =
1414 node.getAttribute("src") ??
1415 node.getAttribute("href") ??
1416 node.getAttribute("poster") ??
1417 null;
1418 const diagnosticCode =
1419 tagName === "link" ? "runtime_stylesheet_load_failed" : "runtime_asset_load_failed";
1420 postRuntimeDiagnosticOnce(
1421 diagnosticCode,
1422 {
1423 tagName,
1424 assetUrl,
1425 currentSrc:
1426 node instanceof HTMLImageElement || node instanceof HTMLMediaElement
1427 ? node.currentSrc || null
1428 : null,
1429 readyState: node instanceof HTMLMediaElement ? node.readyState : null,
1430 networkState: node instanceof HTMLMediaElement ? node.networkState : null,
1431 },
1432 `${diagnosticCode}:${tagName}:${assetUrl ?? "unknown"}`,
1433 );
1434 };
1435 node.addEventListener("error", onError);
1436 registerRuntimeCleanup(() => {
1437 node.removeEventListener("error", onError);
1438 });
1439 }
1440
1441 const fontSet = document.fonts;
1442 if (!fontSet) {
1443 return;
1444 }
1445 void fontSet.ready
1446 .then(() => {
1447 if (state.tornDown) {
1448 return;
1449 }
1450 const failedFamilies = Array.from(fontSet)
1451 .filter((face) => face.status === "error")
1452 .map((face) => face.family)
1453 .filter((family) => Boolean(family))
1454 .slice(0, 10);
1455 if (failedFamilies.length === 0) {
1456 return;
1457 }
1458 postRuntimeDiagnosticOnce(
1459 "runtime_font_load_issue",
1460 {

Callers 1

Calls 3

registerRuntimeCleanupFunction · 0.85
fromMethod · 0.80

Tested by

no test coverage detected