Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget JS doesn't details domain correctly #63

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions frontend/src/components/common/WidgetEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ export const WidgetEditor = () => {
},
});

const [htmlEmbedCode, setHtmlHtmlEmbedCode] = useState<string>("");
const [htmlEmbedCode, setHtmlEmbedCode] = useState<string>("");
const [reactComponentCode, setReactComponentCode] = useState<string>("");
const [reactUsageCode, setReactUsageCode] = useState<string>("");
const currentLocation = typeof window !== "undefined" ? window?.location : undefined;
const embedUrl = `${currentLocation?.protocol}//${currentLocation?.host}/widget.js`;
const embedScript = `<script async src="${embedUrl}"></script>`;

useEffect(() => {
setHtmlHtmlEmbedCode(
setHtmlEmbedCode(
'<div ' +
'data-hievents-id="' + eventId + '" ' +
'data-hievents-primary-color="' + form.values.primary_color + '" ' +
Expand Down Expand Up @@ -165,7 +165,8 @@ export default App;
<Group justify={'space-between'}>
{t`Colors`}

<Popover title={t`The styling settings you choose apply only to copied HTML and won't be stored.`}>
<Popover
title={t`The styling settings you choose apply only to copied HTML and won't be stored.`}>
<IconInfoCircle size={23}/>
</Popover>
</Group>
Expand Down Expand Up @@ -357,4 +358,4 @@ export default App;
</div>
</div>
);
};
};
6 changes: 3 additions & 3 deletions frontend/src/embed/widget.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable lingui/no-unlocalized-strings */
(function () {
(function(scriptElement) {
const isScriptLoaded = () => !!window.hiEventWidgetLoaded;

const loadWidget = () => {
window.hiEventWidgetLoaded = true;

let scriptOrigin;
try {
const scriptURL = document.currentScript.src;
const scriptURL = scriptElement.src;
scriptOrigin = new URL(scriptURL).origin;
} catch (e) {
console.error('HiEvent widget error: Invalid script URL');
Expand Down Expand Up @@ -86,4 +86,4 @@
loadWidget();
}
}
})();
})(document.currentScript);
Loading