diff --git a/packages/venia-ui/lib/RootComponents/CMS/cms.js b/packages/venia-ui/lib/RootComponents/CMS/cms.js index 3134776813..6c228f0f40 100644 --- a/packages/venia-ui/lib/RootComponents/CMS/cms.js +++ b/packages/venia-ui/lib/RootComponents/CMS/cms.js @@ -1,4 +1,4 @@ -import React, { Fragment } from 'react'; +import React, { Fragment, useEffect } from 'react'; import { shape, string } from 'prop-types'; import CMSPageShimmer from './cms.shimmer'; @@ -12,11 +12,33 @@ import defaultClasses from './cms.module.css'; const CMSPage = props => { const { identifier } = props; - const talonProps = useCmsPage({ identifier }); const { cmsPage, shouldShowLoadingIndicator } = talonProps; const classes = useStyle(defaultClasses, props.classes); - + const executeInlineScript = () => { + const scripts = document.getElementsByTagName('script'); + for (let i = 0; i < scripts.length; i++) { + const scriptContent = + scripts[i].textContent || scripts[i].innerText; + if (scriptContent) { + try { + // Execute script in a sandboxed environment + const sandbox = {}; + const codeToExecute = `(function() { ${scriptContent} })();`; + const executedScript = new Function( + 'sandbox', + codeToExecute + ); + executedScript(sandbox); + } catch (error) { + console.error('Error executing inline script:', error); + } + } + } + }; + useEffect(() => { + executeInlineScript(); + }); if (shouldShowLoadingIndicator) { return ; }