Use globalThis for TextEncoder, TextDecoder, and atob browser globals
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,7 @@ async function importKey(b64) {
|
||||
|
||||
async function encrypt(data) {
|
||||
if (!encKey) return null
|
||||
const json = new TextEncoder().encode(JSON.stringify(data))
|
||||
const json = new globalThis.TextEncoder().encode(JSON.stringify(data))
|
||||
const iv = globalThis.crypto.getRandomValues(new Uint8Array(12))
|
||||
const encrypted = await globalThis.crypto.subtle.encrypt({ name: 'AES-GCM', iv, tagLength: 128 }, encKey, json)
|
||||
const buf = new Uint8Array(encrypted)
|
||||
@@ -28,7 +28,7 @@ async function decrypt(b64) {
|
||||
const data = raw.slice(12)
|
||||
try {
|
||||
const decrypted = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv, tagLength: 128 }, encKey, data)
|
||||
return JSON.parse(new TextDecoder().decode(decrypted))
|
||||
return JSON.parse(new globalThis.TextDecoder().decode(decrypted))
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user