debug-waku-dapp.md
1 --- 2 title: Debug Your Waku DApp and WebSocket 3 hide_table_of_contents: true 4 displayed_sidebar: build 5 --- 6 7 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](/run-node/). 8 9 ## Enabling debug logs 10 11 When resolving issues in your Waku DApp, debug logs can be helpful. The `@waku/sdk` and `libp2p` packages use the debug tool to handle and show logs that help you debug effectively. 12 13 ### NodeJS environments 14 15 To enable debug logs for `@waku/sdk` on NodeJS, you must set the `DEBUG` environment variable. To only enable debug logs for `@waku/sdk`: 16 17 ```shell 18 export DEBUG=waku* 19 ``` 20 21 To enable debug logs for both `@waku/sdk` and `libp2p`: 22 23 ```shell 24 export DEBUG=waku*,libp2p* 25 ``` 26 27 To enable debug logs for all components: 28 29 ```shell 30 export DEBUG=* 31 ``` 32 33 ### Browser environments 34 35 To view debug logs in your browser's console, modify the local storage and add the `debug` key. Here are guides for various modern browsers: 36 37 - [Google Chrome](https://developer.chrome.com/docs/devtools/storage/localstorage/) 38 - [Firefox](https://firefox-source-docs.mozilla.org/devtools-user/storage_inspector/local_storage_session_storage/index.html) 39 - [JavaScript](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) 40 41 | KEY | VALUE | DESCRIPTION | 42 | - | - | - | 43 | `debug` | `waku*` | Enables `@waku/sdk` debug logs | 44 | `debug` | `waku*,libp2p*` | Enables `@waku/sdk` and `libp2p` debug logs | 45 | `debug` | `*` | Enables all debug logs | 46 47 ## Checking WebSocket setup 48 49 [Nwaku](/run-node/) provides native support for WebSocket (`ws`) and WebSocket Secure (`wss`) protocols. These are the only [transports](/learn/concepts/transports) supported for connecting to the Waku Network via browsers. 50 51 It's important to note that browsers impose certain limitations on WebSocket usage: 52 53 - **Secure Context Requirement**: Insecure subroutines are prohibited in secure contexts. On an `https://` webpage, only `wss` connections are permitted, while `ws` connections are not allowed. This restriction does not apply if the webpage is served locally, like on `localhost` or `127.0.0.1`. 54 - **Certificate Validation**: Certificate validation rules are consistent for `https` and `wss` connections. Certificates must not be expired, issued by a recognized Certificate Authority (CA), and match the domain name, among other criteria. 55 - **User Feedback on Errors**: 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. 56 57 If you encounter difficulties when connecting to a remote node using `wss`, follow these steps: 58 59 ### Try Websocat for connection 60 61 Attempt to connect using [websocat](https://github.com/vi/websocat), a tool for WebSocket interactions. Test the WebSocket port using the command: 62 63 ```shell 64 websocat -v wss://[WEBSOCKET HOST]:[WEBSOCKET PORT] 65 ``` 66 67 For example, consider a `nwaku` node with the multiaddr as `/dns4/nwakunode.com/tcp/1234/wss/p2p/16...`: 68 69 ```shell 70 $ websocat -v wss://nwakunode.com:1234 71 # ... 72 [INFO websocat::ws_client_peer] Connected to ws 73 ``` 74 75 The connection works if the `[INFO websocat::ws_client_peer] Connected to ws` log entry appears. If not, [check that the certificate is valid](#check-certificate-validity) 76 77 ### Check certificate validity 78 79 Verify the certificate's validity by passing the `-k` or `--insecure` flag to handle invalid certificates in `websocat`: 80 81 ```shell 82 websocat -v -k wss://nwakunode.com:1234 83 ``` 84 85 If this works, the certificate's invalidity is the problem, and you should investigate the cause of the error if not, [check if the WebSocket port is accessible](#check-websocket-port-accessibility). 86 87 ### Check WebSocket port accessibility 88 89 Use `telnet` or another networking tool to verify if the WebSocket port is open and accessible. For example, if the multiaddr is `/dns4/nwakunode.com/tcp/1234/wss/p2p/16...`, use the command: 90 91 ```shell 92 $ telnet nwakunode.com 1234 93 Trying 123.123.123.123... 94 Connected to nwakunode.com. 95 # ... 96 ``` 97 98 If the connection succeeds, there might be an issue with `nwaku`. Consider seeking support on the [Waku Discord](https://discord.waku.org) or [raise an issue](https://github.com/waku-org/nwaku/issues/new). If the connection fails, ensure that the WebSocket port is open.