🚑 (bot) Fix try catch injection when opening s…
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/js",
|
"name": "@typebot.io/js",
|
||||||
"version": "0.0.72",
|
"version": "0.0.73",
|
||||||
"description": "Javascript library to display typebots on your website",
|
"description": "Javascript library to display typebots on your website",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/react",
|
"name": "@typebot.io/react",
|
||||||
"version": "0.0.72",
|
"version": "0.0.73",
|
||||||
"description": "React library to display typebots on your website",
|
"description": "React library to display typebots on your website",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
@ -287,18 +287,7 @@ export const parseNumberWithCommas = (num: number) =>
|
|||||||
num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||||
|
|
||||||
export const injectCustomHeadCode = (customHeadCode: string) => {
|
export const injectCustomHeadCode = (customHeadCode: string) => {
|
||||||
customHeadCode = customHeadCode.replace(
|
customHeadCode = injectTryCatch(customHeadCode)
|
||||||
/<script>/g,
|
|
||||||
`<script>
|
|
||||||
try {`
|
|
||||||
)
|
|
||||||
customHeadCode = customHeadCode.replace(
|
|
||||||
/<\/script>/g,
|
|
||||||
`} catch(e) {
|
|
||||||
console.warn("Error while executing custom head code", e)
|
|
||||||
}
|
|
||||||
</script>`
|
|
||||||
)
|
|
||||||
const headCodes = customHeadCode.split('</noscript>')
|
const headCodes = customHeadCode.split('</noscript>')
|
||||||
headCodes.forEach((headCode) => {
|
headCodes.forEach((headCode) => {
|
||||||
const [codeToInject, noScriptContentToInject] = headCode.split('<noscript>')
|
const [codeToInject, noScriptContentToInject] = headCode.split('<noscript>')
|
||||||
@ -318,6 +307,29 @@ try {`
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const injectTryCatch = (headCode: string) => {
|
||||||
|
const scriptTagRegex = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi
|
||||||
|
const scriptTags = headCode.match(scriptTagRegex)
|
||||||
|
if (scriptTags) {
|
||||||
|
scriptTags.forEach(function (tag) {
|
||||||
|
const wrappedTag = tag.replace(
|
||||||
|
/(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi,
|
||||||
|
function (_, openingTag, content, closingTag) {
|
||||||
|
return `${openingTag}
|
||||||
|
try {
|
||||||
|
${content}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e);
|
||||||
|
}
|
||||||
|
${closingTag}`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
headCode = headCode.replace(tag, wrappedTag)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return headCode
|
||||||
|
}
|
||||||
|
|
||||||
export const getAtPath = <T>(obj: T, path: string): unknown => {
|
export const getAtPath = <T>(obj: T, path: string): unknown => {
|
||||||
if (isNotDefined(obj)) return undefined
|
if (isNotDefined(obj)) return undefined
|
||||||
const pathParts = path.split('.')
|
const pathParts = path.split('.')
|
||||||
|
Reference in New Issue
Block a user