troubleshooting.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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
  7. ==================================
  8. Enabling debug output
  9. ---------------------
  10. Converse has a :ref:`loglevel` configuration setting which lets you to turn on
  11. debug logging in the browser's developer console.
  12. When debugging, you always want to make sure that this setting is set to
  13. ``true`` when calling ``converse.initialize``.
  14. You can also enable debug output via the URL, which is useful when you don't
  15. have access to the server where Converse is hosted.
  16. To do so, add ``#converse?loglevel=debug`` to the URL in the browser's address bar.
  17. Make sure to first remove any already existing URL fragment (the URL fragment
  18. is the part that starts with a ``#``).
  19. With debug logging on, you can open the browser's developer console and study the
  20. data that is logged to it.
  21. In Chrome you can right click in the developer console and save its contents to
  22. a file for later study.
  23. What is logged at the debug loglevel?
  24. -------------------------------------
  25. `Strope.js <http://strophe.im/>`_, the underlying XMPP library which Converse
  26. uses, swallows errors so that messaging can continue in cases where
  27. non-critical errors occur.
  28. This is a useful feature and provides more stability, but it makes debugging
  29. trickier, because the app doesn't crash when something goes wrong somewhere.
  30. That's why checking the debug output in the browser console is important.
  31. If something goes wrong somewhere, the error will be logged there and you'll be
  32. able to see it.
  33. Additionally, Converse will in debug mode also log all XMPP stanzas
  34. (the XML snippets being sent between it and the server) to the console.
  35. This is very useful for debugging issues relating to the XMPP protocol.
  36. For example, if a message or presence update doesn't appear, one of the first
  37. things you can do is to set ``loglevel: debug`` and then to check in the console
  38. whether the relevant XMPP stanzas are actually logged (which would mean that
  39. they were received by Converse). If they're not logged, then the problem is
  40. more likely on the XMPP server's end (perhaps a misconfiguration?). If they
  41. **are** logged, then there might be a bug or misconfiguration in Converse.
  42. Performance issues with large rosters
  43. =====================================
  44. Effort has been made to benchmark and optimize Converse to work with large
  45. rosters.
  46. See for example the benchmarking tests in `spec/profiling.js
  47. <https://github.com/jcbrand/converse.js/blob/master/spec/profiling.js>`_ which
  48. can be used together with the `profiling features of
  49. Chrome <https://developer.chrome.com/devtools/docs/cpu-profiling>`_ to find
  50. bottlenecks in the code.
  51. However, with large rosters (more than 1000 contacts), rendering in
  52. Converse slows down a lot and it may become intolerably slow.
  53. One simple trick to improve performance is to set ``show_only_online_users: true``.
  54. This will (usually) reduce the amount of contacts that get rendered in the
  55. roster, which eases one of the remaining performance bottlenecks.
  56. File upload is not working
  57. ==========================
  58. One of the most common causes for file upload not working is a lack of CORS
  59. support by the file server to which the file should be uploaded.
  60. CORS stands for `Cross-Origin Resource Sharing (CORS) <https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS>`_
  61. and is a technique for overcoming browser restrictions related to the
  62. `same-origin security policy <https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy>`_.
  63. For example, if the domain under which you host Converse is *example.org*,
  64. but the domain of your of your HTTP file server (for `XEP-0363 HTTP File Upload <https://xmpp.org/extensions/xep-0363.html>`_)
  65. is *upload.example.org*, then the HTTP file server needs to enable CORS.
  66. If you're not sure what the domain of the HTTP file server is, take a look at
  67. the console of your browser's developer tools.
  68. You might see an error like this one::
  69. Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://example.de:5443/...
  70. You might also see a 404 HTTP response for an OPTIONS request in the `Network Tab` of your browser's developer tools.
  71. An OPTIONS request is usually a so-called
  72. `CORS pre-flight request <https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS#Preflighted_requests_in_CORS>`_
  73. which is used by the browser to find out whether the endpoint supports
  74. `Cross-Origin Resource Sharing (CORS) <https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS>`_.
  75. If you get a 404 response for such a request, then the endpoint does NOT
  76. support CORS and the browser will prevent requests from being made to it.
  77. This will prevent you from uploading files to it.
  78. How you solve a CORS-related issue depends on your particular setup, specifically it depends on
  79. what you're using as the HTTP file server.
  80. CORS is enabled by adding an ``Access-Control-Allow-Origin`` header, so you'll
  81. have to configure your file server to add this header.
  82. Users don't stay logged in across page reloads
  83. ==============================================
  84. A common complaint in the Converse chat room (`<xmpp:discuss@conference.conversejs.org?join>`_)
  85. is that users are logged out when they reload the page.
  86. The main way in which websites and web apps maintain a user's login session is via
  87. authentication cookies, which are included in every HTTP request sent to the server.
  88. XMPP is however not HTTP, cookies aren't automatically included in traffic to
  89. the XMPP server and XMPP servers don't rely on cookies for authentication.
  90. Instead, an XMPP client is expected to store the user credentials (username and
  91. password, either plaintext or hashed and salted if
  92. `SCRAM <https://en.wikipedia.org/wiki/Salted_Challenge_Response_Authentication_Mechanism>`_
  93. is being used) and to then present those credentials to the XMPP server when authenticating.
  94. This works well for non-web XMPP clients, but Converse has so far avoided
  95. storing user credentials in browser storage, since they can then be accessed by
  96. any scripts running in the browser under the same domain.
  97. So what does Converse do to keep users logged in?
  98. -------------------------------------------------
  99. Use the Web Auth API
  100. ********************
  101. Converse supports the `Web Authentication API <https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API>`_
  102. which let's it use the secure credential management of the browser to get the
  103. uesr credentials to automatically log the user in. This however requires that
  104. the user saves his or her username and password in the browser. Often the user
  105. is automatically asked by the browser whether he/she wants to store the
  106. credentials. If that doesn't happen, the user has to do so manually, usually by
  107. clicking the key icon in the address bar. This works well on most modern browsers,
  108. but not on Firefox, which has insufficient support for the Web Authentication API.
  109. What can users do to stay logged in?
  110. ------------------------------------
  111. Outsource credential management to something else
  112. *************************************************
  113. The issues mentioned above mostly related to users logging in manually, and not
  114. to integrations where Converse automatically fetches user credentials from the
  115. backend via the :ref:`credentials_url` setting.
  116. Use BOSH instead of websocket
  117. *****************************
  118. `BOSH <https://xmpp.org/extensions/xep-0206.html>`_ can be thought of
  119. XMPP-over-HTTP and because HTTP is stateless, BOSH needs to maintain login
  120. sessions for a certain amount of time (usually 60 seconds) even if there is no
  121. HTTP traffic between the client and server. This means that if you have a BOSH
  122. session running, you can reload the page and you will stay logged in.
  123. Note, Websocket connections are however faster and have less overhead than BOSH.
  124. User a browser with adequate support for the Web Auth API
  125. *********************************************************
  126. Another option is to only use a browser with proper support for the Web Auth
  127. API (which mainly means avoiding Firefox) and then to save your credentials in the browser.
  128. Use Converse Desktop
  129. ********************
  130. The `desktop version of Converse <https://github.com/conversejs/converse-desktop>`_
  131. also doesn't have this problem, since the credentials are stored in Electron
  132. and there is no significant risk of other malicious scripts running.
  133. What else can Converse do to keep users logged in?
  134. --------------------------------------------------
  135. This problem could also potentially be fixed by storing the
  136. XMPP credentials securely with web crypto and IndexedDB. This could be done by
  137. generating a private encryption key in non-exportable format, and then using that
  138. to encrypt the credentials before storing them in IndexedDB.
  139. This would protect the credentials from someone who has access to your
  140. computer (or harddrive), but it still won't protect them from malicious scripts
  141. running in the same domain as Converse is being hosted, since they would have the
  142. same level of access as Converse itself (which legitimately needs access to the
  143. credentials).
  144. Common errors
  145. =============
  146. Error: A "url" property or function must be specified
  147. -----------------------------------------------------
  148. That's a relatively generic `Skeletor <https://github.com/conversejs/skeletor>`_ (or `Backbone <http://backbonejs.org/>_`)
  149. error and by itself it usually doesn't give enough information to know how to fix the underlying issue.
  150. Generally, this error happens when a Model is being persisted (e.g. when model.save() is called,
  151. but there is no information specifying where/how it should be persisted.
  152. The Converse models are persisted to browser storage (e.g. sessionStorage, localStorage or IndexedDB),
  153. and this happens by adding a browserStorage attribute on the model, or on the collection containing the model.
  154. See for example here: https://github.com/conversejs/converse.js/blob/395aa8cb959bbb7e26472ed3356160c8044be081/src/headless/converse-chat.js#L359
  155. If this error occurs, it means that a model being persisted doesn't have the ``browserStorage`` attribute,
  156. and it's containing collection (if there is one) also doesn't have that attribute.
  157. This usually happens when a model has been removed from a collection, and then ``.save()`` is called on it.
  158. In the context of Converse it might mean that there's an attempt to persist data before all models have been properly initialized,
  159. or conversely after models have been removed from their containing collections.