Skip to content

Commit

Permalink
feat(lib): ⚡️ Pass host URL params
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 28, 2022
1 parent 1d82940 commit 7b4dc47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/typebot-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typebot-js",
"version": "2.2.3",
"version": "2.2.4",
"main": "dist/index.js",
"unpkg": "dist/index.umd.min.js",
"license": "AGPL-3.0-or-later",
Expand Down
16 changes: 10 additions & 6 deletions packages/typebot-js/src/iframe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ export const createIframe = ({
...iframeParams
}: IframeParams): HTMLIFrameElement => {
const { loadWhenVisible, hiddenVariables } = iframeParams
const iframeUrl = `${url}${parseQueryParams(hiddenVariables)}`
const hostUrlParams = new URLSearchParams(document.location.search)
const hostQueryObj: { [key: string]: string } = {}
hostUrlParams.forEach((value, key) => {
hostQueryObj[key] = value
})
const iframeUrl = `${url}${parseQueryParams({
...hiddenVariables,
...hostQueryObj,
})}`
const iframe = document.createElement('iframe')
iframe.setAttribute(loadWhenVisible ? 'data-src' : 'src', iframeUrl)
iframe.setAttribute('data-id', url)
Expand All @@ -25,11 +33,7 @@ export const createIframe = ({
const parseQueryParams = (starterVariables?: {
[key: string]: string | undefined
}): string => {
return parseHostnameQueryParam() + parseStarterVariables(starterVariables)
}

const parseHostnameQueryParam = () => {
return `?hn=${window.location.hostname}`
return parseStarterVariables(starterVariables)
}

const parseStarterVariables = (starterVariables?: {
Expand Down

4 comments on commit 7b4dc47

@vercel
Copy link

@vercel vercel bot commented on 7b4dc47 Apr 28, 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 7b4dc47 Apr 28, 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

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

@vercel
Copy link

@vercel vercel bot commented on 7b4dc47 Apr 28, 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.