ably-js icon indicating copy to clipboard operation
ably-js copied to clipboard

Connection closes on using protocols like mailto: and tel:

Open huubhermsen opened this issue 8 months ago • 1 comments

Hi,

When clicking links with protocols like mailto: and tel:, any connection to an Ably Client is closed because the browser window dispatches the beforeunload event. This issue arises when you:

  • Initialize the Ably client with closeOnUnload set to true
  • Have no target on a anchor element

We've solved this issue by setting targets for anchors specifically to _blank or targeting a visually hidden iframe, for example:

<>
  <iframe width={0} height={0} name="protocol-demo" />
  <a href="tel:0123456789" target="protocol-demo">Call us</a>
</>

Maybe something to put in (support) documentation?

┆Issue is synchronized with this Jira Task by Unito

huubhermsen avatar Apr 16 '25 14:04 huubhermsen

Hi @huubhermsen,

Thank you for bringing this to our attention! We understand that the beforeunload event can unexpectedly close the Ably client when using mailto: or tel: links with closeOnUnload set to true. Your solution of targeting a visually hidden iframe or _blank for such links is a clever workaround and an excellent approach to address this behavior.

We’ll make sure to take this into account as part of our documentation or support materials to help others who might face a similar issue. Your feedback is greatly appreciated and helps us improve! If there’s anything else you’d like to share or explore, please don’t hesitate to reach out.

ttypic avatar Apr 21 '25 13:04 ttypic