Here is an article and an example project that show how to use the HTML5 web crypto API to encrypt or decrypt a string
It uses PBKDF2 to dervice the key from a password, then encrypts the data with AES-GCM
https://bradyjoslin.com/blog/encryption-webcrypto/The script itself can be downloaded from here:
https://github.com/bradyjoslin/webcrypto-example/blob/master/script.js