Connection closes on using protocols like mailto: and tel:
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
closeOnUnloadset totrue - Have no
targeton 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?
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.