From 47a087c73b4f6fa291fd5a825750095893d9463b Mon Sep 17 00:00:00 2001 From: sabaimran Date: Sun, 8 Dec 2024 17:16:20 -0800 Subject: [PATCH] Fix chatwoot import issue by checking whether we're in an execution environment before loading the script --- .../src/components/ChatwootWidget.js | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/documentation/src/components/ChatwootWidget.js b/documentation/src/components/ChatwootWidget.js index 61d72684..bb90e1c5 100644 --- a/documentation/src/components/ChatwootWidget.js +++ b/documentation/src/components/ChatwootWidget.js @@ -1,14 +1,19 @@ -(function (d, t) { - var BASE_URL = "https://app.chatwoot.com"; - var g = d.createElement(t), s = d.getElementsByTagName(t)[0]; - g.src = BASE_URL + "/packs/js/sdk.js"; - g.defer = true; - g.async = true; - s.parentNode.insertBefore(g, s); - g.onload = function () { - window.chatwootSDK.run({ - websiteToken: 'cFxvnLSjfE2UF4UUiPCA5NsF', - baseUrl: BASE_URL - }) - } -})(document, 'script'); +import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; + +// Only execute on client-side +if (ExecutionEnvironment.canUseDOM) { + (function (d, t) { + var BASE_URL = "https://app.chatwoot.com"; + var g = d.createElement(t), s = d.getElementsByTagName(t)[0]; + g.src = BASE_URL + "/packs/js/sdk.js"; + g.defer = true; + g.async = true; + s.parentNode.insertBefore(g, s); + g.onload = function () { + window.chatwootSDK.run({ + websiteToken: 'cFxvnLSjfE2UF4UUiPCA5NsF', + baseUrl: BASE_URL + }) + } + })(document, 'script'); +}