element-hq / chatterbox

Chatterbox lets you securely embed Hydrogen on any website!
Apache License 2.0
172 stars 21 forks source link

Attempting to connect via http on an external connection causes crash #107

Open willbruceSmartDCSIT opened 9 months ago

willbruceSmartDCSIT commented 9 months ago

Describe the bug When running the chatterbox client on my web browser to connect to the homeserver - using my networks IP (192.168.0.X) - the CB client crashes when loading up. The error message valid in the Chrome Inspect panel is: VM42 main.ts:104 TypeError: Cannot read properties of undefined (reading 'deriveBits') at new Crypto (VM46 hydrogen-view-sdk.js:8749:23) at new Platform (VM46 hydrogen-view-sdk.js:9774:21) at main (VM42 main.ts:57:20) VM46 hydrogen-view-sdk.js:8749 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'deriveBits') at new Crypto (VM46 hydrogen-view-sdk.js:8749:23) at new Platform (VM46 hydrogen-view-sdk.js:9774:21) at main (VM42 main.ts:57:20)

To Reproduce Steps to reproduce the behavior:

  1. Follow installation steps outlined in the readme
  2. Adjust config.json
  3. Connect to server IP
  4. Error visible in the Chrome Inspect Console

Expected behavior Chatterbox client should open up as normal - this works when connecting to localhost

Desktop (please complete the following information):

Rhys-T commented 9 months ago

I ran into that too. It's not exactly a bug in Chatterbox, but rather a limitation in what your browser allows non-secure websites to do. Chatterbox/Hydrogen uses the Web Crypto API, and like a lot of newer web APIs, it's only allowed in secure contexts - which basically means either HTTPS or localhost. So when you connect to another server like 192.168.0.X over insecure HTTP, the entire crypto.subtle object is missing, and CB doesn't bother to check whether it exists before using it, so it ends up crashing (not that CB could work without it anyway).

To let Chatterbox use that API, you can either: