Compare commits

...

1 Commits

Author SHA1 Message Date
Cursor Agent
358f821da3 fix: wrap custom script content in try-catch to prevent ReferenceError
Fixes FORMBRICKS-V3

User-provided custom scripts may reference undefined variables (like
zp_token), causing ReferenceErrors that break the survey. This fix
wraps inline script content in a try-catch block to catch and log
runtime errors without breaking the survey experience.

The error will be logged to the console with a clear warning message,
allowing self-hosted admins to debug their custom scripts while
ensuring the survey remains functional for end users.
2026-03-19 17:05:35 +00:00

View File

@@ -56,9 +56,16 @@ export const CustomScriptsInjector = ({
newScript.setAttribute(attr.name, attr.value);
});
// Copy inline script content
// Copy inline script content, wrapped in try-catch to prevent runtime errors
if (script.textContent) {
newScript.textContent = script.textContent;
// Wrap inline scripts in try-catch to prevent user script errors from breaking the survey
newScript.textContent = `
try {
${script.textContent}
} catch (error) {
console.warn("[Formbricks] Error in custom script:", error);
}
`.trim();
}
document.head.appendChild(newScript);