前言
因為在做美團外賣商家端的nw.js殼子項目,需要保證在殼子裡面使用localStorage的資料可以持久化儲存。
發現nw可以儲存,即使删除應用重寫打包也可以儲存,是以解決了這個需求,但是還是需要知道具體儲存在哪裡,否則不清楚什麼情況下資料會丢失。
儲存位置
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
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnL0UjMwUjN0ADNtADO2gTNzITNxcjM2AzNxAjMtgTNxYDN38CX2AzNxAjMvwFO1EjN0czLcd2bsJ2Lc12bj5ycn9Gbi52YuUTMwIzcldWYtl2Lc9CX6MHc0RHaiojIsJye.png)

打開方式
此localStorage檔案為二進制檔案,不能直接使用文本編輯器打開,但是可以通過二進制檔案檢視器通路。
如我在nw應用中設定了一個localStorage的值:
xxcanghai 123
然後用十六進制編輯器
WinHex
打開 chrome-extension_blodpelipeilefodephhjbnidgkbghmj_0.localstorage 檔案,就可以檢視到裡面的儲存的
xxcanghai
和
123
附 其他浏覽器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/
~/Library/Mozilla/Firefox/Profiles/
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/
如果您認為本文對得起您所閱讀他所花的時間,歡迎點選右下角↘ 推薦。您的支援是我繼續寫作最大的動力,謝謝作者:小小滄海
出處:http://www.cnblogs.com/xxcanghai/
本文位址:http://www.cnblogs.com/xxcanghai/
本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利。