最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to test IndexedDB 'QuotaExceededError' without filling disk? - Stack Overflow

programmeradmin1浏览0评论

I want to make sure my code handles the QuotaExceededError with IndexedDB properly, I'd prefer not torturing my SSD to do so.

Is there any way to set a storage limit (like to say 5 MB) in the developer tools or browser settings?

I want to make sure my code handles the QuotaExceededError with IndexedDB properly, I'd prefer not torturing my SSD to do so.

Is there any way to set a storage limit (like to say 5 MB) in the developer tools or browser settings?

Share Improve this question asked Oct 28, 2018 at 1:42 jdwjdw 1,5733 gold badges19 silver badges26 bronze badges 1
  • Chrome is working on it Issue 945786 – Binyamin Commented Oct 12, 2019 at 17:19
Add a comment  | 

5 Answers 5

Reset to default 12

In Chrome, you can launch the browser with --user-data-dir pointing at a smaller volume, e.g. via tmpfs.

Chrome doesn't have devtools support for such testing, but it's on the wish list.

As of today you can open DevTools, go to the Application Panel and check the Simulate custom storage quota label and then provide the maximum amount of MB that can be stored by IndexedDB.

Chrome DevTools Application Panel Screeshot

I've used a VM with a small hard drive. That's not ideal obviously, so I hope someone suggests a better answer!

Building on @joshua-bell's answer but adding detail on exactly how to do this in Mac OSX:

  1. Copy the mount-ram.sh file at https://gist.github.com/koshigoe/822455 (you will probably want the unmount-ram.sh file for later as well)
  2. Save that file anywhere you want
  3. From the directory where you saved mount-ram.sh, run sh mount-ram.sh mytmpfs 512
  4. cd /Applications/Google Chrome.app/Contents/MacOS (at least that's where it was on my machine)
  5. ./Google\ Chrome --user-data-dir=/PATH/TO/mytmpfs/, replacing /PATH/TO/mytmpfs/ with the path the directory you created in step 3.

Now you've got Chrome running, pointed at a file system with only 512MB of storage.

If you're ok with a 100MB storage limit, just open Chrome in incognito mode.

To see how much storage you have left, try this:

navigator.storage.estimate().then(console.log)
发布评论

评论列表(0)

  1. 暂无评论