Skip to content

Commit

Permalink
feat(engine): ⚡️ Redirect on current window when embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jun 1, 2022
1 parent 05de48b commit 4f208a2
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/bot-engine/src/services/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,27 @@ const executeRedirect = (
{ typebot: { variables } }: LogicContext
): EdgeId | undefined => {
if (!step.options?.url) return step.outgoingEdgeId
const tempLink = document.createElement('a')
tempLink.href = sanitizeUrl(parseVariables(variables)(step.options?.url))
tempLink.setAttribute('target', step.options.isNewTab ? '_blank' : '_self')
tempLink.click()
const formattedUrl = sanitizeUrl(parseVariables(variables)(step.options.url))
const isEmbedded = window.parent && window.location !== window.top?.location
if (isEmbedded) {
if (step.options.isNewTab)
return ((window.top as Window).location.href = formattedUrl)

try {
window.open(formattedUrl)
} catch (err) {
//Can't access to parent window
window.top?.postMessage(
{
from: 'typebot',
redirectUrl: formattedUrl,
},
'*'
)
}
} else {
window.open(formattedUrl, step.options.isNewTab ? '_blank' : '_self')
}
return step.outgoingEdgeId
}

Expand Down

4 comments on commit 4f208a2

@vercel
Copy link

@vercel vercel bot commented on 4f208a2 Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 4f208a2 Jun 1, 2022

@vercel
Copy link

@vercel vercel bot commented on 4f208a2 Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

app.typebot.io
builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 4f208a2 Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.