Is it possible to programmatically scroll to the bottom of the chat?

In our app when user clicks a button in the fullscreen, it closes the fullscreen and displays a new inline widget. However that widget is being generated below the followup response from the chat and it is not visible in the screen. User has to scroll to the bottom to see it. It may appear as nothing is happening and I am afraid it will not be a good UX.

Is it possible to trigger a scroll to the bottom of the chat after user exits fullscreen?

3 Likes

Would also like to know this or :+1: the ability to do this if not in the SDK.

1 Like

AFAIK, this is not in the SDK, however this should do what you’re trying to do:

If you’re in an iframe:

const doc = window.parent.document ?? document // iframe or non-iframe

doc.querySelector(‘[data-is-last-node]’)?.scrollIntoView()

That is “select the element that’s the last node (which was programmatically marked as such)”, and scroll it into view.

Note that this isn’t documented, so this may break at a later date. Consider this a “workaround” for now.

I’ll file a feature request.

4 Likes

@benlesh Thanks a lot into looking into it. Unfortunately doing as you suggested is not possible, because the browsers’ same-origin policy. It’s throws an “Uncaught SecurityError”, because we can’t access the parent from the iframe, as the hostname is different.

I would highly appreciate is such feature is added to the SDK.

Thanks a lot for filing the request!

1 Like

If you add the widget programmatically you may try something like this:

yourContainer.appendChild(widgetElement);

yourContainer.scrollTop = yourContainer.scrollHeight;

Ah yeah… CSP. That makes sense, I should’ve thought of that. Oh well, worth a shot :slight_smile:

FYI: A scrollToBottom feature has been shipped recently:

2 Likes