www.bifa88.com 5

www.bifa88.comjs的localStorage的物理储存位置,开发离线应用

前言

因为在做美团外卖商家端的nw.js壳子项目,需要保证在壳子里面使用localStorage的数据可以持久化保存。
发现nw可以保存,即使删除应用重写打包也可以保存,所以解决了这个需求,但是还是需要知道具体储存在哪里,否则不清楚什么情况下数据会丢失。

Google 在 2007 年 5 月发布了
Gears,它是一种为生成离线网络应用软件而开发的开源技术,Google
希望能在广大开发者的帮助下测试完善功能和发现产品的局限性。简单地说,它是
Google 推出的开源的浏览器插件,而开发者围绕着这个插件进行开发。2008 年 3
月,Google 推出了移动版 Gears,应用进程开始蔓延。

储存位置

nw.js打包出来的应用的localStorage的储存目录为:
**C:\Users【用户名】\AppData\Local【nw应用名称】\User
Data\Default\Local
Storage\chrome-extension_【随机字符】_0.localstorage**

比如我的电脑上的位置是:
C:\Users\xxcanghai\AppData\Local\waimai_e_client_nw\User
Data\Default\Local
Storage\chrome-extension_blodpelipeilefodephhjbnidgkbghmj_0.localstorage

www.bifa88.com 1

Google的官方网站:

打开方式

此localStorage文件为二进制文件,不能直接使用文本编辑器打开,但是可以通过二进制文件查看器访问。
如我在nw应用中设置了一个localStorage的值:xxcanghai 123
www.bifa88.com 2

然后用十六进制编辑器 WinHex打开
chrome-extension_blodpelipeilefodephhjbnidgkbghmj_0.localstorage
文件,就可以查看到里面的储存的xxcanghai123
www.bifa88.com 3

www.bifa88.com 4

附 其他浏览器localStorage的储存位置

 

火狐浏览器

Firefox将localstorage文件:webappsstore.sqlite
存储在配置文件文件夹中
火狐浏览器 (Windows XP):
C:\Documents and Settings<Windows login/user name>\Application
Data\Mozilla\Firefox\Profiles<profile
folder>\webappsstore.sqlite

火狐浏览器 (Windows Vista以上):
C:\Users<Windows login/user
name>\AppData\Roaming\Mozilla\Firefox\Profiles<profile
folder>\webappsstore.sqlite
or:
%APPDATA%\Mozilla\Firefox\Profiles<profile
folder>\webappsstore.sqlite

火狐浏览器 on linux:
~/.mozilla/firefox//webappsstore.sqlite

火狐浏览器 on mac:
~/Library/Application Support/Firefox/Profiles//webappsstore.sqlite
or:
~/Library/Mozilla/Firefox/Profiles//webappsstore.sqlite

一个不错的学习站点:(中文的)

Chrome浏览器

Chrome浏览器将储存在localStorage储存在独立的 Local Storage 文件夹中
Chrome on windows:
%LocalAppData%\Google\Chrome\User Data\Default\Local Storage
Chrome on linux:
~/.config/google-chrome/Default/Local Storage/

Chrome on mac:
~/Library/Application Support/Google/Chrome//Local Storage/
一般情况:
~/Library/Application Support/Google/Chrome/Default/Local Storage/

www.bifa88.com 5

 

文件缓存位置

Location of cached files

The LocalServer stores files that your application captures in a
location determined by the browser and platform.

Windows Vista – Internet Explorer

Location: {FOLDERID_LocalAppDataLow}\Google\Google Gears for Internet
Explorer
Example: C:\Users\Bob\AppData\LocalLow\Google\Google Gears for
Internet Explorer

Windows Vista – Firefox – Files are stored in the user local profile
directory.

Location:
C:\Users\<username>\AppData\Local\Mozilla\Firefox\Profiles\{profile}.default\Google
Gears for Firefox
Example:
C:\Users\Bob\AppData\Local\Mozilla\Firefox\Profiles\uelib44s.default\Google
Gears for Firefox

Windows Vista – Chrome – Files are stored in the user local profile
directory.

Location:
C:\Users\<username>\AppData\Local\Google\Chrome\User
Data\Default\Plugin Data\Google Gears
Example: C:\Users\Bob\AppData\Local\Google\Chrome\User
Data\Default\Plugin Data\Google Gears

Windows XP – Internet Explorer – Files are stored in the user local
profile directory.

Location: C:\Documents and Settings\<username>\Local
Settings\Application Data\Google\Google Gears for Internet Explorer
Example: C:\Documents and Settings\Bob\Local Settings\Application
Data\Google\Google Gears for Internet Explorer

Windows XP – Firefox – Files are stored in the user local profile
directory.

Location: C:\Documents and Settings\<username>\Local
Settings\Application
Data\Mozilla\Firefox\Profiles\{profile}\Google Gears for Firefox
Example: C:\Documents and Settings\Bob\Local Settings\Application
Data\Mozilla\Firefox\Profiles\uelib44s.default\Google Gears for
Firefox

Windows XP – Chrome – Files are stored in the user local profile
directory.

Location: C:\Documents and Settings\<username>\Local
Settings\Application Data\Google\Chrome\User Data\Default\Plugin
Data\Google Gears
Example: C:\Documents and Settings\Bob\Local Settings\Application
Data\Google\Chrome\User Data\Default\Plugin Data\Google Gears

Mac OS X – Safari – Files are stored in the user Application Support
directory.

Location: ~/Library/Application Support/Google/Google Gears for Safari
Example: /Users/Bob/Library/Application Support/Google/Google Gears for
Safari

Mac OS X – Firefox – Files are stored in the user local profile
directory.

Location:
Users/<username>/Library/Caches/Firefox/Profiles/{profile}.default/Google
Gears for Firefox
Example:
Users/Bob/Library/Caches/Firefox/Profiles/08ywpi3q.default/Google Gears
for Firefox

Linux – Firefox – Files are stored in the user home directory.

Location: ~bob/.mozilla/firefox/<firefox’s profile id>/Google
Gears for Firefox
Example: ~bob/.mozilla/firefox/08ywpi3q.default/Google Gears for Firefox