// -- HTML Injection ---------------------------------------------------------- // Injects the Originmain fiber hook `; } return cachedFiberTag; } /** * Build the bridge config ` ); } /** * Strip inline Content-Security-Policy meta tags from HTML. */ function stripMetaCsp(html: string): string { return html.replace( /]+http-equiv\s*=\s*["']?\s*content-security-policy\s*["']?[^>]*\/?>/gi, '', ); } /** * Inject the fiber hook + bridge config scripts into an HTML string. */ export function injectFiberHook(html: string, indexUrl?: string | null): string { const injection = getBridgeConfigTag(indexUrl) + getFiberTag(); const cleaned = stripMetaCsp(html); // Try after const headMatch = cleaned.match(/]*>/i); if (headMatch?.index !== undefined) { const insertAt = headMatch.index + headMatch[0].length; return cleaned.slice(0, insertAt) + injection + cleaned.slice(insertAt); } // Try after const htmlMatch = cleaned.match(/]*>/i); if (htmlMatch?.index !== undefined) { const insertAt = htmlMatch.index + htmlMatch[0].length; return cleaned.slice(0, insertAt) + injection + cleaned.slice(insertAt); } // Final fallback: prepend return injection + cleaned; }