Compare commits

...

1 Commits

Author SHA1 Message Date
Cursor Agent
1dcaaa87d8 fix: wrap custom scripts in try-catch to prevent ReferenceErrors
Fixes FORMBRICKS-GH

- Wrap inline script content in IIFE with try-catch block to catch runtime errors like ReferenceError
- Add onerror handler for external scripts to catch loading failures
- Log errors to console for debugging while preventing survey breakage
- This prevents undefined global variable references (like 'frappe') from breaking the survey experience
2026-02-05 05:01:21 +00:00

View File

@@ -56,9 +56,25 @@ export const CustomScriptsInjector = ({
newScript.setAttribute(attr.name, attr.value);
});
// Copy inline script content
// Copy inline script content with error handling
if (script.textContent) {
newScript.textContent = script.textContent;
// Wrap inline scripts in try-catch to prevent user script errors from breaking the survey
newScript.textContent = `
(function() {
try {
${script.textContent}
} catch (error) {
console.warn('[Formbricks] Error in custom script:', error);
}
})();
`.trim();
}
// Add error handler for external scripts
if (script.src) {
newScript.onerror = (error) => {
console.warn("[Formbricks] Error loading external script:", script.src, error);
};
}
document.head.appendChild(newScript);