josephrocca / OpenCharacters

Simple little web interface for creating characters and chatting with them. It's basically a single HTML file - no server. Share characters using a link (character data is stored within the URL itself). All chat data is stored in your browser using IndexedDB. Currently supports OpenAI APIs and ~any Hugging Face model.
https://josephrocca.github.io/OpenCharacters
MIT License
364 stars 60 forks source link

Cannot read properties of undefined (reading 'digest') at sha256Text #32

Closed drusepth closed 1 year ago

drusepth commented 1 year ago

I get this javascript alert after every message (as well as after refreshing the page on any chat where a message is loading):

qecaLmN

In the console, I also see this stack trace:

2bYrEdl

(index):3324 TypeError: Cannot read properties of undefined (reading 'digest') at sha256Text (utils.js?v=23:342:42) at countTokensInMessages ((index):1972:28) at getBotReply ((index):2509:40) at async doBotReplyIfNeeded ((index):3296:67)

The exact line throwing the error is

const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8);

I'm not sure if this is perhaps just a setup issue on my part, so I've also included my setup instructions below.

Setup details

I'm running the project zip from the local setup doc locally and set my OpenAI key. I'm also serving the project with Apache instead of the Web Server for Chrome app, since I'm planning to host on a remote, headless server.

I'm pretty sure, according to this documentation on Crypto: subtle that the problem is that I'm not serving the page over HTTPS and therefore crypto.subtle is unavailable.

Just figured I'd open this issue (and hopefully close it shortly) while I dig in for myself and anyone else that sees this specific error in the future. :+1:

drusepth commented 1 year ago

Hurrah! Enabling HTTPS was enough to resolve this error, so I'll close this issue. Hopefully it's helpful for anyone searching for the same error in the future.

josephrocca commented 1 year ago

Thanks! Next version will have an informative failure message so that people know they need HTTPS.