跳到正文
Skillpedia
网站与界面(前端)75k · #3084

web-storage

它能做什么

这个技能检查网页如何使用浏览器存储,并让这些代码不会因错误而崩溃。它面向应用会在浏览器中保存数据的开发者。

适用场景

  • ✓代码在没有错误处理的情况下读写 localStorage 的时候。
  • ✓应用把对象保存到存储中,读取时却不做检查的时候。
  • ✓登录令牌等敏感数据保存在浏览器的本地存储中的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/web-storage/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/web-storage/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#3084
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能