Best way to store files in the browser (non-disk)

59 views
Skip to first unread message

Mohamad Bazzi

unread,
Nov 29, 2021, 7:56:14 PM11/29/21
to Chromium Extensions
In my chrome extension, I would like to store files in the browser (from background script) but not on disk, as I would like to read and erase the files quickly. Is the best solution to use blob URLs? If so, how much data can I store as blob URLs? Or should I just store the file contents in an array in the background script?

ilyaigpetrov

unread,
Nov 30, 2021, 9:09:46 AM11/30/21
to Chromium Extensions, bazz...@gmail.com
Blob-urls don't survive extension restarts.
To persist between restarts you have to use chrome.storage.
After reading data from chrome.storage you may construct a data-url [1] or blob-url from it.

Simeon Vincent

unread,
Nov 30, 2021, 4:37:58 PM11/30/21
to Chromium Extensions, ilyaigpetrov, bazz...@gmail.com
Alternatively you can use IndexedDB to store files. Personally I'd recommend using IndexedDB because it's a web platform feature and there are a number of articles and libraries out there covering how to use it to store files. In fact, just now when I did a Google search for "indexeddb file storage" I found Robert Nyman's Storing images and files in IndexedDB post on the Mozilla Hacks blog.

Simeon - @dotproto
Chrome Extensions DevRel


Mohamad Bazzi

unread,
Dec 1, 2021, 6:33:05 PM12/1/21
to Simeon Vincent, Chromium Extensions, ilyaigpetrov
Thanks@
Reply all
Reply to author
Forward
0 new messages