<titledata-rh="true">Debug Your Waku DApp and WebSocket | Waku Documentation</title><metadata-rh="true"name="viewport"content="width=device-width,initial-scale=1"><metadata-rh="true"name="twitter:card"content="summary_large_image"><metadata-rh="true"property="og:url"content="https://docs.waku.org/build/javascript/debug-waku-dapp"><metadata-rh="true"property="og:locale"content="en_GB"><metadata-rh="true"name="docusaurus_locale"content="en-GB"><metadata-rh="true"name="docsearch:language"content="en-GB"><metadata-rh="true"name="keywords"content="waku, web3"><metadata-rh="true"name="image"content="https://docs.waku.org/_og/861227aa62df57a5dc1b839734ce12d766dc642c.png"><metadata-rh="true"name="docusaurus_version"content="current"><metadata-rh="true"name="docusaurus_tag"content="docs-default-current"><metadata-rh="true"name="docsearch:version"content="current"><metadata-rh="true"name="docsearch:docusaurus_tag"content="docs-default-current"><metadata-rh="true"property="og:title"content="Debug Your Waku DApp and WebSocket | Waku Documentation"><metadata-rh="true"name="description"content="This guide provides detailed steps to enable and use debug logs to troubleshoot your Waku DApp, whether in a NodeJS or browser environment and check your WebSocket connections in nwaku."><metadata-rh="true"property="og:description"content="This guide provides detailed steps to enable and use debug logs to troubleshoot your Waku DApp, whether in a NodeJS or browser environment and check your WebSocket connections in nwaku."><linkdata-rh="true"rel="icon"href="/theme/image/favicon.ico"><linkdata-rh="true"rel="canonical"href="https://docs.waku.org/build/javascript/debug-waku-dapp"><linkdata-rh="true"rel="alternate"href="https://docs.waku.org/build/javascript/debug-waku-dapp"hreflang="en-GB"><linkdata-rh="true"rel="alternate"href="https://docs.waku.org/build/javascript/debug-waku-dapp"hreflang="x-default"><linkrel="alternate icon"type="image/png"href="/theme/image/favicon.png">
<h2class="anchor anchorWithHideOnScrollNavbar_WYt5"id="enabling-debug-logs">Enabling debug logs<ahref="#enabling-debug-logs"class="hash-link"aria-label="Direct link to Enabling debug logs"title="Direct link to Enabling debug logs"></a></h2>
<p>When resolving issues in your Waku DApp, debug logs can be helpful. The <code>@waku/sdk</code> and <code>libp2p</code> packages use the debug tool to handle and show logs that help you debug effectively.</p>
<h3class="anchor anchorWithHideOnScrollNavbar_WYt5"id="nodejs-environments">NodeJS environments<ahref="#nodejs-environments"class="hash-link"aria-label="Direct link to NodeJS environments"title="Direct link to NodeJS environments"></a></h3>
<p>To enable debug logs for <code>@waku/sdk</code> on NodeJS, you must set the <code>DEBUG</code> environment variable. To only enable debug logs for <code>@waku/sdk</code>:</p>
<h3class="anchor anchorWithHideOnScrollNavbar_WYt5"id="browser-environments">Browser environments<ahref="#browser-environments"class="hash-link"aria-label="Direct link to Browser environments"title="Direct link to Browser environments"></a></h3>
<p>To view debug logs in your browser's console, modify the local storage and add the <code>debug</code> key. Here are guides for various modern browsers:</p>
<table><thead><tr><th>KEY</th><th>VALUE</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td><code>debug</code></td><td><code>waku*</code></td><td>Enables <code>@waku/sdk</code> debug logs</td></tr><tr><td><code>debug</code></td><td><code>waku*,libp2p*</code></td><td>Enables <code>@waku/sdk</code> and <code>libp2p</code> debug logs</td></tr><tr><td><code>debug</code></td><td><code>*</code></td><td>Enables all debug logs</td></tr></tbody></table>
<h2class="anchor anchorWithHideOnScrollNavbar_WYt5"id="checking-websocket-setup">Checking WebSocket setup<ahref="#checking-websocket-setup"class="hash-link"aria-label="Direct link to Checking WebSocket setup"title="Direct link to Checking WebSocket setup"></a></h2>
<p><ahref="/run-node/">Nwaku</a> provides native support for WebSocket (<code>ws</code>) and WebSocket Secure (<code>wss</code>) protocols. These are the only <ahref="/learn/concepts/transports">transports</a> supported for connecting to the Waku Network via browsers.</p>
<p>It's important to note that browsers impose certain limitations on WebSocket usage:</p>
<ul>
<li><strong>Secure Context Requirement</strong>: Insecure subroutines are prohibited in secure contexts. On an <code>https://</code> webpage, only <code>wss</code> connections are permitted, while <code>ws</code> connections are not allowed. This restriction does not apply if the webpage is served locally, like on <code>localhost</code> or <code>127.0.0.1</code>.</li>
<li><strong>Certificate Validation</strong>: Certificate validation rules are consistent for <code>https</code> and <code>wss</code> connections. Certificates must not be expired, issued by a recognized Certificate Authority (CA), and match the domain name, among other criteria.</li>
<li><strong>User Feedback on Errors</strong>: Web browsers do not display errors related to subroutines to the user. If a WebSocket connection encounters an issue, users won't be alerted directly; you'll need to check the browser's console for error details.</li>
</ul>
<p>If you encounter difficulties when connecting to a remote node using <code>wss</code>, follow these steps:</p>
<h3class="anchor anchorWithHideOnScrollNavbar_WYt5"id="try-websocat-for-connection">Try Websocat for connection<ahref="#try-websocat-for-connection"class="hash-link"aria-label="Direct link to Try Websocat for connection"title="Direct link to Try Websocat for connection"></a></h3>
<p>Attempt to connect using <ahref="https://github.com/vi/websocat"target="_blank"rel="noopener noreferrer">websocat</a>, a tool for WebSocket interactions. Test the WebSocket port using the command:</p>
<p>The connection works if the <code>[INFO websocat::ws_client_peer] Connected to ws</code> log entry appears. If not, <ahref="#check-certificate-validity">check that the certificate is valid</a></p>
<h3class="anchor anchorWithHideOnScrollNavbar_WYt5"id="check-certificate-validity">Check certificate validity<ahref="#check-certificate-validity"class="hash-link"aria-label="Direct link to Check certificate validity"title="Direct link to Check certificate validity"></a></h3>
<p>Verify the certificate's validity by passing the <code>-k</code> or <code>--insecure</code> flag to handle invalid certificates in <code>websocat</code>:</p>
<p>If this works, the certificate's invalidity is the problem, and you should investigate the cause of the error if not, <ahref="#check-websocket-port-accessibility">check if the WebSocket port is accessible</a>.</p>
<h3class="anchor anchorWithHideOnScrollNavbar_WYt5"id="check-websocket-port-accessibility">Check WebSocket port accessibility<ahref="#check-websocket-port-accessibility"class="hash-link"aria-label="Direct link to Check WebSocket port accessibility"title="Direct link to Check WebSocket port accessibility"></a></h3>
<p>Use <code>telnet</code> or another networking tool to verify if the WebSocket port is open and accessible. For example, if the multiaddr is <code>/dns4/nwakunode.com/tcp/1234/wss/p2p/16...</code>, use the command:</p>