简体   繁体   English

将 `jpm run` 用于 Firefox Add-on SDK 扩展时,如何将数据持久存储在 `localStorage` 中

[英]How to persistently store data in `localStorage` when using `jpm run` for a Firefox Add-on SDK extension

I am working on Firefox extension and I need to store date in localStorage for login property.我正在开发 Firefox 扩展,我需要将日期存储在localStorage以用于登录属性。

I used simple storage but simple storage loses data after restart.我使用了简单存储,但简单存储在重启后会丢失数据。

So, please let me know how to store data in localStorage .所以,请让我知道如何在localStorage存储数据。

You are probably using jpm run to test your add-on.您可能正在使用jpm run来测试您的附加组件。 jpm run uses a fresh, temporary profile each time you execute it. jpm run每次执行时都会使用一个新的临时配置文件。 If you want any data to persist from one execution to another you will need to use the -p or --profile= option to specify a profile to use for that run.如果您希望将任何数据从一次执行保存到另一次执行,您将需要使用-p--profile=选项指定用于该运行的配置文件。 See Using profiles on MDN.请参阅在 MDN 上使用配置文件 You can specify either the profile name, or the path to the profile.您可以指定配置文件名称或配置文件的路径。 The lack of persistence of just using jpm run will be an issue for any storage which is placed in the profile, or profile directory be it a preference with simple-prefs , data using simple-storage , a file using io/file , a database using SQLite database , or any other method.仅使用jpm run缺乏持久性对于放置在配置文件或配置文件目录中的任何存储都是一个问题,无论是使用simple-prefs的首选项、使用simple-storage 的数据、使用io/file 的文件、数据库使用SQLite 数据库或任何其他方法。 This is explicitly stated on multiple pages, including the simple-storage page.这在多个页面上都有明确说明,包括简单存储页面。

Examples (from MDN):示例(来自 MDN):

jpm run --profile boogaloo
jpm run --profile path/to/boogaloo

If you want to create a new profile to use for testing, you can use the profile manager .如果要创建用于测试的新配置文件,可以使用配置文件管理器 You can start the profile manager by starting Firefox with any of the options -p , -P , or -ProfileManager .您可以通过使用任何选项-p-P-ProfileManager启动 Firefox 来启动配置文件管理器。 Normally, you will need to exit out of any currently running Firefox instance in order to start a new version of Firefox.通常,您需要退出任何当前正在运行的 Firefox 实例才能启动新版本的 Firefox。 However, it is also possible to start a new instance while having Firefox open with a different profile by using the -no-remote option.但是,也可以使用-no-remote选项在使用不同的配置文件打开 Firefox 的同时启动一个新实例。 For example, on 64-bit Windows, to start the Firefox profile manager, I normally use:例如,在 64 位 Windows 上,要启动 Firefox 配置文件管理器,我通常使用:

"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -no-remote -ProfileManager

If you are really wanting to use local storage, you should store the data within the profile directory, so you will still need to do the above steps to use a specified profile.如果您真的想使用本地存储,您应该将数据存储在配置文件目录中,因此您仍然需要执行上述步骤才能使用指定的配置文件。 You will want to look at io/file , and will need to open() the file and then read or write it using text-streams or byte-streams .您将需要查看io/file ,并且需要open()文件,然后使用text-streamsbyte-streams读取或写入它。 The next logical question is where it should be stored, but that is another question: Where to save files from Firefox add-on?下一个合乎逻辑的问题是它应该存储在哪里,但这是另一个问题:在哪里保存来自 Firefox 附加组件的文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM