Skip to main content
This page covers advanced usage of the Remark SDK, providing developers with more sophisticated control over the chat widget and user experience.

Initialization

Safely wait for the SDK before calling window.remark.

Widget Control

Programmatically open, close, hide, and show the chat widget.

Event Handling

Listen to user interactions and create custom integrations.

Waiting for Remark to initialize

Because the Remark script loads asynchronously, window.remark may not be available when your code runs. Before calling window.remark, wait for the remark:session-initialized event on window:
If your code might run before or after initialization, you can check whether window.remark is already available:

Customizing your user experience with the Remark SDK

The Remark SDK can also be used to control the state of the chat widget. You may wish, for example, to temporarily close the chat widget when displaying full-screen promotions or open the chat widget when a customer clicks on a certain call-to-action on your site. You can open, close, hide, and show the chat widget using one of the options in the following code.

Opening the widget with options

In addition to simply opening the widget, you can pass options to control its initial state and behavior.
This is helpful when you want to start the chat from a specific context, prefill a message, or automatically send a greeting.

Available options

  • from – A string identifier for where or why the widget was opened (for example, homepage, checkout, or category-page). Useful for analytics, tracking, or routing the conversation.
  • message – A string to prefill in the chat input. When paired with mode: 'send', this message will be sent automatically.
  • mode – Controls message handling. Use 'send' to send immediately or omit to just prefill the input.
This approach lets you personalize the chat experience and give your team useful context on how the conversation began.
Embedded and floating widget coordination: When both the floating chat (<remark-chat-widget>) and embedded chat (<remark-qa-activator>) appear on the same page, they coordinate automatically. Only one widget holds the active conversation at a time — the other shows a “paused” state with the matched expert’s avatar and a button to resume the conversation there.On mobile viewports (480 px and below), tapping a prompt in the embedded chat opens the floating widget full-screen instead of starting an inline conversation. The floating widget does not auto-reopen from persisted state across page navigations on mobile — it stays closed unless explicitly opened via remark_open=true or window.remark('open').

URL Parameters

Remark recognizes several URL parameters for controlling widget behavior without writing code. These are useful for testing and sharing links that demonstrate a specific widget configuration. Append them as query parameters to any page URL:
remark_force_widget and remark_preview_inline_elements are also written to sessionStorage when set via URL, so the override persists across page navigations within the same tab. You can also set them directly in sessionStorage — useful in browsers or environments that strip query parameters:
To clear an override, close the tab or remove the key from sessionStorage in DevTools.

Listening for Remark Events

The remark-chat-widget element fires a number of “remark” namespaced events. To listen to any of them, place an event listener on the remark-chat-widget element, or anywhere higher on the DOM. On the element directly
On the window

Listen to all Remark Events

To listen to all the events, you can use the window.remark.events.listenAll function. It takes a callback, called with every remark event. The payload received by the callback is an object: listenAll returns an object with an unsubscribe function. Calling that unsubscribe function will stop the callback from being called again.

List of Remark Events