import { $scramjet } from "../scramjet"; export function errorTemplate(trace: string, fetchedURL: string) { // turn script into a data URI so we don"t have to escape any HTML values const script = ` errorTrace.value = ${JSON.stringify(trace)}; fetchedURL.textContent = ${JSON.stringify(fetchedURL)}; for (const node of document.querySelectorAll("#hostname")) node.textContent = ${JSON.stringify(location.hostname)}; reload.addEventListener("click", () => location.reload()); version.textContent = ${JSON.stringify($scramjet.version.version)}; build.textContent = ${JSON.stringify($scramjet.version.build)}; document.getElementById('copy-button').addEventListener('click', async () => { const text = document.getElementById('errorTrace').value; await navigator.clipboard.writeText(text); const btn = document.getElementById('copy-button'); btn.textContent = 'Copied!'; setTimeout(() => btn.textContent = 'Copy', 2000); }); `; return `
There was an error loading
Try:
If you're the administrator of , try:
Scramjet v (build )
`; } export function renderError(err: unknown, fetchedURL: string) { const headers = { "content-type": "text/html", }; if (crossOriginIsolated) { headers["Cross-Origin-Embedder-Policy"] = "require-corp"; } return new Response(errorTemplate(String(err), fetchedURL), { status: 500, headers: headers, }); }