ably-js: "Unable to parse request body" error when publishing large messages from old browsers

For old browsers (in particular, versions of Internet Explorer too old to support XMLHttpRequest), the ably-js library uses JSONP, both for realtime connections (as part of a Comet protocol) and for making REST requests. Due to how JSONP works, when publishing, the message body is included in the url, which is injected into the src attribute of a script tag. Internet Explorer is liable to truncate this attribute past a certain length. If this happens, the request will fail due to the result not being well-formed json. ably-js version 0.9 or later will attempt to detect this issue and log a "the browser appears to have truncated the script URI" warning.

 

This also applies to other operations besides publish(), e.g. entering the presence set with a large amount of presence data.

 

Solution:

If you need to publish messages from old versions of Internet Explorer, we recommend ensuring that your messages are kept comfortably under 4kB for IE9, or 2kB for IE8.

 

As always, if you want to be informed if a publish fails you can pass a callback to publish(); see https://www.ably.io/documentation/realtime/channels-messages#publish.