Js api - onLoad is not accurate?

functions and methods in the onload method are not ready.

for example:
window.Tawk_API.onLoad = function(){
window.Tawk_API.setAttributes({
‘id’ : ‘A1234’,
‘store’ : ‘Midvalley’
}, function(error){});
};
setAttribute method fails without error

If I set a timeout and wait 3 secs setAttribute runs without error.

2 Likes

Same problem here, setAttributes not work in chats.

How did you fix this>?

I used setTimeout() in a function, passing the number of seconds to wait as a parameter. 2 seconds was spotty for me across various testing conditions, but I found 3 secs to work 100%.

function wait(seconds) {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}

You could also wait for a condition to be true(API fully loaded) and set an interval to check that condition which would be more durable but could lead to other issues which you would likely want to include handling for fails or errors.

Best of luck!

Thank you for the answer..