Add logger fallbacks for iframe forms and views

This commit is contained in:
thePR0M3TH3AN committed 2025-10-15 15:22:42 -04:00
1 parent 15a1986c55
commit b13104162d
11 files changed
+247 -16

No files matched your search

@@ -224,6 +224,22 @@
</div>
</div>
<script>
// Fallback loggers keep embeds functional without bitvidLogger while surfacing warnings/errors via the console.
const fallbackDev = {
log: () => {},
info: () => {},
warn: (...args) => console.warn(...args),
error: (...args) => console.error(...args),
};
const fallbackUser = {
log: () => {},
info: () => {},
warn: (...args) => console.warn(...args),
error: (...args) => console.error(...args),
};
const dev = window.bitvidLogger?.dev || fallbackDev;
const user = window.bitvidLogger?.user || fallbackUser;
document.addEventListener("DOMContentLoaded", () => {
// Logging functions for both on-page and console output.
function log(msg, type = "info") {
@@ -234,7 +250,18 @@
if (type === "warn") div.classList.add("warn");
div.textContent = msg;
document.getElementById("status").appendChild(div);
console.log(`[${type.toUpperCase()}] ${msg}`);
const formatted = `[${type.toUpperCase()}] ${msg}`;
if (type === "error") {
user.error(formatted);
} else if (type === "warn") {
user.warn(formatted);
} else if (type === "success") {
user.log(formatted);
} else if (type === "info") {
dev.info(formatted);
} else {
dev.log(formatted);
}
}
function clear() {
document.getElementById("status").innerHTML = "";
@@ -457,7 +484,7 @@ For further questions, contact us through bitvid’s Nostr support channels.
);
} catch (err) {
log("Error: " + err.message, "error");
console.error(err);
user.error(err);
}
});
});