// Minimal sandbox.js - just listens for sandbox-load and writes the content window.addEventListener("message", (event) => { if (event.data.type === "sandbox-load") { // Validate HTML and JavaScript syntax before document.write() try { // Parse HTML to extract script tags const parser = new DOMParser(); const doc = parser.parseFromString(event.data.code, "text/html"); // Check for HTML parser errors const parserError = doc.querySelector("parsererror"); if (parserError) { throw new Error(`HTML parse error: ${parserError.textContent}`); } // Validate JavaScript in all script tags (except type="module") const scriptTags = Array.from(doc.querySelectorAll("script")); for (let i = 0; i < scriptTags.length; i++) { const scriptContent = scriptTags[i].textContent || ""; const scriptType = scriptTags[i].getAttribute("type"); // Skip validation for module scripts - new Function() can't validate module syntax if (scriptType === "module") { continue; } if (scriptContent.trim()) { try { // Use Function constructor to validate syntax without executing new Function(scriptContent); } catch (jsError) { throw new Error(`JavaScript syntax error in