Parsing Character Card V2/V3 PNG Chunks in Pure Browser JS & Building a Zero-XSS Regex Status Bar Sandbox
Interactive fiction and AI roleplay creators pass around thousands of "character cards" every week—portable PNG portraits that secretly carry structured JSON world lore, persona definitions, alternate opening scenes, Lorebooks, and Regex-driven HTML status bars. Yet the tooling around these files has historically been fragile: legacy scripts rely on Node's Buffer or naive atob() calls that…
Interactive fiction and AI roleplay creators frequently share "character cards" in the form of portable PNG portraits. These cards contain structured JSON world lore, persona definitions, alternate opening scenes, lorebooks, and regex-driven HTML status bars. However, the tools for handling these files have been unstable in the past.
Legacy scripts used Node's Buffer or naive atob() calls, which caused corruption of Japanese, Korean, Thai, and Chinese UTF-8 characters. Community-shared custom HUD templates were often placed directly into innerHTML, turning status bars into potential XSS vulnerabilities. To address these issues, Rubii AI's engineering team developed a browser-based Character Card V1/V2/V3 & Character.AI Export Converter, open-sourcing the engine and Chrome Extension under the MIT license.
They established three non-negotiable constraints: zero dependencies and 100% browser-native execution, zero extension permissions, and zero-XSS regex UI sandboxing. This deep dive explains the binary parsing mechanics for Character Card V2 and V3 PNG chunks, the challenges encountered, the creation of an allowlist-based HTML and inline-CSS sanitizer for regex status bars, and how the same linting/layout tools were exposed through the Model Context Protocol.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to