web-storage
它能做什么
这个技能检查网页如何使用浏览器存储,并让这些代码不会因错误而崩溃。它面向应用会在浏览器中保存数据的开发者。
适用场景
- ✓代码在没有错误处理的情况下读写 localStorage 的时候。
- ✓应用把对象保存到存储中,读取时却不做检查的时候。
- ✓登录令牌等敏感数据保存在浏览器的本地存储中的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/web-storage/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的应用在隐私浏览模式下保存设置时会崩溃。请帮我让存储代码变得安全吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会用错误处理包裹存储的读写操作,并在加载序列化数据时进行检查。它还会标出不应保存在浏览器存储中的敏感数据。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Use Web Storage API safely
localStorage and sessionStorage have a 5–10 MB quota per origin, and any write can throw a QuotaExceededError. Private browsing modes in some browsers disable storage entirely and throw on all writes. Applications that don't handle these errors crash silently, leaving users unable to use the app.
Quick Reference
- Always wrap localStorage access in try/catch — storage can be full or disabled
- Serialize objects with JSON.stringify and validate on read with JSON.parse
- Never store sensitive data (tokens, passwords) in localStorage — use httpOnly cookies
- Use sessionStorage for tab-scoped data that shouldn't persist
Check
Find all localStorage and sessionStorage accesses in this file. Check for missing try/catch, unhandled JSON parsing, and any storage of sensitive data.
Fix
Add try/catch error handling to all Web Storage operations and ensure all object values are properly serialized and deserialized.
Explain
Explain the Web Storage API, its limitations, when to use localStorage vs sessionStorage, and what data should never be stored there.
Code Review
Review scripts, client components, and browser execution paths related to Use Web Storage API safely. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/web-storage
常见问题
为什么存储会导致崩溃?
存储有大小限制,一些隐私浏览模式会将其关闭,因此写入时可能抛出应用必须处理的错误。
什么时候 sessionStorage 是更好的选择?
这个技能建议将它用于只需在单个浏览器标签页中保留的数据。
哪些内容绝不能放进 localStorage?
令牌和密码。这个技能建议对它们改用 httpOnly Cookie。
详情
作者的原始描述
Use when reviewing scripts, client components, bundles, or runtime behavior related to Use Web Storage API safely. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.
热度
- GitHub 星标
- 75k
- 排名
- #3084
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。