troubleshooting.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. .. raw:: html
  2. <div id="banner"><a href="https://github.com/jcbrand/converse.js/blob/master/docs/source/setup.rst">Edit me on GitHub</a></div>
  3. =============================
  4. Troubleshooting and debugging
  5. =============================
  6. General tips on debugging Converse.js
  7. =====================================
  8. When debugging converse.js, always make sure that you pass in ``debug: true`` to
  9. the ``converse.initialize`` call.
  10. Converse.js will then log debug information to the browser's developer console.
  11. Open the developer console and study the data that is logged to it.
  12. `Strope.js <http://strophe.im/>`_ the underlying XMPP library which Converse.js
  13. uses, swallows errors, so that messaging can continue in cases where
  14. non-critical errors occur.
  15. This is a useful feature and provides more stability, but it makes debugging
  16. trickier, because the app doesn't crash when something goes wrong somewhere.
  17. That's why checking the debug output in the browser console is so important. If
  18. something goes wrong somewhere, the error will be logged there and you'll be
  19. able to see it.
  20. Additionally, Converse.js will in debug mode also log all XMPP stanzas
  21. (the XML snippets being sent between it and the server) to the console.
  22. This is very useful for debugging issues relating to the XMPP protocol.
  23. For example, if a message or presence update doesn't appear, one of the first
  24. things you can do is to set ``debug: true`` and then to check in the console
  25. whether the relevant XMPP stanzas are actually logged (which would mean that
  26. they were received by Converse.js). If they're not logged, then the problem is
  27. more likely on the XMPP server's end (perhaps a misconfiguration?). If they
  28. **are** logged, then there might be a bug or misconfiguration in Converse.js.
  29. Conflicts with other JavaScript libraries
  30. =========================================
  31. Problem:
  32. ---------
  33. You are using other JavaScript libraries (like JQuery plugins), and
  34. get errors like these in your browser console::
  35. Uncaught TypeError: Object [object Object] has no method 'xxx' from example.js
  36. Solution:
  37. ---------
  38. First, find out which object is referred to by ``Object [object Object]``.
  39. It will probably be the jQuery object ``$`` or perhaps the lodash/underscore object ``_``.
  40. For the purpose of demonstration, I'm going to assume its ``$``, but the same
  41. rules apply if its something else.
  42. The bundled and minified default build of converse.js, ``converse.min.js``
  43. includes within it all of converse.js's dependencies, which include for example *jQuery*.
  44. If you are having conflicts where attributes or methods aren't available
  45. on the jQuery object, you are probably loading ``converse.min.js`` (which
  46. includes jQuery) as well as your own jQuery version separately.
  47. What then happens is that there are two ``$`` objects (one from
  48. converse.js and one from the jQuery version you included manually)
  49. and only one of them has been extended to have the methods or attributes you require.
  50. Which jQuery object you get depends on the order in which you load the libraries.
  51. There are multiple ways to solve this issue.
  52. Firstly, make sure whether you really need to include a separate version of
  53. jQuery. Chances are that you don't. If you can remove the separate
  54. version, your problem should be solved, as long as your libraries are loaded in
  55. the right order.
  56. Either case, whether you need to keep two versions or not, the solution depends
  57. on whether you'll use require.js to manage your libraries or whether you'll
  58. load them manually.
  59. With require.js
  60. ~~~~~~~~~~~~~~~
  61. Instead of using ``converse.min.js``, manage all the libraries in your project
  62. (i.e. converse.js and its dependencies plus all other libraries you use) as one
  63. require.js project, making sure everything is loaded in the correct order.
  64. Then, before deployment, you make your own custom minified build that bundles everything
  65. you need.
  66. With <script> tags
  67. ~~~~~~~~~~~~~~~~~~
  68. Take a look at `non_amd.html <https://github.com/jcbrand/converse.js/blob/master/non_amd.html>`_
  69. in the converse.js repo.
  70. It shows in which order the libraries must be loaded via ``<script>`` tags. Add
  71. your own libraries, making sure that they are loaded in the correct order (e.g.
  72. jQuery plugins must load after jQuery).
  73. Performance issues with large rosters
  74. =====================================
  75. Effort has been made to benchmark and optimize converse.js to work with large
  76. rosters.
  77. See for example the benchmarking tests in `spec/profiling.js
  78. <https://github.com/jcbrand/converse.js/blob/master/spec/profiling.js>`_ which
  79. can be used together with the `profiling features of
  80. Chrome <https://developer.chrome.com/devtools/docs/cpu-profiling>`_ to find
  81. bottlenecks in the code.
  82. However, with large rosters (more than 1000 contacts), rendering in
  83. converse.js slows down a lot and it may become intolerably slow.
  84. One simple trick to improve performance is to set ``show_only_online_users: true``.
  85. This will (usually) reduce the amount of contacts that get rendered in the
  86. roster, which eases one of the remaining performance bottlenecks.