Freshdesk Library V2 does not initialise when loading freshdesk library dynamically

  • 19 February 2019
  • 1 reply
  • 33 views

Hello,

Whenever I try lo load your js "https://static.freshdev.io/fdk/2.0/assets/fresh_client.js" dynamically, using settimeout or from console, the FrshClient() is never resolved.

Sample Cases:

1: Library working fine.

   

<html>
<head>
</head>
<body>
</body>
<script>
function appendJS()
{
url ="https://static.freshdev.io/fdk/2.0/assets/fresh_client.js";
var tag_hdr = document.getElementsByTagName('head')[0]; var
tag_script = document.createElement('script');
tag_script.setAttribute('type', 'text/javascript');
tag_script.setAttribute('src', url);
tag_hdr.appendChild(tag_script);
console.log("Successfully Loaded freshdesk Library");
}
appendJS();
</script>
</html>

 2. Library Not working, when loading the js after few milisecs/secs.

 

<html>
<head>
</head>
<body>
</body>
<script>
function appendJS()
{
url ="https://static.freshdev.io/fdk/2.0/assets/fresh_client.js";
var tag_hdr = document.getElementsByTagName('head')[0]; var
tag_script = document.createElement('script');
tag_script.setAttribute('type', 'text/javascript');
tag_script.setAttribute('src', url);
tag_hdr.appendChild(tag_script);
console.log("Successfully Loaded freshdesk Library");
}
setTimeout(function(){ appendJS(); }, 100);
</script>
</html>

 3. Library Not working, when loading the library from console by calling the appendJS().

 

<html>
<head>
</head>
<body>
</body>
<script>
function appendJS()
{
url ="https://static.freshdev.io/fdk/2.0/assets/fresh_client.js";
var tag_hdr = document.getElementsByTagName('head')[0]; var
tag_script = document.createElement('script');
tag_script.setAttribute('type', 'text/javascript');
tag_script.setAttribute('src', url);
tag_hdr.appendChild(tag_script);
console.log("Successfully Loaded freshdesk Library");
}
</script>
</html>

 When library failed in initialisation no response is get on the window.onmessage, and the promise is never resolved.

image




This topic has been closed for comments

1 reply

Hi Rajat,


Can I please know the usecase that you're trying to tackle, so that I can better help you out?

It helps us to understand why setTimeout()  is needed.


var url ="https://static.freshdev.io/fdk/2.0/assets/fresh_client.js";


Adding var , solves the issue in #3.


Cheers!